pxx = periodogram(x) returns
the periodogram power spectral density (PSD) estimate of the input
signal, x, using a rectangular window. If x is
real-valued, pxx is a one-sided PSD estimate.
If x is complex-valued, pxx is
a two-sided PSD estimate. The number of points, nfft,
in the discrete Fourier transform (DFT) is the maximum of 256 or the
next power of two greater than the signal length.

pxx = periodogram(x,window,nfft) uses nfft points
in the discrete Fourier transform (DFT). If nfft is
greater than the signal length, x is zero-padded
to length nfft. If nfft is
less than the signal length, the signal is wrapped modulo nfft and
summed using datawrap. For example, the input
signal [1 2 3 4 5 6 7 8] with nfft equal
to 4 results in the periodogram of sum([1 5; 2 6; 3 7; 4
8],2).

[pxx,w]
= periodogram(___) returns the normalized frequency
vector, w. If pxx is a one-sided
periodogram, w spans the interval [0,π]
if nfft is even and [0,π) if nfft is
odd. If pxx is a two-sided periodogram, w spans
the interval [0,2π).

[pxx,f]
= periodogram(___,fs) returns
a frequency vector, f, in cycles per unit time.
The sampling frequency, fs, is the number of
samples per unit time. If the unit of time is seconds, then f is
in cycles/sec (Hz). For real–valued signals, f spans
the interval [0,fs/2] when nfft is
even and [0,fs/2) when nfft is
odd. For complex-valued signals, f spans the
interval [0,fs).

[pxx,w]
= periodogram(x,window,w) returns
the two-sided periodogram estimates at the normalized frequencies
specified in the vector, w. The vector, w,
must contain at least 2 elements.

[pxx,f]
= periodogram(x,window,f,fs) returns
the two-sided periodogram estimates at the frequencies specified in
the vector, f. The vector, f,
must contain at least 2 elements. The frequencies in f are
in cycles per unit time. The sampling frequency, fs,
is the number of samples per unit time. If the unit of time is seconds,
then f is in cycles/sec (Hz).

[___] = periodogram(x,window,___,freqrange) returns
the periodogram over the frequency range specified by freqrange.
Valid options for freqrange are: 'onesided', 'twosided',
or 'centered'.

[___] = periodogram(x,window,___,spectrumtype) returns
the PSD estimate if spectrumtype is specified
as 'psd' and returns the power spectrum if spectrumtype is
specified as 'power'.

Obtain the periodogram of an input signal consisting
of a discrete-time sinusoid with an angular frequency of π/4
radians/sample with additive N(0,1) white noise.

Create a sine wave with an angular frequency of π/4
radians/sample with additive N(0,1) white noise. The signal is 320
samples in length. Obtain the periodogram using the default rectangular
window and DFT length. The DFT length is the next power of two greater
than the signal length, or 512 points. Because the signal is real-valued
and has even length, the periodogram is one-sided and there are 512/2+1
points.

n = 0:319;
x = cos(pi/4*n)+randn(size(n));
pxx = periodogram(x);
plot(10*log10(pxx))

Obtain the modified periodogram of an input
signal consisting of a discrete-time sinusoid with an angular frequency
of π/4 radians/sample with additive N(0,1) white noise.

Create a sine wave with an angular frequency of π/4
radians/sample with additive N(0,1) white noise. The signal is 320
samples in length. Obtain the modified periodogram using a Hamming
window and default DFT length. The DFT length is the next power of
two greater than the signal length, or 512 points. Because the signal
is real-valued and has even length, the periodogram is one-sided and
there are 512/2+1 points.

n = 0:319;
x = cos(pi/4*n)+randn(size(n));
pxx = periodogram(x,hamming(length(x)));
plot(10*log10(pxx))

Obtain the periodogram of an input signal consisting
of a discrete-time sinusoid with an angular frequency of π/4
radians/sample with additive N(0,1) white noise. Use a DFT length
equal to the signal length.

Create a sine wave with an angular frequency of π/4
radians/sample with additive N(0,1) white noise. The signal is 320
samples in length. Obtain the periodogram using the default rectangular
window and DFT length equal to the signal length. Because the signal
is real-valued, the one-sided periodogram is returned by default with
a length equal to 320/2+1.

n = 0:319;
x = cos(pi/4*n)+randn(size(n));
nfft = length(x);
pxx = periodogram(x,[],nfft);
plot(10*log10(pxx))

Obtain the periodogram of the Wolf (relative
sunspot) number data sampled yearly between 1700 and 1987.

Load the relative sunspot number data. Obtain the periodogram
using the default rectangular window and number of DFT points (512
in this example). The sampling rate for these data is 1 sample/year.
Plot the periodogram.

load sunspot.dat
relNums=sunspot(:,2);
[pxx,f] = periodogram(relNums,[],[],1);
plot(f,10*log10(pxx))
xlabel('Cycles/Year'); ylabel('dB');
title('Periodogram of Relative Sunspot Number Data');

