For filtering you'd need the Math.NET Filtering library in addition to Math.NET Numerics. Note that Filtering is only available as preview release yet. Indeed, there seems to be an issue with IIR filter design, but it works with FIR filters.
Essentially you could apply several band-pass filters and then choose the frequency band where the resulting signal has the highest energy.
In LINQPad:
Thanks,
Christoph
Essentially you could apply several band-pass filters and then choose the frequency band where the resulting signal has the highest energy.
In LINQPad:
void Main()
{
var sampleRate = 500; // 500 Hz sampling rate
var signal = Generate.Sinusoidal(1000,sampleRate,90,1.0); // 90 Hz sinus
BandEnergy(signal, sampleRate, 0, 25).Dump("0..25");
BandEnergy(signal, sampleRate, 25, 85).Dump("25..85");
BandEnergy(signal, sampleRate, 85, 180).Dump("85..180");
BandEnergy(signal, sampleRate, 180, 250).Dump("180..250");
}
double BandEnergy(double[] signal, double sampleRate, double lowCutoff, double highCutoff)
{
var filter = OnlineFilter.CreateBandpass(ImpulseResponse.Finite, sampleRate, lowCutoff, highCutoff);
var filtered = filter.ProcessSamples(signal);
return Vector<double>.Build.Dense(filtered).L2Norm();
}
returns:0..25
0.329663254046423
25..85
1.22288405899457
85..180
22.2095816072106
180..250
0.185562999270445
Hence the dominant frequency band is 85..180 Hz, as expected for a 90 Hz sinus signal.Thanks,
Christoph