我在 Matlab 上使用 FFT 计算信号频谱时遗漏了一些东西。我的代码:
%% compute the spectrum of the data (data(t))
L = length(time); % length of the sample
NFFT = 2^(nextpow2(L)-1); % Next power of 2 from length of y
Y = fft(data,NFFT);%/NFFT;%L;
Fs = 1/(mean(time(2:end)-time(1:end-1))); % compute the sampling frequency
f = Fs/2*linspace(0,1,NFFT/2+1);
loglog(f,2*abs(Y(1:NFFT/2+1)))
title('Single-Sided Amplitude Spectrum of My Data')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
你能告诉我我在哪里搞砸了吗?
我试图检查算法是否使用这两个相同信号的采样(相同的采样频率;在两个不同的时间范围 0-10 和 0-100)上工作:
fs=1000;
time10 = [0:1/fs:10];
time100 = [0:1/fs:100];
data10 = sin(2*pi*0.23 .*time10)+cos(2*pi*12 .*time10);
data100 = sin(2*pi*0.23 .*time100)+cos(2*pi*12 .*time100);
我猜这两个频谱应该是 supperpose 但他们不...如此处所示:https ://www.dropbox.com/s/wfols9o409pr94u/FFT_spectrum_StackOverflow.png?dl=0 https://www.dropbox.com/ s/a8vmzwto6x4130w/FFT_spectrum_StackOverflow.fig?dl=0
谢谢