Signal Processing Toolbox | Help Desk |
psd
Estimate the power spectral density (PSD) of a signal.
Pxx = psd(x)
Pxx = psd(x,nfft)
[Pxx,f] = psd(x,nfft,Fs)
Pxx = psd(x,nfft,Fs,window)
Pxx = psd(x,nfft,Fs,window,noverlap)
Pxx = psd(x,...,'dflag
')
[Pxx,Pxxc,f] = psd(x,nfft,Fs,window,noverlap,p)
psd(x,...)
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 = min(256,length(x))
Fs = 2
window = hanning(nfft)
noverlap
= 0
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,
psd(x,[],10000)is equivalent to
psd(x)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
linear
, to remove the best straight-line fit from the prewindowed sections of x
mean
, to remove the mean from the prewindowed sections of x
none
, for no detrending (default)
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.
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:
h = fir1(30,0.2,boxcar(31)); % design a lowpass filter r = randn(16384,1); % white noise x = filter(h,1,r); % color the noise psd(x,1024,10000,kaiser(512,5),0,0.95)
![]()
psd
calculates the power spectral density using Welch's method (see references [1] and [2]):
window
vector to each successive detrended section of x
.
nfft
-point FFT.
Pxx
, the power spectrum of x
.
psd
averages is
k = fix((length(x)-noverlap)/(length(window)-noverlap))An appropriate diagnostic message is displayed when incorrect arguments to
psd
are used:
Requires window's length to be no greater than FFT length. Requires NOVERLAP to be strictly less than the window length. Requires positive integer values for NFFT and NOVERLAP. Requires confidence parameter to be a scalar between 0 and 1. Requires vector input.
Estimate magnitude squared coherence function between two signals. |
|