get y values of z values in spectrogram

2 ビュー (過去 30 日間)
Freeplot
Freeplot 2020 年 4 月 10 日
回答済み: Soumya 2025 年 6 月 24 日
Hii there. I want to get the y-values for specific z-values from a spectrogram. I just want to get the y-values for (z > -10).
This is my code for plot the spectrogram:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load a signal
[x, fs] = audioread('file.wav'); % load an audio file
x = x(:, 1); % get the first channel
% determine the signal parameters
xlen = length(x); % signal length
t = (0:xlen-1)/fs; % time vector
% analysis parameters
wlen = 1024; % window length (recomended to be power of 2)
nfft = 4*wlen; % number of fft points (recomended to be power of 2)
hop = wlen/4; % hop size
TimeRes = wlen/fs; % time resulution of the analysis (i.e., window duration), s
FreqRes = 2*fs/wlen; % frequency resolution of the analysis (using Hanning window), Hz
% time-frequency grid parameters
TimeResGrid = hop/fs; % time resolution of the grid, s
FreqResGrid = fs/nfft; % frequency resolution of the grid, Hz
% perform STFT
w1 = hanning(wlen, 'periodic');
[~, fS, tS, PSD] = spectrogram(x, w1, wlen-hop, nfft, fs);
Samp = 20*log10(sqrt(PSD.*enbw(w1, fs))*sqrt(2));
% plot the spectrogram
figure;
surf(tS, fS, Samp);
shading interp;
axis tight;
box on;
set(gca, 'FontName', 'Times New Roman', 'FontSize', 12);
ylim([0 1500]);
xlim([0 2]);
xlabel('Time, s');
ylabel('Frequency, Hz');
title('Unterarm Messung Ruhepuls');
view(0, 90);
colormap('jet');
hcol = colorbar;
set(hcol, 'FontName', 'Times New Roman', 'FontSize', 12)
ylabel(hcol, 'Magnitude, dB')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

回答 (1 件)

Soumya
Soumya 2025 年 6 月 24 日
Hi,
The ‘find’ function returns the indices of elements in an array that satisfy a specified condition. In the spectrogram matrix, where each element represents a magnitude value at a certain frequency and time, ‘find’ can be used to locate all points where the magnitude exceeds a threshold. This returns two sets of indices which include row indices corresponding to frequencies and column indices corresponding to times. You can then use these indices to extract the actual frequency and time values from the frequency vector and time vector, respectively.
The following steps will help you get the y-values for the specific z-values (here samp):
  • Use the ‘find’ function to find indices for the condition(samp>-10):
[row, col] = find(Samp > -10);
  • Extract corresponding y-values (frequencies) using the computed ‘row’ indexes from the ‘find’ function:
frequencies = fS(row);
Below is the output for a sample data:
Please refer to the following documentation links to know more about the ‘find’ function:
I hope this helps!

カテゴリ

Help Center および File ExchangeTime-Frequency Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by