MathNet.Filtering Bandpass Zero-Phase gives wrong results

258 Views Asked by At

I am trying to implement the filter described by jsanalytics from this question: How to apply a Zero-Phase filter using MathDotNet library?

I just copied the code and added PI, but I am getting some huge numbers in the end of the low pass filter, and the Zero-Phase does not look like the result of the original question.

This is my code from jsanalytics

        //signal + noise
        double pi = Math.PI;
        double fs = 1000; //sampling rate
        double fw = 5; //signal frequency
        double n = 5; //number of periods to show
        double A = 10; //signal amplitude
        double N = 2; //noise amplitude
        int size = (int)(n * fs / fw); //sample size

        var t = Enumerable.Range(1, size).Select(p => p * 1 / fs).ToArray();
        var noise = new WhiteGaussianNoiseSource();
        var y = t.Select(p => (A * Math.Sin(2 * pi * fw * p)) + (N * noise.ReadNextSample())).ToArray();

        //filter
        double fc = 10; //cutoff frequency
        var filter = OnlineFirFilter.CreateLowpass(ImpulseResponse.Finite, fs, fc);

        double[] yf1 = filter.ProcessSamples(y); //Lowpass
        double[] yf2 = filter.ProcessSamples(yf1.Reverse().ToArray()); //Lowpass reversed
        double[] yf2r = yf2.Reverse().ToArray(); //Zero-Phase

This the result of my code : enter image description here

Question: How do i get my results to match jsanalytics?

0

There are 0 best solutions below