我正在尝试从音频文件获得的一组数据中删除频率。
为了简化我的问题,我创建了下面的代码,该代码创建了一组wave,并将它们合并为一个复杂的wave。然后找到该复杂波的傅立叶变换并将其逆。
我希望看到原始波形,因为应该没有数据丢失,但是我收到的波形却截然不同。
import numpy as np
import matplotlib.pyplot as plt
import random
#Get plots
fig, c1 = plt.subplots()
c2 = c1.twinx()
fs = 100 # sample rate
f_list = [5,10,15,20,100] # the frequency of the signal
x = np.arange(fs) # the points on the x axis for plotting
# compute the value (amplitude) of the sin wave for each sample
wave = []
for f in f_list:
wave.append(list(np.sin(2*np.pi*f * (x/fs))))
#Adds the sine waves together into a single complex wave
wave4 = []
for i in range(len(wave[0])):
data = 0
for ii in range(len(wave)):
data += wave[ii][i]
wave4.append(data)
#Get frequencies from complex wave
fft = np.fft.rfft(wave4)
fft = np.abs(fft)
#Note: Here I will add some code to remove specific frequencies
#Get complex wave from frequencies
waveV2 = np.fft.irfft(fft)
#Plot the complex waves, should be the same
c1.plot(wave4, color="orange")
c1.plot(waveV2)
plt.show()
蓝色和橙色线(创建的原始波浪和新波浪)的值应该完全相同
答案 0 :(得分:1)
在进行逆FFT之前,请获取FFT的绝对值。那会改变事情,可能是造成问题的原因。