# Pre-processing EEG signals

Good Afternoon Everybody.

I am developing filters for EEG signals in these days. During the Develop I find some problems:

The filter is FIR (band-pass using a convolution of low-pass filter and high-pass filter) they are 5 filters in different bands and the order is high and the coefficients are very small. I have coefficients of range from 3.8145e-10 to 0.2279, and the filter orders are:

Alpha: 133 Beta: 117 Theta: 124 Delta: 11 (IIR filter) Gamma: 125

The lines codes (only of the filters) are these:

%%Filtro for alpha, beta and gamma signals is the same
[n,fo,ao,peso]=firpmord([Fapp2 Fass2],[1 0],[0.005 0.005],2);
ba=firpm(n,fo,ao,peso);
[n1,fo,ao,peso]=firpmord([Fass1 Fapp1],[0 1],[0.005 0.005],2);
b1a=firpm(n1,fo,ao,peso);
ba=conv(ba,b1a);
Na=length(ba);

%%Filtro señal theta
[n,fo,ao,peso]=firpmord([Ftpp2 Ftss2],[1 0],[0.005 0.1],2);
bt=firpm(n,fo,ao,peso);
[n1,fo,ao,peso]=firpmord([Ftss1 Ftpp1],[0 1],[0.1 0.005],2);
b1t=firpm(n1,fo,ao,peso);
bt=conv(bt,b1t);
Nt=length(bt);

%%Filtro señal delta
[n,Wn]=buttord(Fdpp2, Fdss2,0.005,60);
[n1,Wn]=buttord(Fdss1,Fdpp1,0.005,60);
[b1d,a1d]=butter(n1,Wn,'high');
bd=conv(bd,b1d);


This part is only the pre-processing part but the coefficients are very small. the Fs is 250Hz and the delay group will be 0.5320 seconds. If I change IIR filter to FIR the order is near 200 and the delay group will be major (I tried that using only the band-pass filter without the convolution but the order was major than the actual orders). my questions are:

• Are there methods for reduce order of the filter without lose quality as the ripple or attenuation?

• If I change FIR by IIR, could I lose or distort information?

• Is normal that the coefficients be very small or how could I convert them in bigger numbers (near to order of 0.01 or 0.001 as minimum)?

Also, I tried to use only High-pass filter and Notch Filter then to do the features extractions but I have similar problem with the delay group too because I want to implement in a FPGA or DSP (for real time process) but the delay group is high compare with anothers works like my work.

Sorry, my english is not good. Thank you so much for your time.

The advantage to using FIR-filters here is that you can (relatively easily) account for the delay.
Assuming filters with constant group delay (see examples here,) - which seems likely given that your filters have an odd number of taps - all you have to do is to remove (n-1)/2 samples (where n is the filter order) from the beginning of your data after it has gone through the filter.

For example: Filter your data with the Alpha filter.
It is now longer by 133 samples.
Remove (133-1)/2 samples from the start of the filtered data, and the delay is gone. Do the same for all of your filters, and you can keep the output of all of your filters in sync.

With an IIR, the delay is not that simple to account for. Getting the outputs of you filter back in sync would be challenging if you used IIR filters.

If keeping the filtered signals in sync isn't important, you could switch to using IIR filters for all of your filters.

This would greatly reduce the computational load as well as the amount of memory needed.

As with the FIR, there are design methods for IIR that use the desired passband, ripple, and attenuation to calculate the needed coefficients so that you should be able to generate coefficients for the IIR filters that match your FIR filters in everything except having a constant delay.

As for the coefficients, I wouldn't worry about the actual values unless you have trouble representing them on your selected hardware. Use what your design tool gives you for the coefficients.

There are design tools which can help improve your FIR filters. Check some of the online tools (like this one.) Given the separation of the various bands (wikipedia entry for EEG,) it looks to me like your current filters can't be provoding very good performance, any way. I get only 22dB of attenuation using 133 taps for the alpha filter.

IIR filters that sharp may be difficult to attain, and may be unstable.

It all depends on how much attenuation you need. Since the bands are defined with only a 1Hz transition, any high degree of attenuation will require high order IIR filters or very long FIR filters.

As with any design project, it comes down to making the best compromise between performance and cost - and you need to know what performance is required.

Are there methods for reduce order of the filter without lose quality as the ripple or attenuation?

For any filter implementation there will be compromise/trade-off between Filter Order, Passband and Stopband ripple and Transition band.

If Sharp roll-off is your main priority, then explore Chebychev(type II) filters.

The filtfilt() function in Matlab will remove the group delay due to the filter, but will double the filter order and hence may increase the processing time.

Frequency domain using FFT is usually faster than time-domain convolution of transfer function and signal.

If I change FIR by IIR, could I lose or distort information?

IIR filters are not linear phase and this will distort the signal based on the extent of non-linearity of phase. If the phase response is close to linear, then it can be considered to a linear. It all depends on what your application is. If you want to extract cognitive information from the EEG signal through information theory based approaches, then you will need a very clean signal. On the other hand, if it is just to identify spatial or temporal activation of EEG bands, for example, excitation of Alpha band over time when a subject is presented with sporadic visual stimuli, then you will only need approximate estimation of PSD in the Alpha band over time for visualizations like spectrograms.

Is normal that the coefficients be very small or how could I convert them in bigger numbers (near to order of 0.01 or 0.001 as minimum)?

Why would you want to increase the coefficients? Coefficient are just weights for delay components of the signal. Small coefficient means lesser weightage for the corresponding frequency component. If certain coefficient are very small relative to the mean of the signal, then you should be approximating them to zero to get some minor computational gain rather than increasing them.

Notch filter is generally used only for removing Line noise at 60 Hz.

mmm... Sorry I didn't know it, then I will use High-pass Filter and Notch filter and maybe a Low-pass filter, after that I will try to analyze with anothers feature extraction methods.

But for implementation I need a low order, I read about filtfilt() and only like help in the simulation part, the Low-pass filter has the range of 0-100Hz and the High-pass 0.5Hz-Fs=500/2. But I am continue having hgh orders, I could try to do the convolution between a IIR filter and FIR filter for reduce the ripple and not loss the trade-off

I am proving FDATOOL of MATLAB too.

Again sorry for my english.

Thank you so much for your time.

• You can post comments on the answers by clicking on 'add a comment' below the answers. "I could try to do the convolution between a IIR filter and FIR filter" I don't think that's going to help. If you convolve the transfer function or the IIR and FIR, the order of such a filter will be slightly higher than the maximum order among the two - which is the FIR order. By "convolution" are you referring to a multistage filter with IIR and FIR stages? – Naveen Jun 9 '15 at 20:15
• Thank you, mmm.. I try to remove DC components (0-0.5Hz), and frequencies upper to 100Hz also the frequency of the 60Hz, I have used a IIR Notch Filter for erase the frequency of 60Hz but When I use the FIR high-pass filter (Fp=0.5 Fs=0-25 or 0) the order is high and I can't implement it because in a DSP or FPGA the delay group is about 0.7 seg Fs=250 or 500Hz. – Edgar Medina Castañeda Jun 10 '15 at 0:16