Signal Processing Toolbox |
Spectrogram using short-time Fourier transform
Syntax
S=
spectrogram(x) S=
spectrogram(x,window) S=
spectrogram(x,window,noverlap) S=
spectrogram(x,window,noverlap,nfft) S=
spectrogram(x,window,noverlap,nfft,fs) S=
spectrogram(x,window,noverlap,F) S=
spectrogram(x,window,noverlap,F,fs) [S,F,T] = spectrogram(...) [S,F,T,P] = spectrogram(...) spectrogram(...)
Description
spectrogram
computes the short-time Fourier transform of a signal. The spectrogram is the magnitude of this function.
returns the spectrogram of the input signal vector S = spectrogram(x)
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.
window
is a Hamming window of length nfft
.
noverlap
is the value that produces 50% overlap between segments.
nfft
is the FFT length and is the maximum of 256 or the next power of 2 greater than the length of each segment of x.
fs
is the sampling frequency, which defaults to normalized frequency.
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
uses the =
spectrogram(x,window)
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
overlaps =
spectrogram(x,window,noverlap)
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
uses the =
spectrogram(x,window,noverlap,nfft)
nfft
number of sampling points to calculate the discrete Fourier transform. nfft
must be a scalar.
S
uses =
spectrogram(x,window,noverlap,nfft,fs)
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
uses a vector =
spectrogram(x,window,noverlap,F,fs)
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
returns a vector of frequencies ,F,T] = spectrogram(...)
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
returns a matrix ,F,T.P] = spectrogram(...)
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.
t = 0:0.001:2; y = chirp(t,100,1,200,'q'); spectrogram(y,128,120,128,1E3); title('Quadratic Chirp');
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.
sosfilt | spectrum |
© 1994-2005 The MathWorks, Inc.