`plotpsd` documentation

This function plots a power spectral density of a time series using the `periodogram` function.

## Contents

## Syntax

plotpsd(y,Fs) plotpsd(y,x) plotpsd(...,LineProperty,LineValue) plotpsd(...,'logx') plotpsd(...,'db') plotpsd(...,'lambda') h = plotpsd(...)

## Description

`plotpsd(y,Fs)` plots a power spectrum of 1D array `y` at sampling frequency `Fs` using the `periodogram` function. Sampling frequency `Fs` must be a scalar.

`plotpsd(y,x)` plots a power spectrum of `y` referenced to an independent variable `x`. This syntax requires `x` and `y` to be of equal length and `x` must be equally spaced and monotically increasing. For time series, `x` likely has units of time; for spatial analysis `x` may have units of length.

`plotpsd(...,LineProperty,LineValue)` specifies the plot's line style with any combinations of LineSpec properties (e.g., `'color','r','linewidth',2`, etc).

`plotpsd(...,'logx')` specfies a `semilogx` plot.

`plotpsd(...,'db')` plots power spectrum in decibels.

`plotpsd(...,'lambda')` labels horizontal axis as wavelengths rather than the default frequency. Note, this syntax assumes lambda = 1/f.

`h = plotpsd(...)` returns a handle `h` of the plotted graphics object.

## Examples

Using the inbuilt `train` whistle example, plot start by plotting the time series for context:

load train t = (0:length(y)-1)/Fs; plot(t,y) box off xlabel 'time (s)'

The power spectrum of the train signal looks like this:

```
plotpsd(y,Fs)
xlabel 'frequency (Hz)'
```

This makes the three horns of the train quite clear! Don't like the default thin blue line? Plot a fat red line instead:

plotpsd(y,Fs,'color','red','linewidth',4) xlabel 'frequency (Hz)'

Want to see that as a magenta line plotted in decibels?

plotpsd(y,Fs,'m','db') xlabel 'frequency (Hz)'

Here's a black line with decibels on the vertical scale and a log scale in the horizontal direction.

plotpsd(y,Fs,'k','db','logx') axis tight xlabel 'frequency (Hz)'

Suppose you have some measurements `y` tied to some time vector `t` and you don't want to go through the effort of calculating the sampling rate. If this is the case, simply enter `t` instead of `Fs`:

plotpsd(y,t,'b:','logx') xlabel 'frequency (Hz)'

## Author Info

This function and supporting documentation were written by Chad A. Greene of the University of Texas at Austin's Institute for Geophysics (UTIG), October 2015.