MATLAB How to filter an EEG digital signal with Matlab?

AI Thread Summary
The discussion revolves around processing EEG signals using MATLAB, specifically focusing on filtering techniques. The user initially designed a notch filter to eliminate 50 Hz frequencies and applied it in the frequency domain using FFT and IFFT. However, they encountered issues where the output from IFFT was complex instead of the expected real vector. It was clarified that the FFT of a real signal is inherently complex, and if modifications to the complex vector disrupt the Hermitian property, the inverse transform will yield a complex result. The importance of applying filters correctly was emphasized, noting that digital filters are typically applied in the time domain rather than the frequency domain. The user was advised to use MATLAB's 'filter' function for applying filters designed with fdatool directly to the time domain signal. Additionally, there was a request for example EEG data to practice FFT processing, which another user offered to provide.
lmartinez
Messages
7
Reaction score
0
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.
 
Physics news on Phys.org
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
 
Processing digital signal with Matlab (FFT and filter)

chroot said:
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

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 =)
 
lmartinez said:
but I if I modify the complex vector obtained with fft (for example if I apply a filter) I still get a complex vector.

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
 
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:
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.
 
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!
 
lmartinez said:
I was trying to use a filter designed with fdatool. So, can I apply this imported filter directly on my time domain signal?

Yes, just use the 'filter' function.

- Warren
 
EEG FFT and filter with Matlab

Thank you, I've been searching this for days :smile: :approve:
 
  • #10
lmartinez said:
Thank you, I've been searching this for days :smile: :approve:

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
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 :redface:

Liz
 
  • #12
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
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
Thanks it would be great!
and not too long it does not metter i just need one to apply the fft to it
 
  • #15
I need one digital EEG sample, just for doing some signal processing. than you
 

Similar threads

Replies
5
Views
2K
Replies
4
Views
2K
Replies
10
Views
3K
Replies
5
Views
6K
Replies
11
Views
3K
Replies
4
Views
3K
Back
Top