Have fun with sci.dog

使用Math.net库进行FIR滤波的程序实例

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

但是滤波后存在相位延迟,需要进一步解决。

赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《使用Math.net库进行FIR滤波的程序实例》
文章链接:https://www.sci.dog/?p=883
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发