How to create a matrix with power spectral density for a range of frequencies across time

2 views (last 30 days)
Hello, I currently have a data set from electrophysiological recordings which have voltage over time for different trials. Columns represent time (1ms) and rows represent trials. I would like to convert this matrix to represent power (values) over time (columns) at a range of frequencies (rows). If anyone knows how to do this please let me know!
  8 Comments
Dave B
Dave B on 17 Nov 2021
The vector f should represent frequency to the extent that you gave spectorgram the correct sampling rate. For the vector t: it's not that it starts at an offset so much as each set of values refers to a window. For example, if you had no overlap and you window size was 1 second, your first spectrum is for the time 0-1s.
Here's a demo of both.
fs=20000;
t=linspace(0,3,fs*3);
y(1:fs) = sin(t(1:fs)*1000*2*pi);
y(fs+1:2*fs) = sin(t(1:fs)*2500*2*pi);
y(2*fs+1:3*fs) = sin(t(1:fs)*7777*2*pi);
[s,f,t]=spectrogram(y, fs, 0, [], fs);
imagesc(t,f,log(abs(s)))
colormap hot
caxis([0 1])
axis xy
yline(1000,'b','LineWidth',1)
yline(2500,'b','LineWidth',1)
yline(7777,'b','LineWidth',1)
Andy Garcia Barrabeitg
Andy Garcia Barrabeitg on 11 Dec 2021
Hi Dave thanks for that answer that helped a ton. I'm now wondering why the time for the spectrogram is cutting out the first and last half a second of data, do you happen to know why?

Sign in to comment.

Answers (0)

Categories

Find more on Time-Frequency Analysis in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!