You are on page 1of 4

SPECTROGRAM Spectrogram using a Short-Time Fourier Transform (STFT).

S = SPECTROGRAM(X) returns the spectrogram of the signal specified by vector X in the matrix S. By default, X is divided into eight segments with 50% overlap, each segment is windowed with a Hamming window. The number of frequency points used to calculate the discrete Fourier transforms is equal to the maximum of 256 or the next power of two greater than the length of each segment of X.

If X cannot be divided exactly into eight segments, X will be truncated accordingly.

S = SPECTROGRAM(X,WINDOW) when WINDOW is a vector, divides X into segments of length equal to the length of WINDOW, and then windows each segment with the vector specified in WINDOW. If WINDOW is an integer, X is divided into segments of length equal to that integer value, and a Hamming window of equal length is used. If WINDOW is not specified, the default is used.

S = SPECTROGRAM(X,WINDOW,NOVERLAP) NOVERLAP is the number of samples each segment of X overlaps. NOVERLAP must be an integer smaller than WINDOW if WINDOW is an integer. NOVERLAP must be an integer smaller than the length of WINDOW if WINDOW is a vector. If NOVERLAP is not

specified, the default value is used to obtain a 50% overlap.

S = SPECTROGRAM(X,WINDOW,NOVERLAP,NFFT) specifies the number of frequency points used to calculate the discrete Fourier transforms. If NFFT is not specified, the default NFFT is used.

S = SPECTROGRAM(X,WINDOW,NOVERLAP,NFFT,Fs) Fs is the sampling frequency specified in Hz. If Fs is specified as empty, it defaults to 1 Hz. If it is not specified, normalized frequency is used.

Each column of S contains an estimate of the short-term, time-localized frequency content of the signal X. Time increases across the columns of S, from left to right. Frequency increases down the rows, starting at 0. If X is a length NX complex signal, S is a complex matrix with NFFT rows and k = fix((NX-NOVERLAP)/(length(WINDOW)-NOVERLAP)) columns. For real X, S has (NFFT/2+1) rows if NFFT is even, and (NFFT+1)/2 rows if NFFT is odd.

[S,F,T] = SPECTROGRAM(...) returns a vector of frequencies F and a vector of times T at which the spectrogram is computed. F has length equal to the number of rows of S. T has length k (defined above) and

its value corresponds to the center of each segment.

[S,F,T] = SPECTROGRAM(X,WINDOW,NOVERLAP,F,Fs) where F is a vector of frequencies in Hz (with 2 or more elements) computes the spectrogram at those frequencies using the Goertzel algorithm. The specified frequencies in F are rounded to the nearest DFT bin commensurate with the signal's resolution.

[S,F,T,P] = SPECTROGRAM(...) P is a matrix representing the Power Spectral Density (PSD) of each segment. For real signals, SPECTROGRAM returns the one-sided modified periodogram estimate of the PSD of each segment; for complex signals and in the case when a vector of frequencies is specified, it returns the two-sided PSD.

SPECTROGRAM(...) with no output arguments plots the PSD estimate for each segment on a surface in the current figure. It uses SURF(f,t,10*log10(abs(P)) where P is the fourth output argument. A trailing input string, FREQLOCATION, controls where MATLAB displays the frequency axis. This string can be either 'xaxis' or 'yaxis'. Setting this FREQLOCATION to 'yaxis' displays frequency on the y-axis and time on the x-axis. The default is 'xaxis' which displays the frequency on the x-axis. If FREQLOCATION is specified when output arguments are

requested, it is ignored.

EXAMPLE 1: Display the PSD of each segment of a quadratic chirp. t=0:0.001:2; y=chirp(t,100,1,200,'q'); % 2 secs @ 1kHz sample rate % Start @ 100Hz, cross 200Hz at t=1sec

spectrogram(y,128,120,128,1E3); % Display the spectrogram title('Quadratic Chirp: start at 100Hz and cross 200Hz at t=1sec');

EXAMPLE 2: Display the PSD of each segment of a linear chirp. t=0:0.001:2; x=chirp(t,0,1,150); F = 0:.1:100; [y,f,t,p] = spectrogram(x,256,250,F,1E3,'yaxis'); % NOTE: This is the same as calling SPECTROGRAM with no outputs. surf(t,f,10*log10(abs(p)),'EdgeColor','none'); axis xy; axis tight; colormap(jet); view(0,90); xlabel('Time'); ylabel('Frequency (Hz)'); % 2 secs @ 1kHz sample rate % Start @ DC, cross 150Hz at t=1sec

You might also like