Example #1
0
        public void DFTTestMethod3()
        {
            DiscreteFourierTransform DFT = new DiscreteFourierTransform();
            // test case 2
            List <float> Samples = new List <float> {
                1, 3, 5, 7, 9, 11, 13, 15
            };

            DFT.InputTimeDomainSignal  = new DSPAlgorithms.DataStructures.Signal(Samples, false);
            DFT.InputSamplingFrequency = 4;

            var FrequenciesAmplitudes = new List <float> {
                64, 20.9050074380220f, 11.3137084989848f, 8.65913760233915f, 8, 8.65913760233915f, 11.3137084989848f, 20.9050074380220f
            };
            var FrequenciesPhaseShifts = new List <float> {
                0, 1.96349540849362f, 2.35619449019235f, 2.74889357189107f, -3.14159265358979f, -2.74889357189107f, -2.35619449019235f, -1.96349540849362f
            };
            var Frequencies = new List <float> {
                0, 1, 2, 3, 4, 5, 6, 7
            };

            DFT.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(FrequenciesAmplitudes, DFT.OutputFreqDomainSignal.FrequenciesAmplitudes) &&
                          UnitTestUtitlities.SignalsPhaseShiftsAreEqual(FrequenciesPhaseShifts, DFT.OutputFreqDomainSignal.FrequenciesPhaseShifts));
        }
        public void DFTTestMethod2()
        {
            InverseFastFourierTransform IFFT = new InverseFastFourierTransform();
            // test case 2

            var FrequenciesAmplitudes = new List <float> {
                64, 20.9050074380220f, 11.3137084989848f, 8.65913760233915f, 8, 8.65913760233915f, 11.3137084989848f, 20.9050074380220f
            };
            var FrequenciesPhaseShifts = new List <float> {
                0, 1.96349540849362f, 2.35619449019235f, 2.74889357189107f, 3.14159265358979f, -2.74889357189107f, -2.35619449019235f, -1.96349540849362f
            };
            var Frequencies = new List <float> {
                0, 1, 2, 3, 4, 5, 6, 7
            };

            IFFT.InputFreqDomainSignal = new DSPAlgorithms.DataStructures.Signal(true, Frequencies, FrequenciesAmplitudes, FrequenciesPhaseShifts);

            IFFT.Run();

            List <float> outPutSamples = new List <float> {
                1, 3, 5, 7, 9, 11, 13, 15
            };

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(outPutSamples, IFFT.OutputTimeDomainSignal.Samples));
        }
