I would like to see the spectrogram of x=cos(-250*pi*t^2) for 0<t<2s. How do I plot the spectrogram ( f on y axis, time on x axis)?t = [0,0.1,2]; % Intervall for t y = cos(-2
4 views (last 30 days)
Show older comments
Julia-Alexandra Giesbrecht
on 17 Nov 2021
Commented: Star Strider
on 18 Nov 2021
I need a simple code to plot the spectrogram of sinusoids as f over time.
So far, my code looks like this:
t = [0,0.1,2]; % Intervall for t
y = cos(-250 * pi * t.^2); % the signal
spectrogram(y,t)
But the spectrogram is strange.
Which parameters do I need to add or change?
0 Comments
Accepted Answer
Star Strider
on 17 Nov 2021
The frequency of the sine curve is 125 Hz, however the sampling frequency of ‘t’ is 10 Hz. This leads to asliasing and unfortunate results. Increase the sampling frequency to 1 kHz and the result appears to be more appropriate —
t = [0:0.001:2]; % Intervall for t
y = cos(-250 * pi * t.^2 ); % the signal
spectrogram(y,t)
colormap(turbo)
I also changed the colormap to make the differences easier to see.
.
0 Comments
More Answers (1)
Julia-Alexandra Giesbrecht
on 18 Nov 2021
1 Comment
Star Strider
on 18 Nov 2021
As always, my pleasure!
The important change is providing the high sampling rate (2000 Hz) with that ‘t’ vector.
.
See Also
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!