Forums

Question : PSD, FFT, autocorrelation

Started by Joe February 21, 2005
Hello everybody

I have made a little program in Matlab that calculates the PSD of a signal 
in two ways. One is based on FFT of the autocorrelation function and the 
other PSD is based on an FFT of the signal. For some reason the resulting 
graphs do not look alike. One has a much higher peak than the other. I have
had no luck in finding out how to calculate the scaling factor so I hope
that there is somebody out there who can help me with this problem?

Thanks :o)

Here is the code:

close all
clc
clear

close all
clc
clear

Fs=40000;
t=0:1/Fs:1;
xn=sin(2*pi*2000*t);
N=2^ceil(log2(length(xn)))
f=[-0.5*Fs:Fs/N:0.5*Fs-Fs/N];
Xg=fftshift(fft(xn,N));
Sxx=(length(xn)/Fs).*abs(Xg).^2;
plot(f,Sxx)
rxx=xcorr(xn);
Sxx2=abs(fftshift(fft(rxx,N)));
figure
plot(f,Sxx2)




Joe wrote:
> Hello everybody > > I have made a little program in Matlab that calculates the PSD of a signal > in two ways. One is based on FFT of the autocorrelation function and the > other PSD is based on an FFT of the signal. For some reason the resulting > graphs do not look alike. One has a much higher peak than the other. I have > had no luck in finding out how to calculate the scaling factor so I hope > that there is somebody out there who can help me with this problem?
The frequencies in your FFT do not exactly match the frequency (2000 Hz) of your signal. OUP
Joe wrote:
> Hello everybody > > I have made a little program in Matlab that calculates the PSD of a
signal
> in two ways. One is based on FFT of the autocorrelation function and
the
> other PSD is based on an FFT of the signal. For some reason the
resulting
> graphs do not look alike. One has a much higher peak than the other.
I have
> had no luck in finding out how to calculate the scaling factor so I
hope
> that there is somebody out there who can help me with this problem?
The discrepancy is caused by the estimator for the signal autocorrelation series. The series rxx is first of all biased, it is scaled by a triangular window. This corresponds to convolution in frequency domain between the "true" spectrum and the spectrum of the triangular weight function. Second, the lengths of the sequences xn and rxx are different. The autocorrelation sequence rxx has length 2N-1 where N is the length of xn. This means that no frequency bins in the spectrum of rxx coincide with bins in the spectrum of xn. You could correct for this by zero- padding xn to length 2N-1. To summarize, you have discovered that different estimators for a quantity produce different estimates when applied to the same data. The art of statistical signal processing consits of recognizing this, and being able to choose the correct estimator in any given situation. Rune