pythonmatlabscipylowpass-filter

Equivalent function in python for MATLAB's lowpass() function?


I have the following code in matlab that applies a filter to the "data" dataset. I would like to find the equivalent function in python.

epsilon = 8;
minpts = 12;
Normfreq = 0.0045;
Steepness = 0.9999;
StopbandAttenuation = 20;
filtered = lowpass(data, Normfreq, 'Steepness', Steepness, 'StopbandAttenuation', StopbandAttenuation);

Solution

  • Scipy is probably the best tool for this. You can use scipy's signal processing libraries.

    From their docs, they even offer matlab style filter desing.

    Matlab-style IIR filter design

    butter(N, Wn[, btype, analog, output, fs]) -Butterworth digital and analog filter design.

    buttord(wp, ws, gpass, gstop[, analog, fs]) - Butterworth filter order selection.

    cheby1(N, rp, Wn[, btype, analog, output, fs]) - Chebyshev type I digital and analog filter design.

    cheb1ord(wp, ws, gpass, gstop[, analog, fs]) - Chebyshev type I filter order selection.

    cheby2(N, rs, Wn[, btype, analog, output, fs])- Chebyshev type II digital and analog filter design.

    cheb2ord(wp, ws, gpass, gstop[, analog, fs]) - Chebyshev type II filter order selection.

    ellip(N, rp, rs, Wn[, btype, analog, output, fs])- Elliptic (Cauer) digital and analog filter design.

    ellipord(wp, ws, gpass, gstop[, analog, fs])- Elliptic (Cauer) filter order selection.

    bessel(N, Wn[, btype, analog, output, norm, fs]) - Bessel/Thomson digital and analog filter design.

    iirnotch(w0, Q[, fs]) - Design second-order IIR notch digital filter.

    iirpeak(w0, Q[, fs]) - Design second-order IIR peak (resonant) digital filter.

    You'd probably want to use a butterworth filter and then use the lfilter to apply the filter to your data.

    Ref to this SO answer for a more in-depht example.