Power Spectral Density | MATLAB Tutorial

The Fourier transform of the autocorrelation sequence of any random process gives power spectral density or power spectrum of that signal. The power spectral density is denoted as Pxx(f). Therefore, estimation the power spectral density is equivalent to estimating the autocorrelation. For an ergodic random process if x(n) is known for all n, then estimating power spectral density is straightforward. However, there are two primary limitations making spectral estimation an extremely challenging problem.

Use of DFT/FFT in Power Spectral Density Estimation.

The computation of energy density spectrum and power density spectrum can be efficiently performed by using the techniques of DFT computation via FFT.

Example:

Compute the power spectral density of the signal,
x(n)= {1,1,1,1,0,0,0,0}. Also, sketch spectrums for various lengths of FFT.

MATLAB CODE:

Calculation of PSD using 8 point FFT

```clear all
clc
x=[1,1,1,1,0,0,0,0]; %Input Sequence
Ns=length(x); %Length of input sequence
N=8 %Length of FFT
psd=abs(fft(x,N)).^2/Ns %Calculation of PSD using 8 point FFT
stem((0:(N-1))/N, psd); %Plot PSD
xlim([0 1]);
xlabel('Discrete frequency f, f=k/N, k=0,1....N-1','Fontsize',11, 'fontweight','b');
ylabel('power','fontsize',11,'fontweight','b');
title('power spectrum, FFT length N=8','fontsize',11,'fontweight','b');
```

Calculation of PSD using 16 point FFT

```clear all
clc
x=[1,1,1,1,0,0,0,0]; %Input Sequence
Ns=length(x); %Length of input sequence
N=8 %Length of FFT
psd=abs(fft(x,N)).^2/Ns %Calculation of PSD using 8 point FFT
stem((0:(N-1))/N, psd); %Plot PSD
xlim([0 1]);
xlabel('Discrete frequency f, f=k/N, k=0,1....N-1','Fontsize',11, 'fontweight','b');
ylabel('power','fontsize',11,'fontweight','b');
title('power spectrum, FFT length N=8','fontsize',11,'fontweight','b');
```

Calculation of PSD using 32 Points FFT

```clear all
clc
x=[1,1,1,1,0,0,0,0];%Input Sequence
Ns=length(x); %Length of input sequence
N=32 %Length of FFT
psd=abs(fft(x,N)).^2/Ns; %Calculation of PSD using 32 point FFT figure,stem((0:(N-1))/N, psd);  %Plot PSD
xlabel('Discrete frequency f, f=k/N, k=0,1....N-1','Fontsize',11, 'fontweight','b');
ylabel('power','fontsize',11,'fontweight','b');
title('power spectrum, FFT length N=32','fontsize',11,'fontweight','b')
```

Calculation of PSD using 64 point FFT

```clear all
clc
x=[1,1,1,1,0,0,0,0]; %Input Sequence
Ns=length(x); %Length of input sequence
N=64 %Length of FFT
psd=abs(fft(x,N)).^2/Ns; %Calculation of PSD using 64 point FFT
figure,stem((0:(N-1))/N, psd); %Plot PSD
xlabel('Discrete frequency f, f=k/N, k=0,1....N-1','Fontsize',11, 'fontweight','b');
ylabel('power','fontsize',11,'fontweight','b');
title('power spectrum, FFT length N=64','fontsize',11,'fontweight','b')
```

OUTPUT:

with FFT Length, N=32

I am text block. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.