Example #3
0
        public static bool SignalsPhaseShiftsAreEqual(List <float> l1, List <float> l2)
        {
            if (l1.Count != l2.Count)
            {
                return(false);
            }

            for (int i = 0; i < l1.Count; i++)
            {
                l1[i] = UnitTestUtitlities.RoundPhaseShift(l1[i]);
                l2[i] = UnitTestUtitlities.RoundPhaseShift(l2[i]);

                if ((!float.IsNaN(l1[i]) && float.IsNaN(l2[i])) || (float.IsNaN(l1[i]) && !float.IsNaN(l2[i])))
                {
                    return(false);
                }
                else if (Math.Abs(l1[i] - l2[i]) > 0.0001)
                {
                    //Console.WriteLine(i.ToString() + " " + l1[i].ToString() + " " + l2[i].ToString());
                    return(false);
                }
            }

            return(true);
        }
        public void DirectConvolutionTestMethod4()
        {
            DirectConvolution dc = new DirectConvolution();
            // test case 4 ..
            var expectedOutput = new Signal(new List <float>()
            {
                1, 1, -1, 0, 0, 3, 3, 2, 1
            }, new List <int>()
            {
                -2, -1, 0, 1, 2, 3, 4, 5, 6
            }, false);

            dc.InputSignal1 = new Signal(new List <float>()
            {
                1, 2, 1, 1
            }, new List <int>()
            {
                -2, -1, 0, 1
            }, false);

            dc.InputSignal2 = new Signal(new List <float>()
            {
                1, -1, 0, 0, 1, 1
            }, new List <int>()
            {
                0, 1, 2, 3, 4, 5
            }, false);

            dc.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput.Samples, dc.OutputConvolvedSignal.Samples));
            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesIndicesAreEqual(expectedOutput, dc.OutputConvolvedSignal));
        }
 public void FoldingTestMethod3()
 {
     f.InputSignal        = inputSignal;
     expectedOutputSignal = UnitTestUtitlities.LoadSignal("TestingSignals/Output_Fold.ds");
     f.Run();
     actualOutputSignal = f.OutputFoldedSignal;
 }
 public void ShiftingRightTestMethod2()
 {
     s.InputSignal        = inputSignal;
     s.ShiftingValue      = -500;
     expectedOutputSignal = UnitTestUtitlities.LoadSignal("TestingSignals/Output_Shift_Minus500.ds");
     s.Run();
     actualOutputSignal = s.OutputShiftedSignal;
 }
        public void AutoFastNonNormalizedCorrelationTestMethod2()
        {
            FastCorrelation fc             = new FastCorrelation();
            var             expectedOutput = UnitTestUtitlities.LoadSignal("TestingSignals/FastAutoCorrelationNonNormalized_TestCase.ds");

            fc.InputSignal1 = UnitTestUtitlities.LoadSignal("TestingSignals/FastAutoCorrelation.ds");
            fc.Run();
            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput.Samples, fc.OutputNonNormalizedCorrelation));
        }
        public void QuantizationAndEncodingTestMethod3()
        {
            QuantizationAndEncoding Q = new QuantizationAndEncoding();

            Q.InputLevel  = 4;
            Q.InputSignal = new DSPAlgorithms.DataStructures.Signal(new List <float>()
            {
                -1.22f, 1.5f, 3.24f, 3.94f, 2.20f, -1.1f, -2.26f, -1.88f, -1.2f
            }, false);
            Q.Run();

            List <int> expectedIntervalIndices = new List <int>()
            {
                1, 3, 4, 4, 3, 1, 1, 1, 1
            };
            List <string> expectedEncodedValues = new List <string>()
            {
                "00", "10", "11", "11", "10", "00", "00", "00", "00"
            };
            List <float> expectedQuantizedValues = new List <float>()
            {
                -1.485f, 1.615f, 3.165f, 3.165f, 1.615f, -1.485f, -1.485f, -1.485f, -1.485f
            };
            List <float> expectedSampledError = new List <float>()
            {
                -0.265f, 0.115f, -0.075f, -0.775f, -0.585f, -0.385f, 0.775f, 0.395f, -0.285f
            };

            bool encodedValues   = true;
            bool quantizedValues = true;
            bool indicesValues   = true;
            bool errorValues     = true;

            for (int i = 0; i < expectedEncodedValues.Count; i++)
            {
                if (expectedEncodedValues[i] != Q.OutputEncodedSignal[i])
                {
                    encodedValues = false;
                    break;
                }
            }

            quantizedValues = UnitTestUtitlities.SignalsSamplesAreEqual(expectedQuantizedValues, Q.OutputQuantizedSignal.Samples);
            errorValues     = UnitTestUtitlities.SignalsSamplesAreEqual(expectedSampledError, Q.OutputSamplesError);

            for (int i = 0; i < expectedIntervalIndices.Count; i++)
            {
                if (expectedIntervalIndices[i] != Q.OutputIntervalIndices[i])
                {
                    indicesValues = false;
                    break;
                }
            }

            Assert.IsTrue(encodedValues && quantizedValues && indicesValues && errorValues);
        }
 public void FoldingAndShiftLeftTestMethod5()
 {
     s.ShiftingValue      = -500;
     expectedOutputSignal = UnitTestUtitlities.LoadSignal("TestingSignals/Output_Fold_Minus500.ds");
     f.InputSignal        = inputSignal;
     f.Run();
     s.InputSignal = f.OutputFoldedSignal;
     s.Run();
     actualOutputSignal = s.OutputShiftedSignal;
 }
        public void AutoDirectNormalizedPeriodicCorrelationTestMethod2()
        {
            DirectCorrelation dc = new DirectCorrelation();

            dc.InputSignal1 = UnitTestUtitlities.LoadSignal("TestingSignals/AutoCorrelationPeriodic_TestCase.ds");
            Signal expectedOutput = UnitTestUtitlities.LoadSignal("TestingSignals/AutoCorrelationNormalizedPeriodic_TestCase.ds");

            dc.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput.Samples, dc.OutputNormalizedCorrelation));
        }
        public void IFFT_TestMethod2()
        {
            InverseFastFourierTransform IFFT = new InverseFastFourierTransform();

            IFFT.InputFreqDomainSignal = UnitTestUtitlities.LoadSignal(@"TestingSignals/Signal2_FFT_Results.ds");
            List <float> outPutSamples = UnitTestUtitlities.LoadSignal("TestingSignals/Signal2_FFT.ds").Samples;

            IFFT.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(outPutSamples,
                                                                    IFFT.OutputTimeDomainSignal.Samples));
        }
