Spectrogram in MATLAB
Last Updated :
28 Nov, 2022
A Spectrogram is a detailed, visual representation of how the frequency spectrum of a signal varies with time. They are highly useful in academic and research fields such as physics where signals of different kinds (electrical, broadband, etc.) are required to be studied visually. Spectrograms are very useful in analyzing the results of signal filtering.
MATLAB provides the spectrogram () function that plots the spectrograms for the required input signal. In this article, we shall see how to use the said function to plot spectrograms for different signal forms and various options available for the former.
Syntax:
spectrogram(<signal>)
This will plot the required spectrogram corresponding to the input signal.
Now we shall see the working of the same using some examples and dummy input signals. Firstly, we shall plot a simple spectrogram of a linear chirping function of MATLAB, which is a part of the signal processing toolbox, and see the output plot.
Example 1:
Matlab
t = 0:0.001:2;
z= chirp(t,0,1,230);
spectrogram(z)
title( 'Spectrogram of Linear chirp' )
|
Output:
Here, a time vector of interval length 0.001 is passed to the linear chirp signal. The chirp function will start at a frequency of 0 Hz at time=0 and will pass the 230-hertz frequency at time=1.
Now take another example, we will create a sinusoidal input wave and plot its spectrogram for 2300 samples.
Example 2:
Matlab
t = 0:2290;
phase = pi/4;
freq = 230;
z = sin(freq*t + phase);
spectrogram(z)
title( 'Spectrogram of a sinusoidal wave signal' )
|
Output:
In the above code, we create a sinusoidal signal with frequency = 230Hz, initial phase angle = 45 degrees, and taking 2300 time instances.
Now, we shall plot a quadratic chirp as our last example. Here, we create a quadratic chirp input signal by passing a fifth parameter as ‘quadratic’ which makes the chirp function change its Fast-Fourier Transformation method to quadratic from linear. The initial frequency of the same is 220Hz and it will cross 230Hz at time = 1.
Example 3:
Matlab
t = 0:.0001:23;
z= chirp(t,220,1,230, 'quadratic' );
spectrogram(z)
title( 'Spectrogram of Quadratic chirp' )
|
Output:
Share your thoughts in the comments
Please Login to comment...