public void SpectralAnalysis_NegativeDCOffsetTestWithPhase() { const int offset = -100; var sineGen = new SineWaveGenerator(1000, 100, 52100, offset, Math.PI * 0.34); var d = sineGen.GetNextXSamples(1042).SelectMany(x => x.Data); var data = d.ToList(); var fftData = SpectralAnaylser.FFT(data).ToArray(); var dcOffset = SpectralAnaylser.FindDCOffset(fftData); const double sampleCalculatedOffset = -100.0; Assert.AreEqual(sampleCalculatedOffset, dcOffset, 0.0001); }
public void SpectralAnalysis_PositiveDCOffsetTest() { const int offset = 100; var sineGen = new SineWaveGenerator(1000, 100, 52100, offset); var d = sineGen.GetNextXSamples(1000).SelectMany(x => x.Data); var data = d.ToList(); var fftData = SpectralAnaylser.FFT(data).ToArray(); var dcOffset = SpectralAnaylser.FindDCOffset(fftData); const double sampleCalculatedOffset = 100.49514649954881; Assert.AreEqual(sampleCalculatedOffset, dcOffset, 0.0001); }
public void SpectralAnalysis_PositiveDCOffsetTestWithPhase2() { const int offset = 100; var sineGen1 = new SineWaveGenerator(1000, 20, 52100, offset, Math.PI * 0.34); var sineGen2 = new SineWaveGenerator(1000, 10, 52100, offset, Math.PI * 0.34); var d1 = sineGen1.GetNextXSamples(1042).SelectMany(x => x.Data); var d2 = sineGen2.GetNextXSamples(1042).SelectMany(x => x.Data); var data = d1.Zip(d2, (i, j) => i + j).ToList(); var fftData = SpectralAnaylser.FFT(data).ToArray(); var dcOffset = SpectralAnaylser.FindDCOffset(fftData); const double sampleCalculatedOffset = 200.0; Assert.AreEqual(sampleCalculatedOffset, dcOffset, 0.0001); }
public void SpectralAnalysis_MultipleDCOffsetTestWithPhase() { const int offset1 = 85; const int offset2 = -50; var sineGen1 = new SineWaveGenerator(1000, 20, 52100, offset1, Math.PI * 0.34); var sineGen2 = new SineWaveGenerator(1000, 10, 52100, offset2, Math.PI * 0.71); var d1 = sineGen1.GetNextXSamples(1000).SelectMany(x => x.Data); var d2 = sineGen2.GetNextXSamples(1000).SelectMany(x => x.Data); var data = d1.Zip(d2, (i, j) => i + j).ToList(); var fftData = SpectralAnaylser.FFT(data).ToArray(); var dcOffset = SpectralAnaylser.FindDCOffset(fftData); const double sampleCalculatedOffset = 35.223304466064626; Assert.AreEqual(sampleCalculatedOffset, dcOffset, 0.0001); }