Example #12
0
        public void FFT_TestMethod2()
        {
            DiscreteFourierTransform DFT = new DiscreteFourierTransform();
            // test case 1 ..
            var sig1           = UnitTestUtitlities.LoadSignal("TestingSignals/Signal2_FFT.ds");
            var expectedOutput = UnitTestUtitlities.LoadSignal("TestingSignals/Signal2_FFT_Results.ds");

            DFT.InputTimeDomainSignal  = sig1;
            DFT.InputSamplingFrequency = 360;

            DFT.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput.FrequenciesAmplitudes, DFT.OutputFreqDomainSignal.FrequenciesAmplitudes) &&
                          UnitTestUtitlities.SignalsPhaseShiftsAreEqual(expectedOutput.FrequenciesPhaseShifts, DFT.OutputFreqDomainSignal.FrequenciesPhaseShifts));
        }
        public void NormalizerTestMethod2()
        {
            var sig1           = UnitTestUtitlities.LoadSignal("TestingSignals/Signal2.ds");
            var expectedOutput = UnitTestUtitlities.LoadSignal("TestingSignals/Normalizer_TestCase2.ds").Samples;

            Normalizer a = new Normalizer();

            a.InputMinRange = 0;
            a.InputMaxRange = 1;
            a.InputSignal   = sig1;

            a.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput, a.OutputNormalizedSignal.Samples));
        }
        public void MovingAverageTestMethod2()
        {
            // test case 2 ..
            var sig1           = UnitTestUtitlities.LoadSignal("TestingSignals/Signal2.ds");
            var expectedOutput = UnitTestUtitlities.LoadSignal("TestingSignals/MovingAverage_TestCase2.ds").Samples;

            MovingAverage a = new MovingAverage();

            a.InputSignal     = sig1;
            a.InputWindowSize = 5;

            a.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput, a.OutputAverageSignal.Samples));
        }
Example #15
0
        public void MultiplySignalByConstantTestMethod2()
        {
            var sig1           = UnitTestUtitlities.LoadSignal("TestingSignals/Signal2.ds");
            var expectedOutput = UnitTestUtitlities.LoadSignal("TestingSignals/MultiplySignalByConstant_TestCase2.ds").Samples;


            MultiplySignalByConstant m = new MultiplySignalByConstant();

            m.InputSignal   = sig1;
            m.InputConstant = 10;

            m.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput, m.OutputMultipliedSignal.Samples));
        }
Example #16
0
        public void RemoveDCComponentTestMethod1()
        {
            // test case 1 ..
            var sig1 = UnitTestUtitlities.LoadSignal("TestingSignals/DC_Component.ds");

            var expectedOutput = UnitTestUtitlities.LoadSignal("TestingSignals/DC_Component_Result.ds").Samples;

            RemoveDCComponent m = new RemoveDCComponent();

            m.InputSignal = sig1;


            m.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput, m.OutputSignal.Samples));
        }
        public void SubtractorTestMethod2()
        {
            var sig1 = UnitTestUtitlities.LoadSignal("TestingSignals/Signal1.ds");
            var sig2 = UnitTestUtitlities.LoadSignal("TestingSignals/Signal3.ds");

            var expectedOutput = UnitTestUtitlities.LoadSignal("TestingSignals/Subtractor_TestCase2.ds").Samples;

            Subtractor m = new Subtractor();

            m.InputSignal1 = sig2;
            m.InputSignal2 = sig1;

            m.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput, m.OutputSignal.Samples));
        }
