在 MATLAB 中将 FFT 的幅度缩放为 2

Scaling amplitudes by two for the FFT in MATLAB

刚看了Mablab教程的例子,想研究一下FFT函数。 谁能告诉我最后一步,为什么 P1(2:end-1) = 2*P1(2:end-1)。在我看来,没有必要乘以2。

Fs = 1000;            % Sampling frequency
T = 1/Fs;             % Sampling period
L = 1000;             % Length of signal
t = (0:L-1)*T;        % Time vector

%--------
S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
%---------
X = S + 2*randn(size(t));
%---------
plot(1000*t(1:50),X(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('t (milliseconds)')
ylabel('X(t)')

Y = fft(X);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')

Y = fft(S);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);

plot(f,P1)
title('Single-Sided Amplitude Spectrum of S(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')

Matlab sample

乘以2的原因是fft返回的频谱关于直流分量是对称的。由于它们显示的是 single-sided 振幅谱,因此每个点的振幅都将加倍,以说明频谱 另一侧 上数据的贡献。例如,pi/4的single-sided振幅是pi/4的振幅加上-pi/4的振幅。

第一个样本被跳过,因为它是直流点,因此在频谱的两侧共享。

因此,例如,如果我们查看他们的示例信号的 fft,其中包含振幅为 0.7 的 50Hz 正弦波和振幅为 1 的 120Hz 正弦波。

Fs = 1000;            % Sampling frequency
T = 1/Fs;             % Sampling period
L = 1000;             % Length of signal
t = (0:L-1)*T;        % Time vector

S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);

% Compute the FFT
Y = fft(S);

% Compute the amplitudes
amplitude = abs(Y / L);

% Figure out the corresponding frequencies
f = Fs/L*[0:(L/2-1),-L/2:-1]

% Plot the result
plot(f, amplitude)

绘制此图时,您会发现它是对称的,原始输入幅度只能通过组合频谱两侧的幅度来实现。

他们所做的稍微更明确的版本如下,它对频谱的两半求和

P1(2:end-1) = P1(2:end-1) + P2((L/2+2):end);

但是由于根据定义光谱是对称的,因此选择简单地乘以 2。