Signal Processing Toolbox | ![]() ![]() |
Time-dependent frequency analysis (spectrogram)
Syntax
B=
specgram(a) B=
specgram(a,nfft) [B,f]=
specgram(a,nfft,fs) [B,f,t]=
specgram(a,nfft,fs) B=
specgram(a,nfft,fs,window) B=
specgram(a,nfft,fs,window,numoverlap) specgram(a) B=
specgram(a,f,fs,window,numoverlap)
Description
specgram
computes the windowed discrete-time Fourier transform of a signal using a sliding window. The spectrogram is the magnitude of this function.
calculates the windowed discrete-time Fourier transform for the signal in vector B = specgram(a)
a
. This syntax uses the default values:
nfft = min(256,length(a))
fs = 2
window
is a periodic Hann (Hanning) window of length nfft
.
numoverlap = length(window)/2
nfft
specifies the FFT length that specgram
uses. This value determines the frequencies at which the discrete-time Fourier transform is computed. fs
is a scalar that specifies the sampling frequency. window
specifies a windowing function and the number of samples specgram
uses in its sectioning of vector a
. numoverlap
is the number of samples by which the sections overlap. Any arguments that you omit from the end of the input parameter list use the default values shown above.
If a
is real, specgram
computes the discrete-time Fourier transform at positive frequencies only. If n
is even, specgram
returns nfft/2+1
rows (including the zero and Nyquist frequency terms). If n
is odd, specgram
returns nfft/2
rows. The number of columns in B
is
If a
is complex, specgram
computes the discrete-time Fourier transform at both positive and negative frequencies. In this case, B
is a complex matrix with nfft
rows. Time increases linearly across the columns of B
, starting with sample 1 in column 1. Frequency increases linearly down the rows, starting at 0.
B
uses the specified FFT length =
specgram(a,nfft)
nfft
in its calculations.
returns a vector [B,f] = specgram(a,nfft,fs)
f
of frequencies at which the function computes the discrete-time Fourier transform. fs
has no effect on the output B
; it is a frequency scaling multiplier.
returns frequency and time vectors [B,f,t] = specgram(a,nfft,fs)
f
and t
respectively. t
is a column vector of scaled times, with length equal to the number of columns of B
. t(j)
is the earliest time at which the jth window intersects a
. t(1)
is always equal to 0.
specifies a windowing function and the number of samples per section of the B = specgram(a,nfft,fs,window)
x
vector. If you supply a scalar for window
, specgram
uses a Hann window of that length. The length of the window must be less than or equal to nfft
.
overlaps the sections of B = specgram(a,nfft,fs,window,numoverlap)
x
by numoverlap
samples.
You can use the empty matrix []
to specify the default value for any input argument. For example,
but with a sampling frequency of 10,000 Hz instead of the default 2 Hz.
specgram(...)
with no output arguments displays the scaled logarithm of the spectrogram in the current figure window using
The axis
xy
mode displays the low-frequency content of the first portion of the signal in the lower-left corner of the axes. specgram
uses fs
to label the axes according to true time and frequency.
B
computes the spectrogram at the frequencies specified in =
specgram(a,f,fs,window,numoverlap)
f
, using either the chirp z-transform (for more than 20 evenly spaced frequencies) or a polyphase decimation filter bank. f
is a vector of frequencies in hertz; it must have at least two elements.
Examples
Display the spectrogram of a digitized speech signal:
Note You can view and manipulate a similar spectrogram in the Signal Processing Toolbox Demos, which you access in from the MATLAB Launch Pad. |
Algorithm
specgram
calculates the spectrogram for a given signal as follows:
window
parameter to each section.
nfft
FFT to produce an estimate of the short-term frequency content of the signal; these transforms make up the columns of B
. T
he quantity (length(window)
- numoverlap)
specifies by how many samples specgram
shifts the window.
specgram
truncates the spectrogram to the first nfft/2
+ 1
points for nfft
even and (nfft
+ 1)/2
for nfft
odd.
Diagnostics
An appropriate diagnostic message is displayed when incorrect arguments are used:
Requires window's length to be no greater than the FFT length. Requires NOVERLAP to be strictly less than the window length. Requires positive integer values for NFFT and NOVERLAP. Requires vector input.
See Also
References
[1] Oppenheim, A.V., and R.W. Schafer, Discrete-Time Signal Processing, Prentice-Hall, Englewood Cliffs, NJ, 1989, pp. 713-718.
[2] Rabiner, L.R., and R.W. Schafer, Digital Processing of Speech Signals, Prentice-Hall, Englewood Cliffs, NJ, 1978.
![]() | sosfilt | sptool | ![]() |