Spectrogram of EEG signal
Afficher commentaires plus anciens
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
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.
.
4 commentaires
farin
le 2 Août 2023
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.
.
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')
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 = 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)
.
Catégories
En savoir plus sur EEG/MEG/ECoG dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



