How can I plot a spectrogram plotting time vs instantaneous frequency vs amplitude from an exported output signal?

조회 수: 7 (최근 30일)
I have a text file with time(1st column) and voltage amplitude (2nd column). How do I plot a spectrogram plotting time vs instantaneous frequency vs amplitude? Could you please help me plot it? I will really appreciate it.
I have attached the text file and a picture of the time domain representation of the signal.
  댓글 수: 5
Syed Abid Sahdman
Syed Abid Sahdman 2024년 7월 22일
편집: Syed Abid Sahdman 2024년 7월 22일
Hello Umar,
Thank you so much for your help!
Could you please tell me how to determine the value of the parameters of spectrogram function? Also, does the spectrogram function transform the amplitude to power/frequency? Is there a way to plot just the amplitude?
Also, could you please tell me why we are getting negative instantaneous frequency and how to fix that? Thanks.
Umar
Umar 2024년 7월 22일
편집: Umar 2024년 7월 22일
Hi Syed,
No problem, glad to help you out. Please see my response to your posted questions.
Question: Could you please tell me how to determine the value of the parameters of spectrogram function? Also, does the spectrogram function transform the amplitude to power/frequency?
To answer this question, you have to understand how this function works, please refer to
https://www.mathworks.com/help/signal/ref/spectrogram.html
Now to address your query about, “does the spectrogram function transform the amplitude to power/frequency? “
Please bear in mind that this function computes the power spectral density (PSD) of the signal. This means that the amplitude values are transformed into power values, representing the distribution of power across different frequencies over time.
Question: Is there a way to plot just the amplitude?
If you wish to plot just the amplitude values without converting them to power, you can modify the spectrogram calculation slightly. Instead of using the spectrogram function directly, you can compute the Short-Time Fourier Transform (STFT) manually and plot the magnitude of the resulting spectrogram. For more information on STFT, please refer to
https://www.mathworks.com/help/signal/ref/spectrogram.html#mw_c6dfa97d-9a98-4238-a6bd-d58825fb47e0
Question: could you please tell me why we are getting negative instantaneous frequency and how to fix that?
So, I did some experimentation with code to find solution by using unwrapping of the phase and then realized how to overcome this issue. I had to adjust the calculation of instantaneous frequency to ensure that only positive values are obtained. The negative values in the plot were likely due to the unwrapping of the phase and subsequent calculation of the instantaneous frequency. Here is the snippet code to help this issue.
% Calculate instantaneous phase
instantaneous_phase = unwrap(angle(hilbert(amplitude)));
% Adjust phase to prevent negative frequencies
positive_phase = mod(instantaneous_phase, 2*pi);
% Calculate corrected instantaneous frequency
instantaneous_frequency = diff(positive_phase) / (2 * pi) / (time(2) - time(1));
% Ensure positive values for instantaneous frequency
instantaneous_frequency(instantaneous_frequency < 0) = 0;
I hope all your questions are answered.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by