different way to compute power spectral density
5 次查看(过去 30 天)
显示 更早的评论
Dear everyone,
I am writing a piece of code to compute power spectral density estimate of a signal and wanted to compare two approaches :
- compute the FFT of the signal and square its amplitude
- compute the biased Autocorrelation function and take the FFT
I expected the two methods to give a similar result, however for the second one the Parseval sum in frequency space is wrong.
% Define spatial signal
dx = 1e-3;
Fsx = 1/dx; % sampling frequency
X = 0:dx:2;
L = length(X); % = 2001
Lfft = 2^nextpow2(L); % = 2048
dfx = 1/(Lfft*dx);
T = 0.1;
Z = sin(2*pi*X/T);
% Compute PSD from FFT
fourier_image = fftshift(fft(X,Lfft)/Lfft);
PSDfromFFT = abs(fourier_image).^2;
freq = -Fsx/2:dfx:Fsx/2-dfx; % Frequency axis
% Compute PSD from Autocorrelation
Rxx = xcorr(X,'biased');
lag = (-(L-1):1:(L-1))*dx;
PSDfromRxx = abs(fftshift(fft(Rxx,Lfft)/Lfft));
% Parseval sums
fprintf('\nParseval sums : \n\n');
fprintf('Spatial sum = %f\n', sum(X(:).^2));
fprintf('Frequency sum (from FFT) = %f\n', sum(PSDfromFFT(:))*Lfft);
fprintf('Frequency sum (from ACF) = %f\n', sum(PSDfromRxx(:))*Lfft);
% Plots
figure;
subplot(2,1,1); plot(X,Z,'-b'); title('Signal z(x)');
subplot(2,1,2); plot(lag,Rxx,'-r'); title('Autocorrelation');
figure;
plot(freq,PSDfromFFT,'-or'); title('PSD based on FFT'); hold on;
plot(freq, PSDfromRxx, '-ob'); title('PSD based on autocorrelation');
legend('PSD based on FFT','PSD based on autocorrelation'); hold off;
I get the following result for the Parseval sums :
Parseval sums :
Spatial sum = 2668.667000
Frequency sum (from FFT) = 2668.667000
Frequency sum (from ACF) = 7853.268426
So the first method is ok but there is a factor of ~3 for the second one, and I cannot figure out what is the problem. Note that I scale the fft with 1/N which is a convention for the project I'm working on.
Thanks in advance for the inputs
2 个评论
Soumak Bhattacharjee
2019-11-28
Has this isuue been resolved? What was the problem?
I tried to calculate energy density from auto-correlation and faced the same problem.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!