so I've been trying to implement a low pass filter in C# with the Mathnet filtering library. I have a problem because I don't know how to use the method to create coefficients for the filter. Can someone tell me how to specify the cutoff frequency(it has to be in samples per unit)? For example, if I want the cutoff frequency to be 400Hz, how much is that in samples per unit? Thanks.
public Filter(ISampleProvider _source, long Length, int _cutoff)
{
source = _source;
cutoffFrequency = _cutoff;
float[] s = new float[Length];
_source.Read(s, 0, (int)Length);
Normalize(s);
var coefficients = MathNet.Filtering.FIR.FirCoefficients.LowPass(_source.WaveFormat.SampleRate, (double)400/ ((double)source.WaveFormat.SampleRate/(double)Length), 2);
MathNet.Filtering.FIR.OnlineFirFilter filter = new MathNet.Filtering.FIR.OnlineFirFilter(coefficients);
double[] output = Array.ConvertAll(s, x => (double)x);
double[] output2 = filter.ProcessSamples(output);
output1 = new float[output2.Length];
for (int i = 0; i < output2.Length; i++)
{
output1[i] = Convert.ToSingle(output2[i]);
}
}
I've tried to divide my wanted frequncy by the frequency resolution of my signal but this way the signal doesn't seem to change at all.