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
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
(name file of eeg raw data is 'data' just have 1 channel)
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
vo
on 2 Dec 2022
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.
.
vo
on 2 Dec 2022
thank you very much
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.)
.
vo
on 12 Dec 2022
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.
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.
.
vo
on 12 Dec 2022
Thanks, your explanation is quite detailed and easy to understand for me.
As always, my pleasure!
vo
on 15 Dec 2022
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.)
More Answers (0)
Categories
Find more on EEG/MEG/ECoG in Help Center and File Exchange
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)