You see in the preceding figure that there is a peak in the
periodogram at approximately 0.1 cycles/year, which indicates a period
of approximately 10 years.

Obtain the periodogram of an input signal consisting of
two discrete-time sinusoids with an angular frequencies of π/4
and π/2 radians/sample in additive N(0,1) white noise. Use Goertzel's
algorithm to obtain the two-sided periodogram estimates at π/4
and π/2 radians/sample. Compare the result to the one-sided
periodogram.

n = 0:319;
x = cos(pi/4*n)+0.5*sin(pi/2*n)+randn(size(n));
[pxx,w] = periodogram(x,[],[pi/4 pi/2]);
pxx
[pxx1,w1] = periodogram(x);
plot(w1,pxx1)

You see that the periodogram values obtained using Goertzel's
algorithm are 1/2 the values in the one-sided periodogram. This is
consistent with the fact that using Goertzel's algorithm returns
the two-sided periodogram.

Create a signal consisting of two sine waves with frequencies
of 100 and 200 Hz in N(0,1) white additive noise. The sampling frequency
is 1 kHz. Use Goertzel's algorithm to obtain the two-sided
periodogram at 100 and 200 Hz.

fs = 1000;
t = 0:0.001:1-0.001;
x = cos(2*pi*100*t)+sin(2*pi*200*t)+randn(size(t));
freq = [100 200];
[pxx,f] = periodogram(x,[],freq,fs);

The following example illustrates the use of
confidence bounds with the periodogram. While not a necessary condition
for statistical significance, frequencies in the periodogram where
the lower confidence bound exceeds the upper confidence bound for
surrounding PSD estimates clearly indicate significant oscillations
in the time series.

Create a signal consisting of the superposition of 100-Hz
and 150-Hz sine waves in additive white N(0,1) noise. The amplitude
of the two sine waves is 1. The sampling frequency is 1 kHz.

t = 0:0.001:1-0.001;
fs = 1000;
x = cos(2*pi*100*t)+sin(2*pi*150*t)+randn(size(t));

Obtain the periodogram with 95%-confidence bounds. Plot
the periodogram along with the confidence interval and zoom in on
the frequency region of interest near 100 and 150 Hz.

[pxx,f,pxxc] = periodogram(x,rectwin(length(x)),length(x),fs,...'ConfidenceLevel', 0.95);
plot(f,10*log10(pxx)); hold on;
plot(f,10*log10(pxxc),'r--','linewidth',2);
axis([85 175 min(min(10*log10(pxxc))) max(max(10*log10(pxxc)))]);
xlabel('Hz'); ylabel('dB');
title('Periodogram with 95%-Confidence Bounds');

At 100 and 150 Hz, the lower confidence bound exceeds the upper
confidence bounds for surrounding PSD estimates.

Estimate the power of sinusoid at a specific
frequency using the 'power' option.

Create a 100-Hz sinusoid one second in duration sampled
at 1 kHz. The amplitude of the sine wave is 1.8, which equates to
a power of 1.8^{2}/2 =
1.62. Estimate the power using the 'power' option.

fs = 1000;
t = 0:1/fs:1-1/fs;
x = 1.8*cos(2*pi*100*t);
[pxx,f] = periodogram(x,hamming(length(x)),length(x),fs,'power');
[pwrest,idx] = max(pxx);
fprintf('The maximum power occurs at %3.1f Hz\n',f(idx));
fprintf('The power estimate is %2.2f\n',pwrest);

Obtain the periodogram of a 100-Hz sine wave in additive
N(0,1) noise. The data are sampled at 1 kHz. Use the 'centered' option
to obtain the DC-centered periodogram and plot the result.

fs = 1000;
t = 0:0.001:1-0.001;
x = cos(2*pi*100*t)+randn(size(t));
[pxx,f] = periodogram(x,[],length(x),fs,'centered');
plot(f,10*log10(pxx))
xlabel('Hz'); ylabel('dB')

Window, specified as a row or column vector the same length
as the input signal. If you specify window as
empty, the default rectangular window is used.

Number of DFT points, specified as a positive integer. For a
real-valued input signal, x, the PSD estimate, pxx has
length (nfft/2+1) if nfft is
even, and (nfft+1)/2 if nfft is
odd. For a complex-valued input signal,x, the
PSD estimate always has length nfft. If nfft is
specified as empty, the default nfft is used.

Sampling frequency specified as a positive scalar. The sampling
frequency is the number of samples per unit time. If the unit of time
is seconds, the sampling frequency has units of hertz.

Normalized frequencies for Goertzel algorithm, specified as
a row or column vector with at least 2 elements. Normalized frequencies
are in radians/sample.

Cyclical frequencies for Goertzel algorithm, specified as a
row or column vector with at least 2 elements. The frequencies are
in cycles per unit time. The unit time is specified by the sampling
frequency, fs. If fs has
units of samples/second, then f has units of
Hz.

