|Signal Processing Toolbox||Search Help Desk|
|specgram||Examples See Also|
Time-dependent frequency analysis (spectrogram).
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,noverlap) specgram(a) B = specgram(a,f,Fs,window,noverlap)
specgramcomputes the windowed discrete-time Fourier transform of a signal using a sliding window. The spectrogram is the magnitude of this function.
calculates the spectrogram for the signal in vector
B = specgram(a)
a. This syntax uses the default values:
nfftspecifies the FFT length that
specgramuses. This value determines the frequencies at which the discrete-time Fourier transform is computed.
Fsis a scalar that specifies the sampling frequency.
windowspecifies a windowing function and the number of samples
specgramuses in its sectioning of vector
noverlapis 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
specgramcomputes the discrete-time Fourier transform at positive frequencies only. If
nfft/2+1rows (including the zero and Nyquist frequency terms). If
nfft/2rows. The number of columns in
k = fix((n-noverlap)/(length(window)-noverlap))If
specgramcomputes the discrete-time Fourier transform at both positive and negative frequencies. In this case,
Bis a complex matrix with
nfftrows. 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 = specgram(a,nfft)uses the specified FFT length
nfftin its calculations. Specify
nfftas a power of 2 for fastest execution.
returns a vector
[B,f] = specgram(a,nfft,Fs)
fof frequencies at which the function computes the discrete-time Fourier transform.
Fshas no effect on the output
B; it is a frequency scaling multiplier.
returns frequency and time vectors
[B,f,t] = specgram(a,nfft,Fs)
tis a column vector of scaled times, with length equal to the number of columns of
t(j)is the earliest time at which the j-th window intersects
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)
xvector. If you supply a scalar for
specgramuses a Hanning window of that length. The length of the window must be less than or equal to
specgramzero pads the sections if the length of the window exceeds
overlaps the sections of
B = specgram(a,nfft,Fs,window,noverlap)
noverlapsamples. You can use the empty matrix
to specify the default value for any input argument. For example,
B = specgram(x,,10000)is equivalent to
B = specgram(x)but with a sampling frequency of 10,000 Hz instead of the default 2 Hz.
specgramwith no output arguments displays the scaled logarithm of the spectrogram in the current figure window using
xymode displays the low-frequency content of the first portion of the signal in the lower-left corner of the axes.
Fsto label the axes according to true time and frequency.
B = specgram(a,f,Fs,window,noverlap)computes the spectrogram at the frequencies specified in
f, using either the chirp z-transform (for more than 20 evenly spaced frequencies) or a polyphase decimation filter bank.
fis a vector of frequencies in Hertz; it must have at least two elements.
specgramcalculates the spectrogram for a given signal as follows:
windowparameter to each section.
nfftFFT to produce an estimate of the short-term frequency content of the signal; these transforms make up the columns of
specgramzero pads the windowed sections if
nfft > length(window), so the quantity
(length(window) - noverlap)specifies by how many samples
specgramshifts the window.
specgramtruncates the spectrogram to the first
nfft/2 + 1points for
(nfft + 1)/2for
ExamplePlot the spectrogram of a digitized speech signal:
load mtlb specgram(mtlb,512,Fs,kaiser(500,5),475) title('Spectrogram')
DiagnosticsAn 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.
||Estimate magnitude squared coherence function between two signals.
||Estimate the cross spectral density (CSD) of two signals.
||Estimate the power spectral density (PSD) of a signal using Welch's method.
||Transfer function estimate from input and output.
References Oppenheim, A.V., and R.W. Schafer. Discrete-Time Signal Processing. Englewood Cliffs, NJ: Prentice Hall, 1989. Pgs. 713-718.  Rabiner, L.R., and R.W. Schafer. Digital Processing of Speech Signals. Englewood Cliffs, NJ: Prentice Hall, 1978.