Using fft() to calculate PSD.
2 次查看(过去 30 天)
显示 更早的评论
I used the code below perform spectral analysis of signal with known period of 4 s:
load lujan.dat
data_out.time = lujan(:,1);
data_out.disp = lujan(:,2);
Y = fft(data_out.disp,1000);
Y(1)=[];
NY = length(Y);
Pyy = abs(Y(1:floor(NY/2))).^2;
nyquist = 1/2;
f = (1:NY/2)/(NY/2)*nyquist;
plot(f,Pyy,'-b','LineWidth',3);
title('Power spectral density');
xlabel('Frequency (Hz)');
However the output graph shows a peak at 0.05 Hz which is not correct! IS there something obvious i'm doing wrong?
thanks
0 个评论
采纳的回答
Wayne King
2012-6-21
Are you sure the sampling frequency is 1 ? If so, how far off is the peak from where you expect it to be? Is it almost correct or way off? You also don't tell us how long the time series is, so we don't know why you are adding the length input argument to fft() . Your frequency increment of 1/NY (0.0025) is correct.
更多回答(1 个)
Wayne King
2012-6-21
Then your sampling frequency is specified incorrectly.
Fs = 1/0.2;
% here I'll create a signal just to show you
t = 0:1/Fs:12-1/Fs;
x = cos(2*pi*0.25*t)+randn(size(t));
Y = fft(x,256);
Pyy = abs(Y(1:floor(256/2)+1)).^2;
freq = 0:Fs/256:5/2;
plot(freq,10*log10(Pyy))
grid on
set(gca,'xtick',[0 0.25 0.5 1 1.5 2 2.5])
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!