# How to filter an EEG digital signal with Matlab?

1. Jun 4, 2007

### lmartinez

I have a digital signal from EEG recording. I need to filter 50 Hz frequencies and 0.5 to 120 Hz, so I've tried this:
1. I designed a notch filter with Matlab.
2. I used fft to transform the signal to frecuency domain.
3. I applied the notch filter.
4. I used ifft to get back to time domain.

The problem is that when I use ifft, I understand I'd get a real vector, but I get a complex one.

I've also tried to modify something (just a digit) from the complex vector that I get with fft and when I use ifft, I don't get the original, but a complex one.

Can anybody tell me what's wrong?
Thank you very much.

2. Jun 4, 2007

### chroot

Staff Emeritus
The FFT is by definition a complex operation. If you want a real-valued "version" of the FFT, take it's square modulus. The abs() function will do this for you.

- Warren

3. Jun 4, 2007

### lmartinez

Processing digital signal with Matlab (FFT and filter)

Thank you Warren, I undestand this, but I mean, is it not supposed to get a real vector back if I use Fourier antitransform ifft?

If I try to apply fft to a vector, I get a complex one -until here it's ok- then with ifft, I'm supposed to get the original vector (real).. and I get it, but I if I modify the complex vector obtained with fft (for example if I apply a filter) I still get a complex vector. Then is it correct to apply abs() to this complex vector I get or I'm getting something wrong?

I hope my question is clear =)

4. Jun 4, 2007

### chroot

Staff Emeritus
If you modify the complex vector that results from the fft in such a way that it is no longer an even function (the same on both sides of zero frequency), then its inverse transform will no longer be real.

- Warren

5. Jun 4, 2007

### chroot

Staff Emeritus
By the way, what kind of "filter" are you applying in the frequency domain? Normally, digital filters are applied in the time domain. Certainly, a "notch filter" in the frequency domain does not need to be designed -- you just need to zero out the bins in the fft corresponding to your notch.

- Warren

Last edited: Jun 4, 2007
6. Jun 4, 2007

### cepheid

Staff Emeritus
The FT of an arbitrary REAL signal will be Hermitian, which in this context means that it will be a complex function that for every positive value of omega, the value of the function at the corresponding negative value of omega will be the complex conjugate:

$$\mathcal{F}\{f(t)\} = \hat{F}(\omega)$$

$$f(t) \in \ \mathbb{R}\ \forall \ t \Leftrightarrow \hat{F}(-\omega) = \hat{F}^*(\omega)$$

Another way of saying this is that the real part of the FT of a real signal will be EVEN, and the imaginary part will be ODD. If your filter altered the spectrum in such a way that it no longer satisfied this property, then its inverse FT would no longer be real, I imagine. ;) So...how exactly did you apply a filter to the complex FT of the signal?

EDIT: While I was fiddling around with fancy LaTeX notation, Chroot beat me to it.

7. Jun 4, 2007

### lmartinez

Ok, I got it, in my test I wasn't modifying it in both sides, thank you.

This last question please: maybe the principal error was that I didn't know digital filters are applied in time domain... I was trying to use a filter designed with fdatool. So, can I apply this imported filter directly on my time domain signal?

Thank you very much!

8. Jun 4, 2007

### chroot

Staff Emeritus
Yes, just use the 'filter' function.

- Warren

9. Jun 4, 2007

### lmartinez

EEG FFT and filter with Matlab

Thank you, I've been searching this for days :rofl:

10. Jun 4, 2007

### chroot

Staff Emeritus
Hey no prob. You'll find that MATLAB's help files are quite good, as long as you know some relevant place to begin searching!

To use the filter function with a digital filter designed by fdatool, stored in a variable called Hd, just do this:

output = filter(Hd, input);

By the way, you might be interested in MATLAB's built-in signals, like handel and chirp.

- Warren

11. Jun 4, 2007

### lmartinez

Yes, I'm beginning with Matlab, I was looking for in the Filter Design Toolbox and FFT help...

I'll search this handel and chirp.

If I need more help I'll write you

Liz

12. Oct 19, 2010

### AosorioF

How did you get the vector to use the fft?
it is just that i need one example vector from a EEG, could anyone give me one?

13. Oct 19, 2010

### lmartinez

From a digital electroencephalograph. It's was an analog signal converted to digital.
How long do you need it? I can send you one.

14. Oct 19, 2010

### AosorioF

Thanks it would be great!!
and not too long it does not metter i just need one to apply the fft to it

15. Jan 4, 2011

### ghilankeshe

I need one digital EEG sample, just for doing some signal processing. than you