How to plot the diagonal of a spectrum as a 2d plot?

8 次查看(过去 30 天)
I have a power spectral density spectrogram with x=time, y=frequency, c=power spectral density. My plot has very high PSD values in a linear trend on it and I want to plot the frequency and time that correspond to that high PSD linear trend. How can I plot this? I used this to plot the spectrogram:
tfSpectra = zeros(nf2,totalStack);
tft = nptsGap.*dt.*(0:totalStack-1) + twin/2;
tff = 1./dt./nf.*(0:nf2-1);
for i = 1:totalStack
index = 1+(i-1)*nptsGap : (i-1)*nptsGap+nptsSegment;
fdata = mean(abs(fft(uxt(index,:),nf,1)), 2);
tfSpectra(:,i) = fdata(1:nf2);
end
imagesc(tft,tff,10*log10(tfSpectra))
h = colorbar;
set(get(h,'label'),'string','PSD (dB/Hz)','FontSize',14);
caxis([-30,15])

回答(1 个)

Balavignesh
Balavignesh 2023-11-10
编辑:Balavignesh 2023-11-17
Hi Brianna,
I understand that you have a power spectral density (PSD) spectrogram and you would like to plot the frequency and time that correspond to a high PSD linear trend.
I would suggest you calculate the maximum PSD value and its corresponding indices in the 'tfSpectra' Matrix using the inbuilt functions 'max' and 'find'. After retrieving the frequency and time values corresponding to the maximum PSD, you could plot the spectrogram using the 'imagesc' function. In addition, you could also add markers or annotations to indicate the frequency and time corresponding to the maximum PSD.
The following example code may help you achieve this:
% Sample value of tfSpectra. Use your own data
tfSpectra = [1 2 3; 4 5 6; 7 8 9];
% Calculate maximum PSD value and its corresponding indices
[maxPSD, maxIndex] = max(tfSpectra(:));
[maxFreqIndex, maxTimeIndex] = ind2sub(size(tfSpectra), maxIndex);
% Retrieve frequency and time values corresponding to the maximum PSD
tft = [0 1 2]; % Example time values
tff = [10 20 30]; % Example frequency values
maxFreq = tff(maxFreqIndex);
maxTime = tft(maxTimeIndex);
% Plot the spectrogram
imagesc(tft, tff, 10*log10(tfSpectra));
h = colorbar;
set(get(h, 'label'), 'string', 'PSD (dB/Hz)', 'FontSize', 14);
caxis([-30, 15]);
% Add markers and annotations for the maximum PSD
hold on;
plot(maxTime, maxFreq, 'ro', 'MarkerSize', 10, 'LineWidth', 2);
text(maxTime, maxFreq, sprintf('(%0.2f, %0.2f)', maxTime, maxFreq), 'Color', 'r', 'FontSize', 12, 'VerticalAlignment', 'bottom');
hold off;
Kindly have a look at the following documentation links to have more information on:
Hope that helps!
Balavignesh

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by