How to apply a Zero-Phase filter using MathDotNet library?

为君一笑 提交于 2019-12-04 20:16:39

The following sample shows how to obtain a Zero-Phase filter by using the reverse-filtering technique and it also compares the result with that of a conventional lowpass filter. The signal being filtered is a 5Hz sine wave + white gaussian noise.

//signal + noise
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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!