A recommended method for designing Filters in MATLAB using the Signal Processing Toolbox is to apply a specification-based filter design methodology using the **fdesign** function to create a filter design specification object that contains the specifications for a filter

such as :

- Passband Ripple (amount of ripple or variation we allow in the passband)
- Stopband Attenuation (reduction in signal we want in the stopband)
- Passband Frequency (highest frequency we want to let through our filter)
- Stopband Frequency (frequency beyond which we want to block all the frequencies in our filter)

We avoid a lot of trial & error by getting a list in MATLAB for all the design methods which are available to us, by using **designmethods** function to determine the filter design methods that work for the new filter specification object. Then, use the **design** function to design the filter from the filter design specifications object.

The class of digital filters may broadly be categorized into finite impulse response (FIR) and infinite impulse response (IIR) filters.

FIR filters are quite stable and their impulse response is of finite period (they settle to zero in finite time). As they do not use previous output values to compute their present output ie they have no feedback, they can never become unstable for any type of input signal which gives them distinct advantage over IIR filters. Most FIRs are linear phase filters. They are linear where the phase response of the filter is a linear (straight-line) function of frequency and this occurs if it’s coefficients are symmetrical around the center coefficient. They are generally chosen for applications where linear phase is important and a decent amount of memory and computational performance are available. If linear phase, no ‘phase distortion’ is introduced into the signal to be filtered as all frequencies are shifted in time by the same amount (ie constant phase delay). They also have fixed point performance advantages since the effects of quantization are less severe than that of an IIR. They are widely deployed in audio and biomedical signal enhancement applications.

IIR on the other hand will respond indefinitely (infinite nature of the impulse response). It can be viewed as 2 FIR filters, one of which is connected in a feedback loop. The feedback loop one is the ‘recursive’ section compared to the other ‘non-recursive’ one. Need to ensure that the ‘recursive’ section is stable. Therefore, an IIR filter has both poles and zeros and have to restrict all the poles (ie the ‘recursive’ part) inside the unit circle for the overall filter to be stable. The phase characteristics of an IIR filters are generally non-linear especially near the cut-off frequencies. They require more scaling and numeric overflow analysis when implemented in fixed point. It can have fewer components/less coefficients & memory (lower implementation cost) than FIR for frequency selective filter designs. They have been widely deployed in audio equalisation, biomedical sensor signal processing, IoT smart sensors and high-speed telecommunication/RF low latency applications due to their low number of coefficients.

An FIR ‘Equiripple’ Low Pass Filter (LPF) type in the MATLAB example below requires 175 multipliers & 174 adders compared to IIR ‘Ellip’ LPF which only requires 16 of each. So FIRs usually require many more coefficients for achieving a sharp cut-off than their IIR counterparts. The consequence of this is that they require much more memory and significantly a higher amount of MAC (Multiply-Accumulate) operations.

The longer the filter is, the more number of operations it takes to execute the filter when running it. The higher the order of the filter, the more arithmetic operations it takes and this leads to more hardware (number of adders, multipliers etc). We may want to compromise on the stopband attenuation for the sake of a lower filter order. However, the stopband attenuation is very important. We may have to trade it off for a more complex filter in terms of it’s implementation.

Can enquire about the filter structure and it’s properties by using the **info** function eg

```
'Filter Structure : Direct-Form FIR'
'Filter Length : 175 '
'Stable : Yes '
'Linear Phase : Yes (Type 2) '
```

Can also use the **cost** function of filter objects to estimate computational complexity. This gives us the number of multipliers, adders, states and operations per sample.

Here is the MATLAB code that illustrates how to apply the specification-based filter design methodology :