Hi. I need some help about Spectrograms
40 views (last 30 days)
Show older comments
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!
0 Comments
Answers (3)
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
pwr = p(:,idx); % Power
maxpwr = max(pwr) % Maximum Power
.
15 Comments
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
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.
.
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!