Signal Processing Toolbox Previous page   Next Page
spectrogram

Spectrogram using short-time Fourier transform

Syntax

Description

spectrogram computes the short-time Fourier transform of a signal. The spectrogram is the magnitude of this function.

S = spectrogram(x) returns the spectrogram of the input signal vector x. By default, x is divided into eight segments. If x cannot be divided exactly into eight segments, it is truncated. These default values are used.

Each column of S contains an estimate of the short-term, time-localized frequency content of x. Time increases across the columns of S and frequency increases down the rows.

If x is a length Nx complex signal, S is a complex matrix with nfft rows and k colums, where

For real x, the output S has (nfft/2+1) rows if nfft is even, and (nfft+1)/2 rows if nfft is odd.

S = spectrogram(x,window) uses the window specified. If window is an integer, x is divided into segments equal to that integer value and a Hamming window is used. If window is a vector, x is divided into segments equal to the length of window and then the segments are windowed using the window functions specified in the window vector.

S = spectrogram(x,window,noverlap) overlaps noverlap samples of each segment. noverlap must be an integer smaller than window or if window is a vector, smaller than the length of window.

S = spectrogram(x,window,noverlap,nfft) uses the nfft number of sampling points to calculate the discrete Fourier transform. nfft must be a scalar.

S = spectrogram(x,window,noverlap,nfft,fs) uses fs sampling frequency in Hz. If fs is specified as empty [], it defaults to 1 Hz.

S = spectrogram(x,window,noverlap,F) uses a vector F of frequencies in Hz. F must be a vector with at least two elements. This case computes the spectrogram at the frequencies in F using the Goertzel algorithm. In all other syntax cases where nfft or a default for nfft is used, the short-time Fourier transform is used.

S = spectrogram(x,window,noverlap,F,fs) uses a vector F of frequencies in Hz as above and uses the fs sampling frequency in Hz. If fs is specified as empty [], it defaults to 1 Hz.

[S,F,T] = spectrogram(...) returns a vector of frequencies F and a vector of times T at which the spectrogram is computed. The length of F is equal to the number of rows of S. The length of T is equal to k, as defined above and each value corresponds to the center of each segment.

[S,F,T.P] = spectrogram(...) returns a matrix P containing the power spectral density (PSD) of each segment. For real x, P contains the one-sided modified periodogram estimate of the PSD of each segment. For complex x, P contains the two-sided PSDs.

spectrogram(...) plots on a surface the PSD estimate for each segment. Using spectrogram(...,'freqloc') syntax and adding a 'freqloc' string (either 'xaxis' or 'yaxis') controls where MATLAB displays the frequency axis. Using 'xaxis' displays the frequency on the x-axis. Using 'yaxis' displays frequency on the y-axis and time on the x-axis. The default is 'xaxis'.

Examples

Compute the spectrogram of a quadratic chirp, which starts at 100 Hz and crosses 200 Hz at t = 1 sec.

Compute the spectrogram of a linear chirp, which starts at DC and crosses 150 Hz at t = 1 sec. Display the frequency on the y-axis.

See Also

goertzel, periodogram, pwelch, spectrum.periodogram, spectrum.welch

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.


Previous page  sosfilt spectrum Next page

© 1994-2005 The MathWorks, Inc.