# what is the suitable design Method to the filter?

hi i'm going to design a low pass FIR filter for an EEG signal for the detection of eppileptic siezure and i want to know what is the suitable design Method to the filter? i need this FIR filter just to smooth the signal to use it for discret wavelet transform. thanks

• Hi! Are there any application specific constraints on the FIR filter to be designed? If so please specify them... – Fat32 Mar 24 '17 at 18:46
• Low-pass filters with 3 dB of ripple in the pass-band from 0 to 64 Hz and at least 60 dB of attenuation in the stop-band – afef Mar 24 '17 at 18:52
• Also the sampling frequency $Fs$ is required to define the cutoff frequency $\omega_c$ of the discrete-time filter, however, as your question states you are looking for a suitable design method? This suggests that your filter has some constraints such as minimum length filter ? If this is not the case then any method of FIR filter design should work. – Fat32 Mar 24 '17 at 20:24
• the sampling frequency of the signal is 256 HZ – afef Mar 24 '17 at 22:12

For a quick filter design without getting into trouble, I recommend avoiding any IIR structure and design an FIR using either least squares (firls in matlab) or Parks McClellan (firpm in matlab, remez in octave). There are plenty of answers here on how many taps you will need, (such as How many taps does an FIR filter need?) so you start with that for initial guidance and then refer to the specific help for firpm or firls for further design details using those tools.

Below is a slide I have on my typical design path for simple linear phase FIR filters. Starting with the specifications I estimate the number of taps, and then use that estimate to come up with (floating point) coefficients. I then confirm (using freqz in Matlab, Octave or Python typically) passband and stopband performance and adjust number of taps accordingly. Once the number of coefficients and values is settled, I then map to a fixed point implementation if needed using the guidance further given below and again confirm performance specifications. For final verification, especially if I have gone to fixed point, I do actual SNR testing with test waveforms through the filter at the maximum and minimum signal levels I would expect in my application using test waveforms. This is a good way to confirm that there are no disastrous overflow conditions or poor assumptions on quantization levels needed to maintain a target SNR directly at a component level test.

Design Tools:

Matlab: firpm, firls

Octave: remez, firls

Python: scipy.signal remez, firls

Online Tools:

Equiripple (Parks-McClellan): http://cnx.org/content/m12799/latest/

Least squares: http://cnx.org/content/m10577/latest/

Other tips:

Scale the output, let the filter grow the signal! I think it was fred harris that had the view of analog filters attenuating signals out of band while digital signals grow the signal in band. I found that very insightful. To adjust the output level, scale after the filter; don't be tempted to adjust the output by scaling the input or scaling your coefficients (as it degrades SNR, output noise is accumulated noise from every tap and scaling coefficients increases their own individual error terms), beyond scaling to the proper precision setting as suggested below. This is the reason for "extended precision accumulators"; they let the accumulated value from every tap grow and then once accumulated truncate the output in one location.

Coefficient bit width: A reasonable rule of thumb is to use at least 2 more bits for your coefficients than your datapath width if your datapath was sized based on SNR (or 2 more bits than your SNR requirement directly if your datapath is much wider than necessary).

You can also size the coefficient width based on your rejection requirement using 6 dB/bit (if you need a filter with 60 dB rejection, use 12 bits for your coefficients, with the coefficients scaled to fill that precision of course). Typically actual rejection achieved if limited by coefficient bit width is on the order of 5 to 6 dB / bit; I like to add at least the extra 2 bits for margin unless my design is severely resource constrained in that area.

Least Squares vs Parks McClellan (equiripple): In most of my design applications related to communications I have been more concerned with overall signal and noise than an absolute limit at any one given frequency, so typically use the Least Squares design method. That is the distinction between the two design choices (LS or P-McC) explained simply: Least Squares will minimize the error in a least squares sense, while Park McClellan minimizes the absolute error. Given the same number of taps, the total noise due to pass-band ripple and finite out of band rejection will be less with the Least Squares design approach when integrated over the entire waveform in time or over all frequencies, while the peak error at specific locations in time or frequency can be worst.

Given your sampling and cutoff frequencies in Hz, then your discrete time filter's cutoff frequency $\omega_c$ is $\pi /2$ for [0,$\pi$] mapping or 0.5 if you prefer [0,1] mapping.

This FIR filter will be very easy to design with the most classical window method provided by fir1 function of matlab/octave.

Or you can as well use equiripple FIR filter design such as provided by the remez function of matlab/octave (Parks-McClellan equiripple FIR filter design) if you think you need minimum number of taps to meet the specifications.

The window method with a hamming window gives you the coefficients as follows:

$$h_i[n] = \frac{1}{2\pi} \int_{-\pi/2}^{\pi/2} {1 e^{j\omega n} d\omega}$$ $$h_i[n] = \frac{\sin(n\pi/2)}{\pi n}$$ where $h_i[n]$ is the impulse response of the ideal lowpass FIR filter and the actual filter is obtained by windowing as $$h[n] = h_i[n] w[n]$$

Where $w[n]$ is a Hamming window of length $2N+1$. For attaining a 60 dB rejection in the stop band, with a small transition band, choose length N about 40. So this makes an FIR filter of about 81 taps. If this is too much computation or signal delay for your application, then you can consider using a Kaiser window instead. If a Kaiser window can still not meet your requirements, then apply an equiripple Remez (Parks McClellan) design.

An example FIR filter frequency response is plotted with 81 coefficients: