2

I'm using Math.Net.Numerics to first fill an array with a sine wave, and then using Math.Net.Filtering to create a band pass to filter the data, like so:

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();
}

However, this does not seem to be filtering the samples at all, as can be seen here (identical):

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

What am I doing wrong? The documentation available for the library does not seem very complete yet so I've not learnt much from there.

user9993
  • 5,833
  • 11
  • 56
  • 117

1 Answers1

3

The ProcessSamples method doesn't appear to modify the input array, instead returning a new, filtered array. You need:

postProcessedData = bandPass.ProcessSamples(preProcessedData);

(Here's the documentation.)

Incidentally, this line from your code:

postProcessedData = preProcessedData;

probably doesn't do what you're thinking. It doesn't make a copy of the data; it merely points postProcessedData to the same array that preProcessedData is pointing at. So if ProcessSamples did modify the input array, preProcessedData and postProcessedData would be equal after processing.

adv12
  • 8,443
  • 2
  • 24
  • 48