pwelch

Computes the power spectral density.

Syntax

Pxx=pwelch(x)

Pxx=pwelch(x,window)

Pxx=pwelch(x,window,overlap)

Pxx=pwelch(x,window,overlap,nfft)

Pxx=pwelch(x,window,overlap,nfft,fs)

Pxx=pwelch(x,window,overlap,nfft,fs,range)

Pxx=pwelch(x,window,overlap,nfft,fs,range,spectrumtype)

[Pxx,freq]=pwelch(...)

pwelch(...)

Inputs

x
The signal.
Type: double
Dimension: vector | matrix
window
The window size, or the window vector.
The default is a Hamming window with a length that produces eight data segments.
Type: double | integer
Dimension: scalar | vector
overlap
The number of overlapping points in adjacent windows.
The default is one half of the window length.
Type: integer
Dimension: scalar
nfft
The size of the fft.
The default is the window length. A larger value will pad zeros to each block of windowed data.
Type: integer
Dimension: scalar
fs
The sampling frequency.
The default is 1.0 Hz.
Type: double
Dimension: scalar
range
The spectrum range: 'onesided' or 'twosided'.
The default is 'onesided'.
Type: string
spectrum type
The spectrum type: 'psd' or 'power'.
The default is 'psd'.
Type: string

Outputs

Pxx
The power spectral density or power spectrum.
Type: vector
freq
The vector of frequencies corresponding to the density values.
Type: vector

Example

n = 1000;                           
fs = 1125;                             
ts = 1/fs;              
t = [0:1:(n-1)]*ts;
f1 = 24;
f2 = 56;
omega1 = 2 * pi * f1;
omega2 = 2 * pi * f2;
signal = 3 + 5 * cos(omega1 * t) + 7 * cos(omega2 * t);
window = hann(250,'periodic');
overlap = 125;
fftsize = 250;
range = 'onesided';
[Pxx,frq]=pwelch(signal,window,overlap,fftsize,fs,range);
f = frq([1, 2, 3, 4, 5, 13, 14, 15])'
p = Pxx([1, 2, 3, 4, 5, 13, 14, 15])'
f = [Matrix] 1 x 8
0  4  20  24  28  52  56  60
p = [Matrix] 1 x 8
1.50000  0.75000  0.52083  2.08333  0.52083  1.02083  4.08333  1.02083

Comments

With no return arguments, the function will automatically plot.

The 'onesided' output has a length of nfft/2+1 if nfft is even, or (nfft+1)/2 if nfft is odd.

The 'power' scales the 'psd' result by the equivalent noise bandwidth.

It is often recommended to remove the signal mean prior to calling pwelch. The function does not remove the mean automatically.

When x is a 2D matrix pwelch will operate on each column and the output vectors will be stored in the columns of Pxx.