How to filter an EEG digital signal with Matlab?

In summary: The problem is that when I use ifft, I understand I'd get a real vector, but I get a complex one. 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?
  • #1
lmartinez
7
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
  • #2
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
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 =)
 
  • #4
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
 
  • #5
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:
  • #6
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:

[tex] \mathcal{F}\{f(t)\} = \hat{F}(\omega) [/tex]

[tex] f(t) \in \ \mathbb{R}\ \forall \ t \Leftrightarrow \hat{F}(-\omega) = \hat{F}^*(\omega) [/tex]

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
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
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
 
  • #9
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
 

Related to How to filter an EEG digital signal with Matlab?

1. What is EEG and why is it important?

EEG stands for electroencephalography, which is a method of recording the electrical activity of the brain. It is important because it allows researchers and doctors to study brain function and diagnose neurological disorders.

2. How do I import an EEG signal into Matlab?

To import an EEG signal into Matlab, you can use the "load" function or the "importdata" function. Both methods allow you to load the signal from a file or directly from a device.

3. What is the process for filtering an EEG signal in Matlab?

The process for filtering an EEG signal in Matlab involves several steps. First, you need to design a filter based on your specific needs. Then, you need to import the EEG signal and apply the filter using the "filter" function. Finally, you can visualize the filtered signal using the "plot" function.

4. What are the common types of filters used for EEG signals?

The most common types of filters used for EEG signals are low-pass, high-pass, band-pass, and notch filters. Low-pass filters remove high-frequency noise, high-pass filters remove low-frequency noise, band-pass filters allow a specific frequency range to pass through, and notch filters remove a specific frequency band.

5. Can I customize the filter parameters in Matlab?

Yes, you can customize the filter parameters in Matlab to suit your specific needs. The "designfilt" function allows you to design a filter with custom parameters such as filter type, cutoff frequency, and filter order. You can also use the "fdatool" app to interactively design and customize your filter.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
809
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
Back
Top