0% found this document useful (0 votes)
5 views9 pages

MATLAB Spectrogram Analysis Guide

The document discusses using the MATLAB command specgram to generate spectrograms from signals. Specgram divides signals into overlapping segments, windows each segment, and forms columns of the spectrogram matrix from the discrete Fourier transforms of the segments. The document provides examples of using specgram to analyze chirp signals and the effect of window length on the spectrogram.

Uploaded by

AM12345
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views9 pages

MATLAB Spectrogram Analysis Guide

The document discusses using the MATLAB command specgram to generate spectrograms from signals. Specgram divides signals into overlapping segments, windows each segment, and forms columns of the spectrogram matrix from the discrete Fourier transforms of the segments. The document provides examples of using specgram to analyze chirp signals and the effect of window length on the spectrogram.

Uploaded by

AM12345
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Multiple Logons

50 50
100 100
150 150
200 200
250 250
50 100 150 50 100 150

50 50
100 100
150 150
200 200
250 250
20 40 60 80 100 120 20 40 60
Demo Signal

10

15

20

25

30

20 40 60 80 100 120 140 160


MATLAB code
• You can use the MATLAB command: specgram
• SPECGRAM Spectrogram using a Short-Time Fourier Transform (STFT).
• B = SPECGRAM(A) calculates the spectrogram for the signal in vector A.
• SPECGRAM divides the signal into overlapping segments, windows each
• segment and forms the columns of B with their discrete Fourier
• transforms.

• B = SPECGRAM(A,NFFT,Fs) specifies the number of FFT points used to
• calculate the discrete Fourier transforms. If NFFT = [] or is not
• specified the default NFFT = minimum of 256 and the length of A. Fs is
• the sampling frequency which does not effect the spectrogram but is
• used for scaling plots. If Fs=[] or is not specified it defaults to 2
• Hz.

• B = SPECGRAM(A,NFFT,Fs,WINDOW,NOVERLAP) uses WINDOW to window each
• overlapping segment and forms the columns of B with their zero-padded,
• length NFFT discrete Fourier transforms. If you specify a scalar for
• WINDOW, SPECGRAM uses a Hanning window of length NFFT. WINDOW must
• have a length smaller than or equal to NFFT and greater than NOVERLAP.
• NOVERLAP is the number of samples each segement of A overlaps. The
• default value of NOVERLAP = length(WINDOW)/2.
Logon
1

0.5

-0.5

-1
0 20 40 60 80 100 120 140

10

20

30
10 20 30 40 50 60 70 80 90
Effect of Window Length
1
0

-1
0 50 100 150 200 250 300

5
10
15
50 100 150 200

10
20
30
50 100 150 200

