Spectrogram of EEG signal

조회 수: 16 (최근 30일)
farin
farin 2023년 7월 31일
댓글: Star Strider 2023년 8월 4일
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

답변 (1개)

Star Strider
Star Strider 2023년 7월 31일
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
farin
farin 2023년 8월 4일
편집: farin 2023년 8월 4일
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
Star Strider
Star Strider 2023년 8월 4일
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)
.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by