这个混淆可能是由于你所引用的两个例子不同而产生的结果。请参阅下面的代码以获取本说明中的参考资料。
在第一个示例中,该图是频率范围内的功率谱(周期图)。请注意,在第一个曲线图中,周期图并未居中于0,这意味着频率范围似乎是奈奎斯特采样频率的两倍。正如在数学工具链接中提到的那样,为了避免这种混淆(图2),将周期图居中为0是很常见的做法。
对于第二个例子,采用相同的参数,原始图是具有不同归一化的傅立叶光谱的振幅,比第一个例子(图3)。使用Matlab完整频率排序的语法(如代码中所述),将这个看起来不同的fft结果转换为示例1的结果是微不足道的;在图4中复制了0中心周期图的相同结果。
因此,具体回答你的问题,在这两种情况下的频率范围是相同的,最大频率为奈奎斯特采样频率为:了解如何DFFT作品
f = fs/2*linspace(0,1,NFFT/2+1);
的关键(同样在Matlab中)的理解是,您只需将您的离散数据集投影到傅立叶空间,其中由matlab中的fft()函数返回的是每个频率分量的展开系数,以及给出系数(在Matlab中如例2):
f = [f(1:end-1) -fliplr(f(1,2:end))];
了解更多详细信息,请参见在DFT的维基百科页面: https://en.wikipedia.org/wiki/Discrete_Fourier_transform
这也可能有助于您拿FFT省略长度为2参数的功率
y = fft(x).
在这情况下,你会看到y中只有少数非零分量对应于你的输入信号的确切系数。数学工作页面声称以下作为使用或不使用此长度的动机:
“对变换长度使用两个幂来优化FFT算法,但实际上通常使用n的执行时间差别很小= m“。
%% First example:
% http://www.mathworks.com/help/matlab/math/fast-fourier-transform-fft.html
fs = 10; % Sample frequency (Hz)
t = 0:1/fs:10-1/fs; % 10 sec sample
x = (1.3)*sin(2*pi*15*t) ... % 15 Hz component
+ (1.7)*sin(2*pi*40*(t-2)); % 40 Hz component
% Removed the noise
m = length(x); % Window length
n = pow2(nextpow2(m)); % Transform length
y = fft(x,n); % DFT
f = (0:n-1)*(fs/n); % Frequency range
power = y.*conj(y)/n; % Power of the DFT
subplot(2,2,1)
plot(f,power,'-o')
xlabel('Frequency (Hz)')
ylabel('Power')
title('{\bf Periodogram}')
y0 = fftshift(y); % Rearrange y values
f0 = (-n/2:n/2-1)*(fs/n); % 0-centered frequency range
power0 = y0.*conj(y0)/n; % 0-centered power
subplot(2,2,2)
plot(f0,power0,'-o')
% plot(f0,sqrt_power0,'-o')
xlabel('Frequency (Hz)')
ylabel('Power')
title('{\bf 0-Centered Periodogram} Ex. 1')
%% Second example:
% http://stackoverflow.com/questions/10758315/understanding-matlab-fft-example
% Let's redefine the parameters for consistency between the two examples
Fs = fs; % Sampling frequency
% T = 1/Fs; % Sample time (not required)
L = m; % Length of signal
% t = (0:L-1)*T; % Time vector (as above)
% % Sum of a 3 Hz sinusoid and a 2 Hz sinusoid
% x = 0.7*sin(2*pi*3*t) + sin(2*pi*2*t); %(as above)
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
% NFFT == n (from above)
Y = fft(x,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
subplot(2,2,3)
plot(f,2*abs(Y(1:NFFT/2+1)),'-o')
title('Single-Sided Amplitude Spectrum of y(t)')
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
% Get the 0-Centered Periodogram using the parameters of the second example
f = [f(1:end-1) -fliplr(f(1,2:end))]; % This is the frequency ordering used
% by the full fft in Matlab
power = (Y*L).*conj(Y*L)/NFFT;
% Rearrange for nicer plot
ToPlot = [f; power]; [~,ind] = sort(f);
ToPlot = ToPlot(:,ind);
subplot(2,2,4)
plot(ToPlot(1,:),ToPlot(2,:),'-o')
xlabel('Frequency (Hz)')
ylabel('Power')
title('{\bf 0-Centered Periodogram} Ex. 2')
亲爱的PZwan,谢谢。其实这是一个完整的答案和一个非常有用的代码来理解你的解释和matlab的DFT和fft的一般事情。 – Gohann
亲爱的Gohann,这是我的荣幸。我很高兴这对你有帮助。 – PZwan