在窗口FFT后缩放幅度以恢复正确的幅度

时间:2014-12-02 22:49:20

标签: python numpy signal-processing fft

我正在尝试将Hann窗口应用于正弦信号,其想法是应用FFT来恢复频率和幅度。这是我创建的规范案例,以便在我移动数据之前增加我的理解(实时信号,我想准确地确定频率内容和幅度)。在下面的代码中,我需要乘以2.0的额外因子来恢复振幅。我理解乘以2 / N但现在我乘以4 / N.有没有人遇到这个或任何人可以解释为什么这是?这是我的代码:

import numpy as np
import matplotlib.pyplot as plt

# first create the time signal, which has two frequencies 13.2 hz and 43.9 hz
f_s = 100.0 # Hz  sampling frequency
f = 1.0 # Hz
time = np.arange(0.0, 10.0, 1/f_s)
x = 5 * np.sin(13.2 * 2 * np.pi * f * time) + 3 * np.sin(43.9 * 2 * np.pi * f * time)
x = x + np.random.randn(len(time)) #inject some noise

# apply hann window and take the FFT
win = np.hanning(len(x))
FFT = np.fft.fft(win * x) * 2.0  # IT SEEMS I NEED AN ADDITIONAL FACTOR OF 2 TO RECOVER THE AMPLITUDES
n = len(FFT)
freq_hanned = np.fft.fftfreq(n, 1/f_s)  
half_n = np.ceil(n/2.0)
fft_hanned_half = (2.0 / n) * FFT[:half_n]
freq_hanned_half = freq_hanned[:half_n]

# and plot
plt.plot(freq_hanned_half, np.abs(fft_hanned_half))
plt.xlabel("Frequency (Hz)")
plt.ylabel("Amplitude")

1 个答案:

答案 0 :(得分:1)

von Hann窗口的平均值是(大约)0.5,对于N=1000你有

>>> N=1000 ; print sum(np.hanning(N))/N
0.4995
>>> 

这是否解释了乘以2来恢复离散振幅的必要性?