Example #18
0
        public void AdderTestMethod2()
        {
            var sig1 = UnitTestUtitlities.LoadSignal("TestingSignals/Signal1.ds");
            var sig2 = UnitTestUtitlities.LoadSignal("TestingSignals/Signal3.ds");

            var expectedOutput = UnitTestUtitlities.LoadSignal("TestingSignals/Adder_TestCase2.ds");

            Adder a = new Adder();

            a.InputSignals = new List <Signal>();
            a.InputSignals.Add(sig1);
            a.InputSignals.Add(sig2);

            a.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput.Samples, a.OutputSignal.Samples));
        }
        public void AutoFastNonNormalizedCorrelationTestMethod1()
        {
            FastCorrelation fc = new FastCorrelation();

            var expectedOutput = new Signal(new List <float>()
            {
                0.50f, 0.25f, 0.00f, 0.25f
            }, false);

            fc.InputSignal1 = new Signal(new List <float>()
            {
                1, 0, 0, 1
            }, true);

            fc.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput.Samples, fc.OutputNonNormalizedCorrelation));
        }
        public void LowCoefficientsTestMethod1()
        {
            FIR FIR = new FIR();

            var sig1 = UnitTestUtitlities.LoadSignal("TestingSignals/ecg400.ds");
            var expectedCoefficients = UnitTestUtitlities.LoadSignal("TestingSignals/LPFCoefficients.ds");

            FIR.InputFilterType          = DSPAlgorithms.DataStructures.FILTER_TYPES.LOW;
            FIR.InputFS                  = 8000;
            FIR.InputStopBandAttenuation = 50;
            FIR.InputCutOffFrequency     = 1500;
            FIR.InputTransitionBand      = 500;

            FIR.InputTimeDomainSignal = sig1;

            FIR.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesIndicesAreEqual(expectedCoefficients, FIR.OutputHn));
        }
        public void HighFilteredSignalTestMethod2()
        {
            FIR FIR = new FIR();

            var sig1 = UnitTestUtitlities.LoadSignal("TestingSignals/ecg400.ds");
            var expectedFilteredSignal = UnitTestUtitlities.LoadSignal("TestingSignals/ecg_high_pass_filtered.ds");

            FIR.InputFilterType          = DSPAlgorithms.DataStructures.FILTER_TYPES.HIGH;
            FIR.InputFS                  = 8000;
            FIR.InputStopBandAttenuation = 70;
            FIR.InputCutOffFrequency     = 1500;
            FIR.InputTransitionBand      = 500;

            FIR.InputTimeDomainSignal = sig1;

            FIR.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesIndicesAreEqual(expectedFilteredSignal, FIR.OutputYn));
        }
        public void CrossDirectNormalizedNonPeriodicCorrelationTestMethod2()
        {
            DirectCorrelation fc = new DirectCorrelation();

            var expectedOutput = new Signal(new List <float>()
            {
                0.2916059f, 0.3499271f, 0.4665695f, 0.0000000f, 0.0000000f, 0.0000000f, 0.0000000f
            }, false);

            fc.InputSignal1 = new Signal(new List <float>()
            {
                2, 1, 0, 0, 3
            }, false);
            fc.InputSignal2 = new Signal(new List <float>()
            {
                2, 1, 4
            }, false); fc.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput.Samples, fc.OutputNormalizedCorrelation));
        }
        public void CrossDirectNonNormalizedPeriodicCorrelationTestMethod2()
        {
            DirectCorrelation fc = new DirectCorrelation();

            var expectedOutput = new Signal(new List <float>()
            {
                0.7142857f, 0.8571429f, 1.1428571f, 0.8571429f, 0.4285714f, 1.7142857f, 0.2857143f
            }, false);

            fc.InputSignal1 = new Signal(new List <float>()
            {
                2, 1, 0, 0, 3
            }, true);
            fc.InputSignal2 = new Signal(new List <float>()
            {
                2, 1, 4
            }, true); fc.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput.Samples, fc.OutputNonNormalizedCorrelation));
        }
        public void DFTTestMethod1()
        {
            FastFourierTransform FFT = new FastFourierTransform();
            // test case 1 ..
            var sig1 = UnitTestUtitlities.LoadSignal("TestingSignals/DFT_Signal1.ds");

            FFT.InputTimeDomainSignal  = sig1;
            FFT.InputSamplingFrequency = 4;

            List <float> amplitude = new List <float> {
                64, 20.9050074380220f, 11.3137084989848f, 8.65913760233915f, 8, 8.65913760233915f, 11.3137084989848f, 20.9050074380220f
            };
            List <float> phase = new List <float> {
                0, 1.96349540849362f, 2.35619449019235f, 2.74889357189107f, 3.14159265358979f, -2.74889357189107f, -2.35619449019235f, -1.96349540849362f
            };

            FFT.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(amplitude, FFT.OutputFreqDomainSignal.FrequenciesAmplitudes) && UnitTestUtitlities.SignalsSamplesAreEqual(phase, FFT.OutputFreqDomainSignal.FrequenciesPhaseShifts));
        }
        public void BandStopFilteredSignalTestMethod4()
        {
            FIR FIR = new FIR();

            var sig1 = UnitTestUtitlities.LoadSignal("TestingSignals/ecg400.ds");
            var expectedFilteredSignal = UnitTestUtitlities.LoadSignal("TestingSignals/ecg_band_stop_filtered.ds");

            FIR.InputFilterType = DSPAlgorithms.DataStructures.FILTER_TYPES.BAND_STOP;

            FIR.InputFS = 1000;
            FIR.InputStopBandAttenuation = 60;
            FIR.InputF1             = 150;
            FIR.InputF2             = 250;
            FIR.InputTransitionBand = 50;

            FIR.InputTimeDomainSignal = sig1;

            FIR.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesIndicesAreEqual(expectedFilteredSignal, FIR.OutputYn));
        }
        public void BandPassCoefficientsTestMethod3()
        {
            FIR FIR = new FIR();

            var sig1 = UnitTestUtitlities.LoadSignal("TestingSignals/ecg400.ds");
            var expectedCoefficients = UnitTestUtitlities.LoadSignal("TestingSignals/BPFCoefficients.ds");

            FIR.InputFilterType = DSPAlgorithms.DataStructures.FILTER_TYPES.BAND_PASS;

            FIR.InputFS = 1000;
            FIR.InputStopBandAttenuation = 60;
            FIR.InputF1             = 150;
            FIR.InputF2             = 250;
            FIR.InputTransitionBand = 50;

            FIR.InputTimeDomainSignal = sig1;

            FIR.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesIndicesAreEqual(expectedCoefficients, FIR.OutputHn));
        }
        public void CrossFastNormalizedCorrelationTestMethod1()
        {
            FastCorrelation fc = new FastCorrelation();

            var expectedOutput = new Signal(new List <float>()
            {
                0.9667248f, 0.7352555f, 0.6807921f, 0.8577981f
            }, false);

            fc.InputSignal1 = new Signal(new List <float>()
            {
                4, 3, 1, 6
            }, false);
            fc.InputSignal2 = new Signal(new List <float>()
            {
                5, 2, 3, 7
            }, false);

            fc.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput.Samples, fc.OutputNormalizedCorrelation));
        }
        public void CrossDirectNormalizedPeriodicCorrelationTestMethod1()
        {
            DirectCorrelation fc = new DirectCorrelation();

            var expectedOutput = new Signal(new List <float>()
            {
                0.5974621f, 0.3502364f, 0.2472257f, 0.6180642f, 0.3502364f, 0.7210749f,
            }, false);

            fc.InputSignal1 = new Signal(new List <float>()
            {
                4, 3, 1, 6
            }, true);
            fc.InputSignal2 = new Signal(new List <float>()
            {
                5, 2, 3
            }, true);

            fc.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput.Samples, fc.OutputNormalizedCorrelation));
        }
        public void CrossDirectNonNormalizedPeriodicCorrelationTestMethod1()
        {
            DirectCorrelation fc = new DirectCorrelation();

            var expectedOutput = new Signal(new List <float>()
            {
                4.8333333f, 2.8333333f, 2.0000000f, 5.0000000f, 2.8333333f, 5.8333333f
            }, false);

            fc.InputSignal1 = new Signal(new List <float>()
            {
                4, 3, 1, 6
            }, true);
            fc.InputSignal2 = new Signal(new List <float>()
            {
                5, 2, 3
            }, true);

            fc.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput.Samples, fc.OutputNonNormalizedCorrelation));
        }
        public void CrossFastNonNormalizedCorrelationTestMethod1()
        {
            FastCorrelation fc = new FastCorrelation();

            var expectedOutput = new Signal(new List <float>()
            {
                17.7500000f, 13.5000000f, 12.5000000f, 15.7500000f
            }, false);

            fc.InputSignal1 = new Signal(new List <float>()
            {
                4, 3, 1, 6
            }, false);
            fc.InputSignal2 = new Signal(new List <float>()
            {
                5, 2, 3, 7
            }, false);

            fc.Run();

            Assert.IsTrue(UnitTestUtitlities.SignalsSamplesAreEqual(expectedOutput.Samples, fc.OutputNonNormalizedCorrelation));
        }