输入信号以特定频率到达。我正在对此进行FFT,然后想要找到与该特定频率相对应的幅度。我不确定我是否朝着正确的方向前进?以下是我提出的两个功能:
def fft_v2(y, freq, fs=30000):
Ts = 1.0/fs; # sampling interval
t = np.arange(0,1,Ts) # time vector
n = len(y) # length of the signal
k = np.arange(n)
T = n/fs
frequency = k/T # two sides frequency range
frequency = frequency[range(n/2)] # one side frequency range
Y = np.fft.fft(y)/n # fft computing and normalization
Y = Y[range(n/2)]
amplitude = []
for fq,amp in zip(frequency, Y):
if fq == freq:
amplitude.append(max(abs(Y)))
print max(amplitude)
def fft(y, freq, fs=30000):
n = len(y) # Get the signal length
dt = 1/float(fs) # Get time resolution
fft_output = np.fft.rfft(y) # Perform real fft
rfreqs = np.fft.rfftfreq(n, dt) # Calculatel frequency bins
fft_mag = np.abs(fft_output) # Take only magnitude of spectrum
# Normalize the amplitude by number of bins and multiply by 2
# because we removed second half of spectrum above the Nyqist
# frequency and energy must be preserved
fft_mag = fft_mag * 2 / n
print np.array(fft_mag), np.array(rfreqs)
在第二个函数中,如何找到对应于特定频率的幅度?