init
This commit is contained in:
95
DataPRO/FftSharp.Test/FftSharp.Tests.csproj
Normal file
95
DataPRO/FftSharp.Test/FftSharp.Tests.csproj
Normal file
@@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props')" />
|
||||
<Import Project="..\packages\NUnit.3.12.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{56CD6397-CFE7-4B95-987F-C4B869560B78}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>FftSharp.Tests</RootNamespace>
|
||||
<AssemblyName>FftSharp.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NSubstitute, Version=4.2.0.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NSubstitute.4.2.1\lib\net46\NSubstitute.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.2\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="PowerSpectralDensityShould.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="PSD.csv">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="Raw.csv">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Common\DTS.Common\DTS.Common.csproj">
|
||||
<Project>{f7a0804f-61a4-40ae-83d0-f1137622b592}</Project>
|
||||
<Name>DTS.Common</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\FftSharp\FftSharp.csproj">
|
||||
<Project>{9ff2beb4-a267-4139-a37d-9c9a58d7d36d}</Project>
|
||||
<Name>FftSharp</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.12.0\build\NUnit.props'))" />
|
||||
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.3.14.0\build\net35\NUnit3TestAdapter.props'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
2050
DataPRO/FftSharp.Test/PSD.csv
Normal file
2050
DataPRO/FftSharp.Test/PSD.csv
Normal file
File diff suppressed because it is too large
Load Diff
133
DataPRO/FftSharp.Test/PowerSpectralDensityShould.cs
Normal file
133
DataPRO/FftSharp.Test/PowerSpectralDensityShould.cs
Normal file
@@ -0,0 +1,133 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FftSharp.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
public class PowerSpectralDensityShould
|
||||
{
|
||||
#region helper functions
|
||||
private void ParseData(string filename, out List<double> vals1, out List<double> vals2)
|
||||
{
|
||||
vals1 = new List<double>();
|
||||
vals2 = new List<double>();
|
||||
|
||||
using (var rawReader = new StreamReader(TestContext.CurrentContext.TestDirectory + "\\" + filename))
|
||||
{
|
||||
while (!rawReader.EndOfStream)
|
||||
{
|
||||
var line = rawReader.ReadLine();
|
||||
var values = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (double.TryParse(values[0], out double val1))
|
||||
{
|
||||
vals1.Add(val1);
|
||||
}
|
||||
if (double.TryParse(values[1], out double val2))
|
||||
{
|
||||
vals2.Add(val2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool CloseEnough(double[] val1, double[] val2)
|
||||
{
|
||||
for (int i = 0; i < val1.Length; i++)
|
||||
{
|
||||
var exp = Math.Floor(Math.Log10(val1[i]));
|
||||
var exp2 = Math.Floor(Math.Log10(val2[i]));
|
||||
exp += exp < 0 ? 1 : -1;
|
||||
if (exp <= -10 && exp2 <= -10) continue; // under 1e-10? we're in the noise floor, skip
|
||||
|
||||
var diff = Math.Abs(val1[i] - val2[i]);
|
||||
var delta = Math.Pow(10, exp);
|
||||
if (diff > delta)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
const int RawValueLength = 304478;
|
||||
const int PSDValueLength = 2049;
|
||||
|
||||
[Test]
|
||||
public void BasicWelch_1_RawTestDataShouldParse()
|
||||
{
|
||||
//Arrange
|
||||
List<double> gVals, sVals;
|
||||
ParseData("Raw.csv", out sVals, out gVals);
|
||||
//Act
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(gVals.Count, Is.EqualTo(RawValueLength));
|
||||
Assert.That(sVals.Count, Is.EqualTo(RawValueLength));
|
||||
});
|
||||
}
|
||||
[Test]
|
||||
public void BasicWelch_2_PSDResultsDataShouldParse()
|
||||
{
|
||||
//Arrange
|
||||
List<double> hzVals, g2ovHzVals;
|
||||
ParseData("PSD.csv", out hzVals, out g2ovHzVals);
|
||||
//Act
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(g2ovHzVals.Count, Is.EqualTo(PSDValueLength));
|
||||
Assert.That(hzVals.Count, Is.EqualTo(PSDValueLength));
|
||||
});
|
||||
}
|
||||
[Test]
|
||||
public void BasicWelch_3_FFTSharpFreqShouldMatchPSDResultFreq()
|
||||
{
|
||||
//Arrange
|
||||
List<double> hzVals, g2ovHzVals;
|
||||
ParseData("PSD.csv", out hzVals, out g2ovHzVals);
|
||||
var sampleRate = 10000;
|
||||
//Act
|
||||
var freq = FftSharp.Transform.FFTfreq(sampleRate, g2ovHzVals.Count);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(hzVals.Count, Is.EqualTo(PSDValueLength));
|
||||
Assert.That(freq.Length, Is.EqualTo(PSDValueLength));
|
||||
// see if they're close enough
|
||||
Assert.That(hzVals.ToArray(), Is.EqualTo(freq).Using<double[]>(CloseEnough));
|
||||
});
|
||||
}
|
||||
[Test]
|
||||
public void BasicWelch_4_TestBasicFlatTopNoOverlap4096Width()
|
||||
{
|
||||
//Arrange
|
||||
List<double> gVals, sVals;
|
||||
ParseData("Raw.csv", out sVals, out gVals);
|
||||
List<double> hzVals, g2ovHzVals;
|
||||
ParseData("PSD.csv", out hzVals, out g2ovHzVals);
|
||||
var sampleRate = 10000;
|
||||
var averagingType = FftSharp.WindowAveragingType.Averaging;
|
||||
var windowWidth = 4096;
|
||||
var overlappingPct = 0;
|
||||
//Act
|
||||
FftSharp.WindowType type = WindowType.Rectangular;
|
||||
var psd = FftSharp.Transform.PSD_Welch(gVals.ToArray(), sampleRate, type, windowWidth, overlappingPct, averagingType);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(g2ovHzVals.Count, Is.EqualTo(PSDValueLength));
|
||||
Assert.That(psd.Length, Is.EqualTo(PSDValueLength));
|
||||
// see if they're close enough
|
||||
Assert.That(g2ovHzVals.ToArray(), Is.EqualTo(psd).Using<double[]>(CloseEnough));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
36
DataPRO/FftSharp.Test/Properties/AssemblyInfo.cs
Normal file
36
DataPRO/FftSharp.Test/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("FftSharp.Test")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("FftSharp.Test")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2022")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("56cd6397-cfe7-4b95-987f-c4b869560b78")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
304479
DataPRO/FftSharp.Test/Raw.csv
Normal file
304479
DataPRO/FftSharp.Test/Raw.csv
Normal file
File diff suppressed because it is too large
Load Diff
11
DataPRO/FftSharp.Test/app.config
Normal file
11
DataPRO/FftSharp.Test/app.config
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = "")]
|
||||
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
|
||||
Binary file not shown.
Binary file not shown.
9
DataPRO/FftSharp.Test/packages.config
Normal file
9
DataPRO/FftSharp.Test/packages.config
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Castle.Core" version="4.4.0" targetFramework="net461" />
|
||||
<package id="NSubstitute" version="4.2.1" targetFramework="net461" />
|
||||
<package id="NUnit" version="3.12.0" targetFramework="net461" />
|
||||
<package id="NUnit3TestAdapter" version="3.14.0" targetFramework="net461" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net461" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net461" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user