Lab 3 PSD
Lab 3 PSD
Lab 3 PSD
Power Spectral Densfty (PSD) is the frequency response of a random or periodic signal. It tells
us where the average power is distributed as a function of frequency.
The PSD is deterministic, and for certain types of random signals is independent of time1.
This is useful because the Fourier transform of a random time signal is itself random, and
therefore of little use calculating transfer relationships (i.e., finding the output of a filter
when the input is random).
The PSD of a random time signal x(t) can be expressed in one of two ways that are
equivalent to each other
1. The PSD is the average of the Fourier transform magnitude squared, over a large
time interval
1
S x ( f ) lim E
T 2T
x(t )e
T
j 2ft
dt
R ( )e
T
j 2ft
dt
R x ( ) E x(t ) x * (t )
The power can be calculated from a random signal over a given band of frequencies as
follows:
S ( f )df R (0)
P12
f2
S ( f )df R (0)
f1
The signal has to be stationary, which means that us statistics do not change as a function of
time.
If a random signal x(t) is passed through a time-invariant filter with frequency response H(f),
the resulting signal y(t) has a PSD as follows:
x(t)
y(t)
H(f)
Sy ( f ) Sx ( f ) H( f )
xl=randn(1,10000);
x2=randn(1,10000);
t=linspace(0,10,10000);
dt = t(2)-t(1);
subplot(2,2,1),plot(t,x1)
subplot(2,2,2),plot(t,x2)
% signal 1
% signal 2
% time series
% time increment
%plot of x1
%plot of x2
The sample frequency is 1kHz. The FFT of each of these signals is calculated from
X1=fftshift(fft(x1));
X2=fftshift(fft(x2));
Df=1/dt;
f=linspace(Df/2,Df/2,10000);
subplot(2,2,3),plot(f,dB(X1));
subplot(2,2,4),plot(f,dB(X2));
% FFT of signal 1
% FFT of signal 2
% fequency span
% frequency series
%plot of FFT of x1
%plot FFT of x2
The plot below shows a 0.1 second snapshot of two random time functions x1(t) and x2(t) and
the first 10 Hz of the fast Fourier transform of these signals.
This shows that the frequency responses of these random signals are generally different,
although they seem to have a common average level, and have similar overall randomness,
which would be exhibited in the rest of the spectrum if we were to show it.
Perhaps what we should be doing is looking at the average Fourier transform instead of just a
single sample of the Fourier transform this is, more or less, what the PSD is; it is the average
Fourier transform squared taken over a very long time interval.
We now calculate and plot the PSD of the original time series x1(t) and x2(t).
x1=randn(1,10000);
x2=randn(1,10000);
t=linspace(0,10,10000);
dt = t(2)-t(1);
Df = 1/dt
subplot(2,2,1),plot(t,x1)
subplot(2,2,2),plot(t,x2)
Sx1=psd(x1,1024,1000);
Sx2=psd(x2,1024,1000);
f=linspace0,Df/2,length(Sx1));
subplot(2,2,3),plot(f,db(Sx1));
subplot(2,2,4),plot(f,db(Sx2));
% signal 1
% signal 2
% time series
% time increment
% fequency span
%plot of x1
%plot of x2
%PSD of x1
%PSD of x2
% frequency series
%plot of PSD of x1
%plot of PSD of x2
The PSD for each signal looks more or less flat across the frequency band. This type of noise is
referred to as white, and if we had taken an infinitesimally small time increment, we would see
this flatness across the entire frequency band.
The reason that there is some variation about the constant level is that we didnt take a large
enough (i.e., infinite) time sequence of random numbers to calculate the PSD from. The estimate
of the PSD (as calculated in MATLAB) becomes more accurate as the sample size becomes
infinite.
The mean of the PSDs of xl and x2 turn out to be very close to 1.
mean(Sxl)
mean(Sx2)
%= 1.0137
%= 1.0241
This is telling us that the average value of the MATLAB PSD, which is the variance, is close to
unity.
Now lets consider filtering the Gaussian noise. First design a high order Butterworth filter that
cuts off at half the Nyquist frequency (500 Hz)
[b,a]=butter(40,0.5);
Now plot the frequency response, normalized to the nyquist frequency (this just makes the
maximum frequency be 1)
freqz(b,a)
Now produce new noise samples y1(t) and y2(t) by filtering x1(t) and x2(t).
y1=filter(b,a,x1);
%filter x1
y2=filter(b,a,x2);
%filter x2
Y1=fftshift(fft(y1)); %calculate frequency response of y1
Y2=fftshift(fft(y2)); %calculate frequency response of y2
subplot(2,2,1),plot(t,x1)
%plot of y1
subplot(2,2,2),plot(t,x2)
%plot of y2
subplot(2,2,3),plot(f,dB(X1));
%plot of FFT of y1
subplot(2,2,4),plot(f,dB(X2));
%plot FFT of y2
We see that the time series is smoother (it has been filtered), but the FFT remains random. The
variance of the filtered noise is reduced to roughly 0.5.
var(y1)
var(y2)
%= 0.4895
%= 0.4956
Sy1=psd(y1,1024,1000);
Sy2=psd(y2,1024,1000);
f=linspace(0,Df/2,length(Sx1));
subplot(2,2,1),plot(t,x1)
subplot(2,2,2),plot(t,x2)
subplot(2,2,3),plot(f,db(Sy1));
subplot(2,2,4),plot(f,db(Sy2));
%PSD of y1
%PSD of y2
% frequency series
%plot of y1
%plot of y2
%plot of PSD of x1
%plot of PSD of x2
Basically what we have done here is filtered white noise. The PSD of the filtered noise takes on
the shape of the filter frequency response, and is the same (within experimental variation) for
each independent noise signal.