Time-Frequency Reassignment using Spectrogram Function

6 views (last 30 days)
Dear Colleagues. I'm trying to obtain the reassigned version of a spectrogram using Matlab's built-in function spectrogram. Instead of plotting the reassigned version automatically, which works fine, I'm interested in assigning the modified spectrogram to a variable, using the following command:
Reassigned_Spec = spectrogram(In_Sig,Win,F_Size-H_Size,F_Size,fs,'reassign','yaxis');
The problem is that the data that I'm getting into the output variable is not the reassigned spectrogram, it is just the normal spectrogram. Any idea why this is happening? Thanks.
  1 Comment
Alejandro Delgado-Castro
Alejandro Delgado-Castro on 21 Mar 2017
Well, I have solved the problem myself and wanted to share the solution I found in case someone else is trapped into the same situation. The key thing is that Matlab returns the reassigned spectrogram in the same structure used to return the normal power spectrogram, which is a different structure in the sequence of output variables. So, the command I finally used looks like this:
[~,~,~,Reassigned_Spec] = spectrogram(Ori_Sig,Win,F_Size-H_Size,F_Size,fs,'power','reassigned');
The returned matrix is equivalent to the one automatically plotted when no output variable is specified.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 21 Mar 2017
You most likely have to get the data from the figure itself. It took some handle-spelunking to find this (in R2017a, I’m still reading the Release Notes). I never needed to do this, so it was something of an education.
This is from one of the examples in the documentation for the spectrogram function. It seems to provide the information in the plot that spectrogram produces.
The Example Code
Fs = 1000;
t = 0:1/Fs:2;
y = chirp(t,100,1,200,'quadratic');
figure(1)
spectrogram(y,kaiser(128,18),120,128,Fs,'reassigned','yaxis')
Ch = get(gca, 'Children')
Xd = Ch.XData;
Yd = Ch.YData;
Cd = Ch.CData;
figure(2)
surf(Xd, Yd, Cd)
grid on
  2 Comments
Alejandro Delgado-Castro
Alejandro Delgado-Castro on 21 Mar 2017
Thanks for your answer. I also found a way to extract the reassigned spectrogram directly from the function by rearranging the order of the output variables.
Star Strider
Star Strider on 21 Mar 2017
My pleasure.
I saw your solution in the documentation, but did not test it in my code.

Sign in to comment.

More Answers (0)

Categories

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

Products

Community Treasure Hunt

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

Start Hunting!