Signal Processing Toolbox
  Go to function:
    Search    Help Desk 
specgram    Examples   See Also

Time-dependent frequency analysis (spectrogram).

Syntax

Description

specgram computes the windowed discrete-time Fourier transform of a signal using a sliding window. The spectrogram is the magnitude of this function.

B = specgram(a) calculates the spectrogram for the signal in vector a. This syntax uses the default values:

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. noverlap 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 = specgram(a,nfft) uses the specified FFT length nfft in its calculations. Specify nfft as a power of 2 for fastest execution.

[B,f] = specgram(a,nfft,Fs) returns a vector 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.

[B,f,t] = specgram(a,nfft,Fs) returns frequency and time vectors 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 j-th window intersects a. t(1) is always equal to 0.

B = specgram(a,nfft,Fs,window) specifies a windowing function and the number of samples per section of the x vector. If you supply a scalar for window, specgram uses a Hanning window of that length. The length of the window must be less than or equal to nfft; specgram zero pads the sections if the length of the window exceeds nfft.

B = specgram(a,nfft,Fs,window,noverlap) overlaps the sections of x by noverlap samples.

You can use the empty matrix [] to specify the default value for any input argument. For example,

is equivalent to

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 = 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. f is a vector of frequencies in Hertz; it must have at least two elements.

Algorithm

specgram calculates the spectrogram for a given signal as follows:

   1.
It splits the signal into overlapping sections and applies the window specified by the window parameter to each section.
   2.
It computes the discrete-time Fourier transform of each section with a length nfft FFT to produce an estimate of the short-term frequency content of the signal; these transforms make up the columns of B. specgram zero pads the windowed sections if nfft > length(window), so the quantity (length(window) - noverlap) specifies by how many samples specgram shifts the window.
   3.
For real input, specgram truncates the spectrogram to the first nfft/2 + 1 points for nfft even and (nfft + 1)/2 for nfft odd.

Example

Plot the spectrogram of a digitized speech signal:

Diagnostics

An appropriate diagnostic message is displayed when incorrect arguments are used:

See Also

cohere
Estimate magnitude squared coherence function between two signals.
csd
Estimate the cross spectral density (CSD) of two signals.
pwelch
Estimate the power spectral density (PSD) of a signal using Welch's method.
tfe
Transfer function estimate from input and output.

References

[1] Oppenheim, A.V., and R.W. Schafer. Discrete-Time Signal Processing. Englewood Cliffs, NJ: Prentice Hall, 1989. Pgs. 713-718.

[2] Rabiner, L.R., and R.W. Schafer. Digital Processing of Speech Signals. Englewood Cliffs, NJ: Prentice Hall, 1978.



[ Previous | Help Desk | Next ]