Signal Processing Toolbox Help Desk

psd

Purpose

Estimate the power spectral density (PSD) of a signal.

Syntax

Description

Pxx = psd(x) estimates the power spectrum of the sequence x using the Welch method of spectral estimation. Pxx = psd(x) uses the following default values:

nfft specifies the FFT length that psd uses. This value determines the frequencies at which the power spectrum is estimated. Fs is a scalar that specifies the sampling frequency. window specifies a windowing function and the number of samples psd uses in its sectioning of the x vector. 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 x is real, psd estimates the spectrum at positive frequencies only; in this case, the output Pxx is a column vector of length nfft/2+1 for nfft even and (nfft+1)/2 for nfft odd. If x is complex, psd estimates the spectrum at both positive and negative frequencies and Pxx has length nfft.

Pxx = psd(x,nfft) uses the specified FFT length nfft in estimating the power spectrum for x. Specify nfft as a power of 2 for fastest execution.

[Pxx,f] = psd(x,nfft,Fs) returns a vector f of frequencies at which the function evaluates the PSD. f is the same size as Pxx, so plot(f,Pxx) plots the power spectrum versus properly scaled frequency. Fs has no effect on the output Pxx; it is a frequency scaling multiplier.

Pxx = psd(x,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, psd uses a Hanning window of that length. The length of the window must be less than or equal to nfft; psd zero pads the sections if the length of the window is less than nfft. psd returns an error if the length of the window is greater than nfft.

Pxx = psd(x,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 except x. For example,

is equivalent to

but with a sampling frequency of 10,000 Hz instead of the default of 2 Hz.

Pxx = psd(x,...,'dflag') specifies a detrend option, where dflag is

The dflag parameter must appear last in the list of input arguments. psd recognizes a dflag string no matter how many intermediate arguments are omitted.

[Pxx,Pxxc,f] = psd(x,nfft,Fs,window,noverlap,p) where p is a positive scalar between 0 and 1 returns a vector Pxxc that contains an estimate of the p*100 percent confidence interval for Pxx. Pxxc is a two-column matrix that is the same length as Pxx. The interval [Pxxc(:,1),Pxxc(:,2)] covers the true PSD with probability p. plot(f,[Pxx Pxxc Pxxc]) plots the power spectrum inside the p*100 percent confidence interval. If unspecified, p defaults to 0.95.

psd(x,...) with no output arguments plots the PSD versus frequency in the current figure window. If the p parameter is specified, the plot includes the confidence interval.

Example

Generate a colored noise signal and plot its PSD with a confidence interval of 95%. Specify a length 1024 FFT, a 512-point Kaiser window with no overlap, and a sampling frequency of 10 kHz:

Algorithm

psd calculates the power spectral density using Welch's method (see references [1] and [2]):

  1. It applies the window specified by the window vector to each successive detrended section of x.
  2. It transforms each section with an nfft-point FFT.
  3. It forms the periodogram of each section by scaling the magnitude squared of each transform.
  4. It averages the periodograms of the overlapping sections to form Pxx, the power spectrum of x.
The number of sections that psd averages is

Diagnostics

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

See Also

cohere

Estimate magnitude squared coherence function between two signals.

csd

Estimate the cross spectral density (CSD) of two signals.

pmem

Power spectrum estimate using maximum entropy method (MEM).

pmtm

Power spectrum estimate using the multitaper method (MTM).

pmusic

Power spectrum estimate using MUSIC eigenvector method.

specgram

Time-dependent frequency analysis (spectrogram).

tfe

Transfer function estimate from input and output.

References

[1] Rabiner, L.R., and B. Gold. Theory and Application of Digital Signal Processing. Englewood Cliffs, NJ: Prentice Hall, 1975. Pgs. 399-419.

[2] Welch, P.D. "The Use of Fast Fourier Transform for the Estimation of Power Spectra: A Method Based on Time Averaging Over Short, Modified Periodograms." IEEE Trans. Audio Electroacoust. Vol. AU-15 (June 1967). Pgs. 70-73.

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



[ Previous | Help Desk | Next ]