MATLAB Answers

Plotting spectrogram for EEG data

51 views (last 30 days)
Sparsha Kumari
Sparsha Kumari on 5 Feb 2020
Answered: Daniel M on 24 Apr 2020
I am done with the filtering and plotting the power spectrum for the EEG data. Now I want to plot the spectrogram for this data. I have tried using the 'spectrogram' and 'stft' function and played with the various input options but I do not get the plot the way I want it to be. Could someone please show me some light in this regard.
P.S. : I need to get it as shown in figure 1 (Reference: William E. DeCoteau et. al. www.pnas.orgcgidoi10.1073pnas.0700818104). Instead I get it as shown in the figure 2.


Jakob B. Nielsen
Jakob B. Nielsen on 5 Feb 2020
Can you show us what you do to get your figure, and your data? Otherwise, off the top of my mind, try using the surf function and add shading interp in there.
Sparsha Kumari
Sparsha Kumari on 5 Feb 2020
Thanks a lot for your reply! I get it as shown in figure 2. I have used the 'stft' function as follows and got the plot,
stft(data, fs);

Sign in to comment.

Answers (1)

Daniel M
Daniel M on 24 Apr 2020
You should plot the absolute value of your output from spectrogram or stft. Maybe even the log, or 10*log10 too (but I don't recall exactly, you'll have to look up the documentation). Basically, when you call those functions with outputs, try and make the plot match the one you get when you call the functions without outputs.
Your spectral and temporal resolution are very different from the first figure. That paper is doing a time-frequency analysis over ~ 4 seconds and 25 Hz. You are looking at ~150 ms and 500 Hz. You can look at this tutorial (with video) on how time window and frequency resolution trade-off with each other.


Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by