Frequency range for the PSD estimate, specified as a one of 'onesided', 'twosided',
or 'centered'. The default is 'onesided' for
real-valued signals and 'twosided' for complex-valued
signals. The frequency ranges corresponding to each option are

'onesided' — returns the
one-sided PSD estimate of a real-valued input signal, x.
If nfft is even, pxx will
have length nfft/2+1 and is computed over the
interval [0,π] radians/sample. If nfft is
odd, the length of pxx is (nfft+1)/2
and the interval is [0,π) radians/sample. When fs is
optionally specified, the corresponding intervals are [0,fs/2]
cycles/unit time and [0,fs/2) cycles/unit time
for even and odd length nfft respectively.

'twosided' — returns the
two-sided PSD estimate for either the real-valued or complex-valued
input, x. In this case, pxx has
length nfft and is computed over the interval
[0,2π) radians/sample. When fs is optionally
specified, the interval is [0,fs) cycles/unit
time.

'centered' — returns the
centered two-sided PSD estimate for either the real-valued or complex-valued
input, x. In this case, pxx has
length nfft and is computed over the interval
(-π,π] radians/sample for even length nfft and
(-π,π) radians/sample for odd length nfft.
When fs is optionally specified, the corresponding
intervals are (-fs/2, fs/2]
cycles/unit time and (-fs/2, fs/2)
cycles/unit time for even and odd length nfft respectively.

Power spectrum scaling, specified as one of 'psd' or 'power'.
Omitting the spectrumtype, or specifying 'psd',
returns the power spectral density. Specifying 'power' scales
each estimate of the PSD by the equivalent noise bandwidth of the
window. Use the 'power' option to obtain an estimate
of the power at each frequency.

Coverage probability for the true PSD, specified as a scalar
in the range (0,1). The output, pxxc, contains
the lower and upper bounds of the probabilityx100%
interval estimate for the true PSD.

PSD estimate, specified as a real-valued, nonnegative column
vector. The units of the PSD estimate are in squared magnitude units
of the time series data per unit frequency. For example, if the input
data is in volts, the PSD estimate is in units of squared volts per
unit frequency. For a time series in volts, if you assume a resistance
of 1 ohm and specify the sampling frequency in Hz, the PSD estimate
is in watts/Hz.

Normalized frequencies, specified as a real-valued column vector.
If pxx is a one-sided PSD estimate, w spans
the interval [0,π] if nfft is even and
[0,π) if nfft is odd. If pxx is
a two-sided PSD estimate, w spans the interval
[0,2π). For a DC-centered PSD estimate, f spans
the interval (-π,π] radians/sample for even length nfft and
(-π,π) radians/sample for odd length nfft.

Cyclical frequencies, specified as a real-valued column vector.
For a one-sided PSD estimate, f spans the interval
[0,fs/2] when nfft is even
and [0,fs/2) when nfft is
odd. For a two-sided PSD estimate, f spans the
interval [0,fs). For a DC-centered PSD estimate, f spans
the interval (-fs/2, fs/2]
cycles/unit time for even length nfft and (-fs/2, fs/2)
cycles/unit time for odd length nfft .

Confidence bounds, specified as an N-by-2 matrix with real-valued
elements. The row dimension of the matrix is equal to the length of
the PSD estimate, pxx. The first column contains
the lower confidence bound and the second column contains the upper
confidence bound for the corresponding PSD estimates in the rows of pxx.
The coverage probability of the confidence intervals is determined
by the value of the probability input.

The periodogram is a nonparametric estimate of the power spectral
density (PSD) of a wide-sense stationary random process. The periodogram
is the Fourier transform of the biased estimate of the autocorrelation
sequence. For a signal, x_{n},
sampled at fs samples per unit time, the periodogram
is defined as

where Δt is the sampling interval. For a one-sided periodogram,
the values at all frequencies except 0 and the Nyquist, 1/2Δt,
are multiplied by 2 so that the total power is conserved.

If the frequencies are in radians/sample, the periodogram is
defined as

The frequency range in the preceding equations has variations
depending on the value of the freqrange argument.
See the description of freqrange in Input Arguments.

The integral of the true PSD, P(f), over
one period, 1/Δt for cyclical frequency and
2π for normalized frequency, is equal to the variance of the
wide-sense stationary random process.

For normalized frequencies, replace
the limits of integration appropriately.

The modified periodogram multiplies the input time series by
a window function. A suitable window function is nonnegative and decays
to zero at the beginning and end points. Multiplying the time series
by the window function tapers the data gradually
on and off and helps to alleviate the leakage in the periodogram.
See Bias and Variability in the Periodogram for an example.

If h_{n} is a window
function, the modified periodogram is defined by

where Δt is the sampling interval.

If the frequencies are in radians/sample, the modified periodogram
is defined as

The frequency range in the preceding equations has variations
depending on the value of the freqrange argument.
See the description of freqrange in Input Arguments.