I have a raw eeg data and i want to plot the alpha wave(8-12Hz) of this data in the same window . How can i do? please help me

 Accepted Answer

Design a bandpass filter (using bandpass or other appropriate function), filter the signal, and plot it —
Fs = 1000;
L = 1E+4;
t = linspace(0, L-1, L)/Fs;
EEG = randn(size(t));
EEGfilt = bandpass(EEG, [8 12], Fs, 'ImpulseResponse','iir');
figure
plot(t, EEG, 'DisplayName','Unfiltered')
hold on
plot(t, EEGfilt, 'DisplayName','Filtered')
hold off
grid
legend('Location','best')
Make sppropriate changes to get the desired result.
.

10 Comments

Dear sir, i don't know what exactly the value of y-axis perform?
You can still design an efficient elliptic filter.
Here is some prototype code. I will let you adapt it to your needs, rather than do all of it for you. See the documentation on ellipord, ellip, zp2sos ,freqz and filtfilt for those details.
Fs = ...; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = [8 12]/Fn; % Normalised Passband Frequencies
Ws = Wp.*[0.98 1.02]; % Stopband Frequencies
Rp = 1; % Passband Ripple/Attenuation
Rs = 60; % Stopband Ripple/Attenuation
[n,Wn] = ellipord(Wp,Ws,Rp,Rs); % Calculate Filter Order
[z,p,k] = ellip(n,Rp,Rs,Wp); % Design Filter
[sos,g] = zp2sos(z,p,k); % Implement Filter As Second-Order-Section Representation
figure
freqz(sos, 2^16, Fs) % Filter Bode Plot
% set(subplot(2,1,1), 'XLim',[0 15]) % Optional
% set(subplot(2,1,2), 'XLim',[0 15]) % Optional
EEGfilt = filtfilt(sos,g,EEG); % Filter EEG
This assumes the the original signal is ‘EEG’. The freqz call allows you to be sure that the filter does what you want it to. If it does not, change the filter design until it does. It is also possible to specify ‘Ws’ as specific frequencies, similar to the way I specified ‘Wp’ here.
Another option is to use the designfilt function (introduced in R2014a), and it has a few more options. I simply prefer to use command-line functions.
.
As always, my pleasure!
You changed your original Comment. You initially asked for an alternative to the bandpass function. The y-axis is the amplitude of the signal. (The x-axis is time, since this is an EEG.)
.
I see someone code using this function
EEGfilt = bandpass(EEG, [8 12], Fs, 'ImpulseResponse','iir');
But they add [8 12]/fs/2. Why they do so? Can you explain more? thank you
EEGfilt = bandpass(EEG, [8 12]/fs/2, Fs, 'ImpulseResponse','iir');
@vo — It is necessary to divide the frequencies in Hz by the Nyquist frequency (the highest uniquely identifiable frequency in a sampled signal, one-half the sampling frequency) in order to normalise the signal on the interval radians/independent variable unit (seconds, centimetres, etc.), although actually to the interval as arguments to the MATLAB filter design functions.
According to the bandpass documentation, this is correct:
EEGfilt = bandpass(EEG, [8 12], Fs, 'ImpulseResponse','iir');
however this will not give the desired result:
EEGfilt = bandpass(EEG, [8 12]/fs/2, Fs, 'ImpulseResponse','iir');
The reason is that the bandpass function does the normalisation internally.
The second call will result in a passband of [8 12]/(Fs/2)^2, so for a sampling frequency of 1000 Hz, [0.000032 0.000048] instead of the intended [0.016 0.024]. Details are important.
.
Thanks, your explanation is quite detailed and easy to understand for me.
hi @Star Strider Can you help me one more?
I wonder if I use function bandpass, Do I need a step denoise a signal before, or not?
I do not understand ‘step denoise a signal’. I would just filter the signal with the bandpass function. There is no specific need to do any other processing on it before filtering it. If you want to do further processing on it afterwards, then it is appropriate to do that on the filtered signal. One such approach could be to remove broadband noise (that no frequency selective filter is capable of completely removing). I do not have your EEG signals, so I cannot determine if that is necessary. (The easiest approach to that problem would be to use the sgolayfilt function.)

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2016b

Tags

Asked:

vo
on 2 Dec 2022

Commented:

on 15 Dec 2022

Community Treasure Hunt

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

Start Hunting!