Clear Filters
Clear Filters

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

31 views (last 30 days)
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 Comments
Syed Abid Sahdman
Syed Abid Sahdman about 4 hours ago
Edited: Syed Abid Sahdman about 4 hours ago
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 about 3 hours ago
Edited: Umar about 3 hours ago
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.

Sign in to comment.

Answers (0)

Categories

Find more on Time-Frequency Analysis in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!