# 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.
`window`- The window size, or the window vector.
`overlap`- The number of overlapping points in adjacent windows.
`nfft`- The size of the fft.
`fs`- The sampling frequency.
`range`- The spectrum range: 'onesided' or 'twosided'.
`spectrum type`- The spectrum type: 'psd' or 'power'.

## Outputs

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

## 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`.