Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Low Pass filter: different results in versions 0.5.0 and 0.6.0 #15

Open
h28669 opened this issue Jan 31, 2019 · 1 comment
Open

Low Pass filter: different results in versions 0.5.0 and 0.6.0 #15

h28669 opened this issue Jan 31, 2019 · 1 comment

Comments

@h28669
Copy link

h28669 commented Jan 31, 2019

I have upgraded our project from Math.Net.Filtering 0.5.0 to 0.6.0 Now I get completely different results with LowPass filter.

Example
var frequency = 1d / 360d;
var samplingFrequency = 0.1; // Nyquist: sampling rate must be at least double the frequency
var amplitude = 1;
var seriesLength = 10;
var input = Generate.Sinusoidal(seriesLength, samplingFrequency, frequency, amplitude);
var filter = new LowPassFilter();

Result with 0.5.0 {0, 0.032, 0.203, 0.4, 0.584, 0.751, 0.895, 1.012, 1.098, 1.151};
Result with 0.6.0 {0, -0.003, -0.004, -0.005, -0.008, -0.007, -0.01, -0.009, -0.009, -0.012}

Which one is correct? Do I need to change something when setting up filter?

Within my wrapper class "LowPassFilter" the filter is created as follows:
The values used are: filter.CutOffFrequency = 0.04; filter.OrderOfFilter = 2;

protected override OnlineFilter CreateFilter() {
return OnlineFilter.CreateLowpass(ImpulseResponse.Finite, SamplingFrequency, CutOffFrequency.Value, OrderOfFilter);
}

Thanks for help
Gianni

@SOCMarcel
Copy link

Hello,

as far as I unterstand the source code (https://github.com/mathnet/mathnet-filtering/blob/master/src/Filtering/OnlineFilter.cs, https://github.com/mathnet/mathnet-filtering/blob/master/src/Filtering/FIR/FirCoefficients.cs) there seems to be an issue with CreateLowpass(ImpulseResponse mode, double sampleRate, double cutoffRate, int order):

In case of passed mode ImpulseResponse.Finite the following code is executed:
double[] c = FirCoefficients.LowPass(sampleRate, cutoffRate, order >> 1);
return new OnlineFirFilter(c);
Yet as you can see in the history (probably corresponding to version change from 0.5 to 0.6) the signature of FirCoefficients.LowPass(...) changed from
public static double[] LowPass(double samplingRate, double cutoff, int halforder = 0)
to
public static double[] LowPass(double samplingRate, double cutoff, double dcGain = 1.0, int halforder = 0)

So from my point of view the order parameter from CreateLowpass(...) gets now passed as dcGain to FirCoefficients.LowPass(...) instead of halforder which results in incorrect coefficients.

Kind regards.
Marcel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants