MathNet.Filter 没有过滤数据
MathNet.Filter not filtering data
我使用 Math.Net.Numerics 首先用正弦波填充数组,然后使用 Math.Net.Filtering 创建带通来过滤数据,如下所示:
void Main()
{
double[] preProcessedData = new double[128];
double[] postProcessedData = new double[128];
//Generate sinewave (350Hz, 250 samples)
preProcessedData = MathNet.Numerics.Generate.Sinusoidal(250, 44100, 350, 20);
postProcessedData = preProcessedData;
MathNet.Filtering.OnlineFilter bandPass = MathNet.Filtering.OnlineFilter.CreateBandpass(MathNet.Filtering.ImpulseResponse.Finite, 44100, 390, 410);
bandPass.ProcessSamples(postProcessedData);
//LINQPad extensions
preProcessedData.Dump();
postProcessedData.Dump();
}
然而,这似乎根本没有过滤样本,如这里所见(相同):
Unfiltered Filtered
1.139189962 1.139189962
2.274680952 2.274680952
3.402786006 3.402786006
4.519842146 4.519842146
5.622222267 5.622222267
6.706346918 6.706346918
7.768695925 7.768695925
8.80581982 8.80581982
9.81435104 9.81435104
10.79101486 10.79101486
11.73264004 11.73264004
12.6361691 12.6361691
13.49866827 13.49866827
14.31733699 14.31733699
15.08951702 15.08951702
15.81270108 15.81270108
16.48454099 16.48454099
17.10285526 17.10285526
我做错了什么?该库可用的文档似乎还不是很完整,所以我没有从那里学到很多东西。
ProcessSamples
方法似乎没有修改输入数组,而是返回一个新的过滤数组。您需要:
postProcessedData = bandPass.ProcessSamples(preProcessedData);
(这里是 documentation。)
顺便说一下,您代码中的这一行:
postProcessedData = preProcessedData;
可能并没有按照您的想法行事。它不会复制数据;它只是将 postProcessedData
指向 preProcessedData
指向的同一个数组。所以如果ProcessSamples
did修改输入数组,preProcessedData
和postProcessedData
处理后相等
我使用 Math.Net.Numerics 首先用正弦波填充数组,然后使用 Math.Net.Filtering 创建带通来过滤数据,如下所示:
void Main()
{
double[] preProcessedData = new double[128];
double[] postProcessedData = new double[128];
//Generate sinewave (350Hz, 250 samples)
preProcessedData = MathNet.Numerics.Generate.Sinusoidal(250, 44100, 350, 20);
postProcessedData = preProcessedData;
MathNet.Filtering.OnlineFilter bandPass = MathNet.Filtering.OnlineFilter.CreateBandpass(MathNet.Filtering.ImpulseResponse.Finite, 44100, 390, 410);
bandPass.ProcessSamples(postProcessedData);
//LINQPad extensions
preProcessedData.Dump();
postProcessedData.Dump();
}
然而,这似乎根本没有过滤样本,如这里所见(相同):
Unfiltered Filtered
1.139189962 1.139189962
2.274680952 2.274680952
3.402786006 3.402786006
4.519842146 4.519842146
5.622222267 5.622222267
6.706346918 6.706346918
7.768695925 7.768695925
8.80581982 8.80581982
9.81435104 9.81435104
10.79101486 10.79101486
11.73264004 11.73264004
12.6361691 12.6361691
13.49866827 13.49866827
14.31733699 14.31733699
15.08951702 15.08951702
15.81270108 15.81270108
16.48454099 16.48454099
17.10285526 17.10285526
我做错了什么?该库可用的文档似乎还不是很完整,所以我没有从那里学到很多东西。
ProcessSamples
方法似乎没有修改输入数组,而是返回一个新的过滤数组。您需要:
postProcessedData = bandPass.ProcessSamples(preProcessedData);
(这里是 documentation。)
顺便说一下,您代码中的这一行:
postProcessedData = preProcessedData;
可能并没有按照您的想法行事。它不会复制数据;它只是将 postProcessedData
指向 preProcessedData
指向的同一个数组。所以如果ProcessSamples
did修改输入数组,preProcessedData
和postProcessedData
处理后相等