MATLAB Answers

frequency analysis with a Waterfall

8 views (last 30 days)
Fabian Laumen
Fabian Laumen on 14 Jul 2021
Answered: Arthi Sathyamurthi on 20 Jul 2021
Hey community
I would like to compare different datasets by a time-frequency based analysis method. I have in mind a waterfall diagram. Is it possible to get from this diagram specific values like maximum magnitude and the corresponding frequency, or the average excited frequency (similar to the spectral centroid in an FFT)? Here is the code I am using and an image of the waterfall.
Best regards and thank you in advance
Abb_2 = figure(2);
[p,f,t] = pspectrum(TreBu_output.Window,general.sampl_frequency_in_Hz,'spectrogram');
xlabel('Frequency (Hz)')
ylabel('Time (seconds)')
zlabel('Magnitude (V^2)')
title(['Frequency waterfall ', Name]);
xlim([0 2e5])
wtf = gca;
wtf.XDir = 'reverse';
view([30 45])

Answers (1)

Arthi Sathyamurthi
Arthi Sathyamurthi on 20 Jul 2021
Hello Fabian,
To get diagram specific values like maximum magnitude with their corresponding frequency and time, from just visualization you can use a datatip in the figure window by just clicking on the maximum point or you can use the datatip function in MATLAB if you know the positions already.
In case you don’t know the maximum value and wish to calculate it, you can use the max function. Copy the following code to your program to calculate it.
[maxValuesofSpectrum, indexMaxValuesofSpectrum] = max(p,[],'linear'); % Maximum magnitudes for each individual time value of the spectrogram
[maxValue, indexMaxValue] = max(maxValuesofSpectrum); % Maximum magnitude among all the time values of spectrogram
[rowIndexofMaxValue, columnIndexofMaxValue] = ind2sub(size(p),indexMaxValuesofSpectrum(indexMaxValue));
f(rowIndexofMaxValue); % Spectrum frequency corresponding to the maximum magnitude
t(columnIndexofMaxValue); % Time value corresponding to the maximum magnitude
You can comment out the 2nd and 5th line if you want to find the maximum magnitude for each individual time

Community Treasure Hunt

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

Start Hunting!

Translated by