【问题标题】:Scaling amplitudes by two for the FFT in MATLAB在 MATLAB 中将 FFT 的幅度缩放 2
【发布时间】:2017-01-23 13:46:04
【问题描述】:

我刚刚阅读了 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

【问题讨论】:

    标签: matlab signal-processing fft


    【解决方案1】:

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

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

    因此,例如,如果我们查看他们的示例信号的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。

    【讨论】:

    • 非常感谢。我现在可以理解了。 @Suever
    • @suever,您定义频率向量的方式是错误的。您可以从上传的图中看到,这两个峰位于400Hz aprox。这与预期的50Hz120Hz 完全不同。频率向量在matlab中被定义为f = Fs/L*[0:(L/2-1),-L/2:-1]
    • @lucianopaz 感谢您指出这一点!我太专注于幅度,以至于错过了频率标签。已更新。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-09
    • 2021-05-25
    • 2011-12-07
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多