Skip to content

Lowpass filter response with example application #18

@hulaomr

Description

@hulaomr

Hello,

Using the following example (with release 0.7.0 from NuGet), the low pass filter has a unexpected response.

` double fs = 1000; //sampling rate
double fw = 5; //signal frequency
double fn = 50; //noise frequency
double n = 5; //number of periods to show
double A = 1; //signal amplitude
double N = 0.1; //noise amplitude
int size = (int)(n * fs / fw); //sample size

        var t = Enumerable.Range(1, size).Select(p => p * 1 / fs).ToArray();
        var y = t.Select(p => (A * Math.Sin(2 * Math.PI * fw * p)) + (N * Math.Sin(2 * Math.PI * fn * p))).ToArray(); //Original 

        //lowpass filter 
        double fc = 10; //cutoff frequency 
        var lowpass = OnlineFirFilter.CreateLowpass(ImpulseResponse.Finite, fs, fc);

        //bandpass filter 
        double fc1 = 0; //low cutoff frequency 
        double fc2 = 10; //high cutoff frequency 
        var bandpass = OnlineFirFilter.CreateBandpass(ImpulseResponse.Finite, fs, fc1, fc2);

        //narrow bandpass filter 
        fc1 = 3; //low cutoff frequency 
        fc2 = 7; //high cutoff frequency 
        var bandpassnarrow = OnlineFirFilter.CreateBandpass(ImpulseResponse.Finite, fs, fc1, fc2);

        double[] yf1 = lowpass.ProcessSamples(y); //Lowpass 
        double[] yf2 = bandpass.ProcessSamples(y); //Bandpass 
        double[] yf3 = bandpassnarrow.ProcessSamples(y); //Bandpass Narrow `

The original signal (plus noise) is on the following chart:

image

The lowpass filter response is below:

image

The bandpass filter response is below:

image

The bandpass with narrow band is below:

image

All the signals involved in this test application are below:

image

Any advice regarding the response of the lowpass filter is appreciated.

Attached is the Source Code and VS2019 example application for your reference.

Thanks

FilterExample.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions