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

5 Ansichten (letzte 30 Tage)
Brianna Miranda am 30 Apr. 2022
Bearbeitet: Balavignesh am 17 Nov. 2023
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])
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Balavignesh am 10 Nov. 2023
Bearbeitet: Balavignesh am 17 Nov. 2023
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.
% 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;
Hope that helps!
Balavignesh
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Spectral Measurements finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by