Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to filter an EEG digital signal with Matlab?

  1. Jun 4, 2007 #1
    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. jcsd
  3. Jun 4, 2007 #2

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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
     
  4. Jun 4, 2007 #3
    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 =)
     
  5. Jun 4, 2007 #4

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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
     
  6. Jun 4, 2007 #5

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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
  7. Jun 4, 2007 #6

    cepheid

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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.
     
  8. Jun 4, 2007 #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!
     
  9. Jun 4, 2007 #8

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Yes, just use the 'filter' function.

    - Warren
     
  10. Jun 4, 2007 #9
    EEG FFT and filter with Matlab

    Thank you, I've been searching this for days :rofl: :approve:
     
  11. Jun 4, 2007 #10

    chroot

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    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
     
  12. Jun 4, 2007 #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
     
  13. Oct 19, 2010 #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?
     
  14. Oct 19, 2010 #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.
     
  15. Oct 19, 2010 #14
    Thanks it would be great!!
    and not too long it does not metter i just need one to apply the fft to it
     
  16. Jan 4, 2011 #15
    I need one digital EEG sample, just for doing some signal processing. than you
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: How to filter an EEG digital signal with Matlab?
  1. Noise Filter In Matlab (Replies: 1)

Loading...