Why my EEG raw data can not be processed by this FFT code, while the other EEG raw data provided in EEGLab tutorial can?

I wish to plot frequency vs. power spectrum of eeg raw data from EMOTIV Epoc using this code:
clear;
clc;
[hdr,record] = edfread('dataemotiv.edf');
Fs = hdr.samples(1,1); %to see sampling frequency
F3 = record(5,:);
%BUTTERWORTH FILTER
cutOffFreq = 15; % Hz
filterOrder = 1; % Filter order (e.g., 2 for a second-order Butterworth filter)
D = butter(filterOrder, cutOffFreq/(Fs/2)); % Generate filter coefficients
[b, a] = butter(filterOrder, cutOffFreq/(Fs/2)); % Generate filter coefficients
Y3 = filtfilt(b, a, F3); % Apply filter to data using zero-phase filtering
%Power Spectrum
y=fft(F3);
PS=abs(y).^2;
N=length(y);
freq=(1:N/2)*Fs/N;
plot(freq,PS(1:N/2))
When I applied this to another EEG raw data provided in EEGlab tutorial "eegexample.edf", I got this:
But when I applied the code to my eeg data "dataemotiv.edf", I got this:
Please help me to know why this can happen. I'm sorry for my long post. Thanks for the help.
PS: My friend applied wavelet transform to my EEG data and can get power spectrum plot. I don't know what differ FFT and wavelet transform that my EEG data can be processed by wavelet transform.

 Accepted Answer

Subtract off the mean of your data and try again.

3 Comments

Thanks Walter, it works!
As I use F3, my code will be F3 = F3 - mean(F3). Is this right?
Yes, that looks appropriate.
The difficulty you were observing is that the mean of your data was sufficiently large that the total power of your data, which is what shows up in the first bin of fft(), was much much greater than any of the individual coefficients, so your coefficients just were not showing up with your y axes automatically scaled. When you subtract off the mean, the total power becomes 0 (to within numeric error) which leaves room for your actual coefficients to be visible on the graph.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!