Hi. I need some help about Spectrograms

40 views (last 30 days)
Kaosar Soomro
Kaosar Soomro on 2 Jun 2022
Edited: Star Strider on 3 Jun 2022
I have EMG data, which I split into active contraction zones which I did and computed their spectrograms. How can I extract dominant and median frequency from the signal spectrum?
Apprectiate the help, thanks!

Answers (3)

Star Strider
Star Strider on 2 Jun 2022
I would use the pspectrum function for this with the 'spectrogram' option, since the units and results are easier to interpret. It has several options for outputs, so choose the one that works best for what you want to do. I am not certain what frequencies you are referring to, or exactly what you want to do, however extracting the frequencies as a function of time is straightforward.
Example —
fs = 3000;
t = 0:1/fs:1-1/fs;
x2 = exp(2j*pi*100*cos(2*pi*2*t)) + randn(size(t))/100;
[p,f,t] = pspectrum(x2,fs,'spectrogram');
figure
surf(t,f,p,'EdgeColor','none')
colormap(turbo)
view(0,90)
xlabel('Time')
ylabel('Frequency')
zlabel('Power')
tr = t>0.009 & t<0.101; % Time Range
idx = find(tr); % Indices
fv = f(idx) % Frequency
fv = 5×1
1.0e+03 * -1.5000 -1.4971 -1.4941 -1.4912 -1.4883
pwr = p(:,idx); % Power
maxpwr = max(pwr) % Maximum Power
maxpwr = 1×5
0.2213 0.2436 0.2854 0.3530 0.4771
.
  15 Comments
Star Strider
Star Strider on 3 Jun 2022
Kaosar Soomro’s Answer moved here —
Ah okay, could I use the below functions on each segment (active zone where muscle contraction occurs)? - how would I know what to put for the timeColumn?
[s,f,t] = spectrogram(x, Fs);
timeColumn = 5;
intpwr = cumtrapz(f, abs(s(:,timeColumn)));
medianpwrfreq = interp1(intpwr, f, max(intpwr)/2);
Appreciate the help!
Star Strider
Star Strider on 3 Jun 2022
Edited: Star Strider on 3 Jun 2022
I am lost.
This is not compatible with the buffer matrix you want to use.
I have no idea how to make spectrogram or pspectrum compatible with the buffer matrix, other than to compute the spectrogram on each column of the buffer matrix. I demonstrated that elsewhere.
EDIT — (3 Jum 2022 at 16:12)
I can get specified time bins with pspectrum however not with spectrogram
EMG = randn(1,2.5E+5); % Create Data
Fs = 1E+3; % Sampling Frequency
L = numel(EMG);
tv = linspace(0, L-1, L)/Fs;
[sp,sf,st] = pspectrum(EMG, tv, 'spectrogram', 'TimeResolution',20, 'OverlapPercent',0);
figure
surfc(st,sf,sp, 'EdgeColor','none')
grid on
xlabel('Time (s)')
ylabel('Frequency (Hz)')
colormap(turbo)
view(0,90)
set(gca,'XTick',st+10, 'XTickLabel',st) % Ticks At Time Bin Midpoints, So 10, 30, ...
Neither one has a median frequency option.
.

Sign in to comment.


Kaosar Soomro
Kaosar Soomro on 2 Jun 2022
This is great, However for each segment (these are not the same as in my other post) which I have defined as certain regions of the signal, I have generated a spectrogram (time-frequency), I'm interested in extracting the dominat and median frequency from each of these spectrograms.
Could you break down how would I go about doing this?
Thanks

Kaosar Soomro
Kaosar Soomro on 3 Jun 2022
Ah okay, could I use the below functions on each segment (active zone where muscle contraction occurs)? - how would I know what to put for the timeColumn?
[s,f,t] = spectrogram(x, Fs);
timeColumn = 5;
intpwr = cumtrapz(f, abs(s(:,timeColumn)));
medianpwrfreq = interp1(intpwr, f, max(intpwr)/2);
Appreciate the help!

Community Treasure Hunt

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

Start Hunting!