20
40
60
20 40 60 80 100 120 140 160 180
Spectrogram Examples-2
• %spcgrm;
• x=logon(50,0.3,200)+logon(130,0.7,200)+logon(140,-0.5,200);
• S1=specgram(x,256,200,16,15);
• S2=specgram(x,256,200,32,31);
• S3=specgram(x,256,200,64,63);
• S4=specgram(x,256,200,128,127);
• subplot(221);
• imagesc(abs(S1));
• subplot(222);
• imagesc(abs(S2));
• subplot(223);
• imagesc(abs(S3));
• subplot(224);
• imagesc(abs(S4));
• %example 2;
• x=exp(j*0.5*[1:200])+exp(j*2*[1:200]);
• S=specgram(x,256,200,32,31);
• figure
• imagesc(abs(S));
Example
• %logon; • t=0:0.001:2; % 2 secs @ 1kHz
• x=logon(64,0.4,128); sample rate
• tflog=specgram(x,32,128,32,31); • tf1=specgram(y,256,1E3,256,250);
• subplot(211); • y=chirp(t,0,1,150); % Start @ DC,
• plot(real(x)); cross 150Hz at t=1sec
• subplot(212);
• t=-2:0.001:2; % +/-2 secs @ 1kHz
• imagesc(abs(tflog)); sample rate
• pause;
• figure
• y=chirp(t,100,1,200,'q'); % Start @ 100Hz,
cross 200Hz at t=1sec
• %demo signal;
• tfdemo=specgram(demosig,32,200,32,31); • tf2=specgram(y,128,1E3,128,120); %
• imagesc(abs(tfdemo));
Display the spectrogram
• pause • figure;
• figure; • subplot(211)
• % effect of the window length; • imagesc(abs(tf1));
• y=[zeros(1,128),exp(j*0.6*[1:128])]; • title('Linear Chirp: start at DC, cross 150Hz
• subplot(411); at t=1sec');
• plot(real(y)); • subplot(212)
• subplot(412);
• imagesc(abs(tf2));
• tf1=specgram(y,16,256,16,15);
• imagesc(abs(tf1)); • title('Quadractic Chip: start at 100Hz and
• subplot(413); cross 200Hz at t=1sec');
• tf2=specgram(y,32,256,32,31);
• imagesc(abs(tf2));
• subplot(414);
• tf3=specgram(y,64,256,64,63);
• imagesc(abs(tf3));
Chirp Signals
Linear Chirp: start at DC, cross 150Hz at t=1sec

20
40
60
80
100
120
50 100 150 200 250

Quadractic Chip: start at 100Hz and cross 200Hz at t=1sec

20

40

60
50 100 150 200 250 300 350 400 450
Two Sinusoids

50

100

150

200

250
20 40 60 80 100 120 140 160

Common questions

Powered by AI

In spectrogram representations, a linear chirp is characterized by a straight-line frequency increase over time, showing a consistent rate of frequency change, while a quadratic chirp exhibits a parabolic curve, indicating a frequency change that accelerates over time. The linear chirp crosses frequencies at constant intervals, whereas the quadratic chirp's rate of frequency crossing changes, leading to different bandwidth expansion patterns in the spectrogram .

To calculate a spectrogram using the SPECGRAM function in MATLAB, the essential parameters are the signal vector (A), the number of FFT points (NFFT), the sampling frequency (Fs), the window function (WINDOW), and the overlap between segments (NOVERLAP). The signal vector is the data input, NFFT determines the number of frequency bins, Fs scales the plot but doesn't alter the spectrogram's frequency content, WINDOW defines the shape and size of the window applied to each segment influencing time-frequency trade-offs, and NOVERLAP determines how much consecutive segments overlap, affecting the smoothness and continuity of the spectral image .

Different window sizes in a spectrogram significantly influence its visual output by altering its clarity and detail. A small window size improves temporal detail and dynamism, allowing transient features to be visible, although at the cost of frequency resolution. Larger windows provide more stable frequency detail at the cost of temporal resolution, potentially blurring dynamic changes. Thus, the choice of window size is critical in balancing the trade-off between time and frequency resolution .

The Hanning window in the SPECGRAM function acts to taper the edges of each data segment to zero, minimizing spectral leakage by reducing the discontinuities at the beginning and end of each windowed segment. It is often used because it effectively balances between main lobe width and side lobe suppression, providing a compromise between frequency resolution and leakage, making it suitable for general time-frequency analysis .

The window length in MATLAB's SPECGRAM function affects the time-frequency resolution of the spectrogram. A shorter window length provides better time resolution but poorer frequency resolution, while a longer window length gives better frequency resolution but poorer time resolution. This trade-off is observed because using a shorter segment increases time precision but reduces the number of frequency components that can be accurately measured within that segment, and vice versa .

The overlap between segments, specified by the parameter NOVERLAP in the SPECGRAM function, impacts spectrogram computation by influencing the temporal smoothness and the number of spectral estimates. Higher overlap increases the correlation between consecutive spectral estimates, which can improve the continuity and smoothness of the spectrogram along the time axis, while also potentially increasing computational cost. Conversely, less overlap means fewer calculations but may reduce visual continuity between time segments .

The sampling frequency (Fs) in the SPECGRAM function is crucial because it dictates how the frequency axis of the spectrogram is scaled, ensuring that the spectral analysis reflects the true frequency components of the input signal. While Fs itself does not affect the frequency content of the spectrogram, an incorrect choice can lead to misinterpretation of the spectrogram's frequency values due to improper scaling. Therefore, selecting the correct sampling frequency ensures accuracy in representing the signal's frequency content .

Zero-padding in MATLAB's SPECGRAM function increases the number of points in the FFT calculation without adding additional data, which can enhance the frequency resolution of the spectrogram. It interpolates the frequency bins, allowing for a finer spectral visualization, which is particularly useful for distinguishing closely spaced frequency components when window size is limited .

The relationship between window overlap and computational cost in the SPECGRAM function is direct: increasing the overlap between segments results in more overlap calculations, increasing the computational load. More overlap provides greater continuity and resolution along the time axis, but the redundancy in data processing adds to the computational expense. Thus, a balance must be achieved between desired spectral continuity and available computational resources .

Logarithmic scaling of frequencies in spectrogram analysis aids by compressing the wide range of frequencies typically present in real signals, enabling a more discernible view of both low and high-frequency components. This scaling is particularly useful for signals with exponential or logarithmically varying spectral features, allowing for a balanced representation of all frequencies in the spectrogram, where differences in low-frequency content that might otherwise be overshadowed by high frequencies become apparent .

You might also like