You are here : matlabSignal Processingperiodogram

periodogram() - Signal Processing

examplepxx = periodogram(x) returns
the periodogram power spectral density (PSD) estimate, pxx,
of the input signal, x, found using a rectangular
window. When x is a vector, it is treated as
a single channel. When x is a matrix, the PSD
is computed independently for each column and stored in the corresponding
column of pxx. 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.
examplepxx = periodogram(x,window) returns
the modified periodogram PSD estimate using the window, window. window is
a vector the same length as x.
examplepxx = 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π).
example[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/second (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).

example[pxx,w] = periodogram(x,window,w) returns
the two-sided periodogram estimates at the normalized frequencies
specified in the vector, w. w must
contain at least two elements.
example[pxx,f] = periodogram(x,window,f,fs) returns
the two-sided periodogram estimates at the frequencies specified in
the vector, f. f must contain
at least two 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/second (Hz).

example[___] = periodogram(x,window,___,freqrange) returns
the periodogram over the frequency range specified by freqrange.
Valid options for freqrange are: 'onesided', 'twosided',
or 'centered'.
example[___] = 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'.

example[___,pxxc] = periodogram(___,'ConfidenceLevel',probability) returns
the probability × 100%
confidence intervals for the PSD estimate in pxxc.

[rpxx,f]
= periodogram(___,'reassigned') reassigns each
PSD estimate to the frequency closest to its center of energy. rpxx contains
the sum of the estimates reassigned to each element of f.
example[rpxx,f,pxx,fc]
= periodogram(___,'reassigned') also returns
the nonreassigned PSD estimates, pxx, and the
center-of-energy frequencies, fc. If you use
the 'reassigned' flag, then you cannot specify
a probability confidence interval.

exampleperiodogram(___) with no output
arguments plots the periodogram PSD estimate in dB per unit frequency
in the current figure window.

Syntax

pxx = periodogram(x) examplepxx = periodogram(x,window) examplepxx = periodogram(x,window,nfft) example[pxx,w] = periodogram(___)[pxx,f] = periodogram(___,fs) example[pxx,w] = periodogram(x,window,w) example[pxx,f] = periodogram(x,window,f,fs) example[___] = periodogram(x,window,___,freqrange) example[___] = periodogram(x,window,___,spectrumtype) example[___,pxxc] = periodogram(___,'ConfidenceLevel',probability) example[rpxx,f]
= periodogram(___,'reassigned')[rpxx,f,pxx,fc]
= periodogram(___,'reassigned') exampleperiodogram(___) example

Example

Periodogram Using Default InputsOpen This Example
Obtain the periodogram of an input signal consisting of a discrete-time sinusoid with an angular frequency of
white noise.
Create a sine wave with an angular frequency of
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,w] = periodogram(x);
plot(w,10*log10(pxx))

Repeat the plot using periodogram with no outputs.periodogram(x)

Modified Periodogram with Hamming WindowOpen This Example
Obtain the modified periodogram of an input signal consisting of a discrete-time sinusoid with an angular frequency of
white noise.
Create a sine wave with an angular frequency of
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));
periodogram(x,hamming(length(x)))

DFT Length Equal to Signal LengthOpen This Example
Obtain the periodogram of an input signal consisting of a discrete-time sinusoid with an angular frequency of
white noise. Use a DFT length equal to the signal length.
Create a sine wave with an angular frequency of
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);
periodogram(x,[],nfft)

Periodogram of Relative Sunspot NumbersOpen This Example
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 sample 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.Periodogram at a Given Set of Normalized FrequenciesOpen This Example
Obtain the periodogram of an input signal consisting of two discrete-time sinusoids with an angular frequencies of
and
white noise. Obtain the two-sided periodogram estimates at
and
rad/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/pi,pxx1,w/pi,2*pxx,'o')
legend('pxx1','2 * pxx')
xlabel('\omega / \pi')

pxx =

14.0589    2.8872

The periodogram values obtained are 1/2 the values in the one-sided periodogram. When you evaluate the periodogram at a specific set of frequencies, the output is a two-sided estimate.Periodogram at a Given Set of Cyclical FrequenciesOpen This Example
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. 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 = periodogram(x,[],freq,fs)

pxx =

0.2647    0.2313

Upper and Lower 95%-Confidence BoundsOpen This Example
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.fs = 1000;
t = 0:0.001:1-0.001;
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-.')

xlim([85 175])
xlabel('Hz')
ylabel('dB')
title('Periodogram with 95%-Confidence Bounds')

The lower confidence bound in the immediate vicinity of 100 and 150 Hz is significantly above the upper confidence bound outside the vicinity of 100 and 150 Hz.Power Estimate of SinusoidOpen This Example
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
. 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);
The maximum power occurs at 100.0 Hz
The power estimate is 1.62
DC-Centered PeriodogramOpen This Example
Obtain the periodogram of a 100 Hz sine wave in additive
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));
periodogram(x,[],length(x),fs,'centered')

Reassigned PeriodogramOpen This ExampleGenerate a signal that consists of a 200 Hz sinusoid embedded in white Gaussian noise. The signal is sampled at 1 kHz for 1 second. The noise has a variance of 0.012. Reset the random number generator for reproducible results.rng('default')

Fs = 1000;
t = 0:1/Fs:1-1/Fs;
N = length(t);
x = sin(2*pi*t*200)+0.01*randn(size(t));
Use the FFT to compute the power spectrum of the signal, normalized by the signal length. The sinusoid is in-bin, so all the power is concentrated in a single frequency sample. Plot the one-sided spectrum. Zoom in to the vicinity of the peak.q = fft(x,N);
ff = 0:Fs/N:Fs-Fs/N;

ffts = q*q'/N^2

ff = ff(1:floor(N/2)+1);
q = q(1:floor(N/2)+1);

stem(ff,abs(q)/N,'*')
axis([190 210 0 0.55])

ffts =

0.4997

Use periodogram to compute the power spectrum of the signal. Specify a Hann window and an FFT length of 1024. Find the percentage difference between the estimated power at 200 Hz and the actual value.wind = hann(N);

[pun,fr] = periodogram(x,wind,1024,Fs,'power');

hold on
stem(fr,pun)

periodogErr = abs(max(pun)-ffts)/ffts*100

periodogErr =

4.7349

Recompute the power spectrum, but this time use reassignment. Plot the new estimate and compare its maximum with the FFT value.[pre,ft,pxx,fx] = periodogram(x,wind,1024,Fs,'power','reassigned');

stem(fx,pre)
hold off

reassignErr = abs(max(pre)-ffts)/ffts*100

reassignErr =

0.0779

Periodogram PSD Estimate of a Multichannel SignalOpen This Example
Generate 1024 samples of a multichannel signal consisting of three sinusoids in additive
white Gaussian noise. The sinusoids' frequencies are
,
, and
rad/sample. Estimate the PSD of the signal using the periodogram and plot it.
N = 1024;
n = 0:N-1;

w = pi./[2;3;4];
x = cos(w*n)' + randn(length(n),3);

periodogram(x)

Related ExamplesBias and Variability in the PeriodogramPower Spectral Density Estimates Using FFT