Here is a simple example of setting up a fir filter with a windowing function to improve it (for a 2 MSPS input and 125 kHz cutoff frequency):
double samplingRate = 2000000;
double cutoffFreq = 125000;
int filterWidth = 130;
var mathNetCoeffs = MathNet.Filtering.FIR.FirCoefficients.LowPass(samplingRate, cutoffFreq, filterWidth/2);
MathNet.Filtering.Windowing.BlackmanWindow blackmanWindow = new MathNet.Filtering.Windowing.BlackmanWindow();
blackmanWindow.Width = mathNetCoeffs.Length;
var windowArr = blackmanWindow.CopyToArray();
for (int i = 0; i < mathNetCoeffs.Length; i++) mathNetCoeffs[i] *= windowArr[i];
MathNet.Filtering.FIR.OnlineFirFilter mathNetFilter = new MathNet.Filtering.FIR.OnlineFirFilter(mathNetCoeffs);
The windowing function is very important for making a working filter. Hamming is another popular choice, but I’m using Blackman here. Then use the filter by calling ProcessSample or ProcessSamples:
double mathNetFiltered = mathNetFilter.ProcessSample(value);
Also note that the actual filter width will be filterWidth + 1. You want the actual filter width to be odd (for good filter symmetry), so set filterWidth to an even value.
转StackOverflow上的一个回复,亲测有效 https://stackoverflow.com/questions/43616110/mathnet-filtering-cutoff-frequency
但是滤波后存在相位延迟,需要进一步解决。