How to filter an EEG digital signal with Matlab?

Click For Summary

Discussion Overview

The discussion revolves around filtering a digital EEG signal using MATLAB, specifically focusing on the application of FFT (Fast Fourier Transform) and IFFT (Inverse Fast Fourier Transform) to manipulate frequency components. Participants explore the challenges of obtaining a real-valued output after filtering and the appropriate methods for applying filters in both frequency and time domains.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant describes their process of filtering a digital EEG signal using a notch filter and expresses confusion about receiving a complex vector after applying IFFT.
  • Another participant explains that the FFT operation is inherently complex and suggests using the square modulus to obtain a real-valued version.
  • A participant questions whether it is expected to receive a real vector from IFFT after modifying the complex vector obtained from FFT.
  • It is noted that if the modified complex vector does not maintain the Hermitian property, the inverse transform will not yield a real output.
  • There is a discussion about the nature of digital filters, with one participant suggesting that digital filters are typically applied in the time domain rather than the frequency domain.
  • A participant inquires about applying a filter designed with fdatool directly to the time domain signal, which is confirmed to be possible.
  • Several participants express a need for example EEG data to practice applying FFT.

Areas of Agreement / Disagreement

Participants generally agree on the properties of FFT and IFFT, but there are differing views on the application of filters in the frequency versus time domains. The discussion remains unresolved regarding the best practices for modifying complex vectors obtained from FFT.

Contextual Notes

Participants mention the importance of maintaining the Hermitian property of the Fourier transform for real signals, which could affect the outcome of the inverse transform. There is also a lack of consensus on the best approach to filtering in the context of EEG signal processing.

Who May Find This Useful

This discussion may be useful for individuals working with digital signal processing, particularly in the context of EEG data analysis, MATLAB programming, and those seeking to understand the implications of FFT and filtering techniques.

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
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K