Finding the auto-correlation function from PSD
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I want to find the auto-correlation (AC) function of a signal by taking the inverse fourier transform of the power spectral density (PSD), but when I test my code on a sample signal the resulting AC function does not match with the AC I calcuate using the xcorr function. What is the reason of this difference? Should I calculate the PSD in a different way?
The signal is a noisy signal comprised of two sine signals (MATLAB example: https://www.mathworks.com/help/matlab/ref/fft.html) and my code is as following:
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1500; % Length of signal
t = (0:L-1)*T; % Time vector
%Form a signal containing a 50 Hz sinusoid of amplitude 0.7 and a 120 Hz sinusoid of amplitude 1.
S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
%Corrupt the signal with zero-mean white noise with a variance of 4.
y = S + 2*randn(size(t));
%Auto correlation using matlab function:
[cor lag] = xcorr(y,y);
figure;
plot(lag(floor(length(cor)/2)+1:end),cor(floor(length(cor)/2)+1:end));
title('Auto Correlation')
% PSD
fy = fft(y);
nf = length(fy);
p2y = 1/(nf*Fs)*(abs(fy).^2);
p1y = p2y(1:nf/2+1);
p1y(2:end-1) = 2*p1y(2:end-1);
freqs = 0:Fs/nf:Fs/2;
figure;plot(freqs,p1y)
title('Power spectral density')
% PSD using the inverse fourier transform:
invCorr = abs(ifft(p2y));
figure;plot(invCorr);title('Estimated Auto Correlation from PSD')
~~~~~~~~~~~~~~ Results :
PSD:

AC from xcorr:

AC from PSD:

0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Spectral Estimation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!