问题
Is there a specific function or class in the Math.NET library to obtain a Zero-Phase (non causal) IIR filter?
If not, how can this be achieved using current functions? I believe this can be obtained by filtering the signal and then filtering the reverse, but I'm not sure the result is correct.
回答1:
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
来源:https://stackoverflow.com/questions/47204103/how-to-apply-a-zero-phase-filter-using-mathdotnet-library