Spectrogram of EEG signal

Hello. I would like to plot spectrogram of a 700s of EEG signal with fs=256. Pls help me to have spectrogram with stft like below pic.Thanks

Réponses (1)

Star Strider
Star Strider le 31 Juil 2023

0 votes

One approach —
Fs = 256;
figure
spectrogram(EEGsignal, hann, [], [], [], Fs)
xlim([0 700]) % May Not Be Necessary If The EEG Is Only 700 s Long
Using the pspectrum function with tthe 'spectrogram' option is another option. Note that while the results of these functions may appear to be similar, they are not the same. The spectrogram function results are in dB/Hz, and tthe pspectrum results are in dB.
See the documentation for spectrogram and pspectrum for details.
.

4 commentaires

farin
farin le 2 Août 2023
Hi star strider . thank you for your answer. I tried spectrogram(EEGsignal, hann, [], [], [], Fs). But it didnt work. I used spectrogram(EEG ,1000).Then I could get plot like the attached pic. But on my plot x is 0 to 2500, and frequency is normalized. Please let me know how to solve this problem. Thank you alot for your help.
Star Strider
Star Strider le 2 Août 2023
I do not know what ‘it didnt work’ means.
It would likely be easier to reply (and perhaps provide a solution) if I had your signal.
.
farin
farin le 4 Août 2023
Modifié(e) : farin le 4 Août 2023
Dear Star Strider,
Recently, I have started to do my research on EEG and I am not good at matlab. in this regards, I highly apprieciate your help. I have attached 2-channel EEG signal. I coud get plot like pic. But with choosing 4.5 instead of 500 in M parameter, output is not clear. Pleae let me know to how to choose the best parameter for M.
M=floor(length(w))/500);
g=hamming(M,'periodic');
L=floor(0.75*M);
Ndft=128;
spectrogram(w,g,L,Ndft,fs,'yaxis')
Another question is to plot FTC spectrum and WTC of this signal to have plot as attached.
FTC=coherence based on Fourier transform. WTC=wavelet coherence
thanks a lot for your help
The ‘M’ parameter here is the segment length of the signal segments the function uses to calculate the Fourier transform. Using 4.5 in the denominator produces a segment length of 39651 samples, and that would definitely obscure any detail. Setting it to a lower value (the denominator value of 500 produces a segment length of 356) will result in better resolution. The documentation example uses a denominator value of 4.5 because that signal length has only 1024 elements. Your signals each have 178432 elements.
I do not usually do coherence plots, and I have no recent experience with wavelets, although I was able to find the wcoherence function. The mscohere function (and similar functions) produce only 2D results, not anything similar to a spectrogram plot.
I added the pspectrum calls because I wanted to see what the power spectrum looked like iun two dimensions. That helps me understand the spectrogram results.
figure
imshow(imread('Spectrum.jpg'))
LD = load('EEG.mat')
LD = struct with fields:
w: [178432×1 double] x: [178432×1 double] loc: 357 en: 649
EEGsignal1 = LD.w;
EEGsignal2 = LD.w;
Fs = 256;
L = numel(EEGsignal1);
tv = linspace(0, L-1, L)/Fs;
[p1,f1] = pspectrum(EEGsignal1,Fs);
[p2,f2] = pspectrum(EEGsignal1,Fs);
figure
subplot(2,1,1)
plot(f1,p1)
grid
subplot(2,1,2)
plot(f2,p2)
grid
M=floor(L/500)
M = 356
M = 256;
g=hamming(M,'periodic');
L=floor(0.75*M);
Ndft=128;
figure
spectrogram(EEGsignal1,g,L,Ndft,Fs,'yaxis')
colormap(turbo)
spectrogram(EEGsignal2,g,L,Ndft,Fs,'yaxis')
colormap(turbo)
.

Connectez-vous pour commenter.

Catégories

Question posée :

le 31 Juil 2023

Commenté :

le 4 Août 2023

Community Treasure Hunt

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

Start Hunting!

Translated by