Search code examples
matlabfilteringsignal-processing

MATLAB signal processing: knowing order of FIR filter to be designed


For didactical purposes i want to create a lowpass FIR filter (of any type, Equiripple will be ok) that attenuate an 'omega1' frequency (example: 0.3 rad/s, normalized) of at least 80 dB.

I know that for IIR Butterworth filters there is a function called "buttord", which compute the cut frequency and the minimum order required by the IIR filter by knowing:

  1. The edge of the pass band
  2. The edge of the stop band
  3. Maximum ripple allowed in the passband
  4. Maximum ripple allowed in the stopband

I'm looking for something similar for FIR filters, in order to compute filters coefficients by fir1 or firpm functions. I managed to design my filter using the filterDesign graphical tool of MATLAB, but I'm trying to entirely design the filter by code scripting.


Solution

  • 1. Open the MATLAB filterDesigner app

    typing filterDesigner in MATLAB command prompt

    and design your filter BUT do not use the zero pole editor

    Just define the template of the above 80dB frequency notch.

    If filterDesigner app not yet installed, install it directly from the MATLAB Apps store available inside MATLAB, not from external app stores like Google Play or Apple Store.

    2. Once filter ready open

    File > Generate MATLAB Code > Filter Design Function

    MATLAB saves you the effort and automatically produces all the code you are asking for, inside a function.

    If you don't need a function, just take the code lines you need inside the generated function

    filterDesigner can also export your design to a SIMULINK block and to a C function.

    MATLAB filterDesigner generates C code for you, check for more details here :

    https://uk.mathworks.com/help/signal/ug/getting-started-with-filter-designer.html