问题
我试图从一组从音频文件中获取的数据中删除一个频率。在
为了简化我的问题,我创建了下面的代码,它创建了一组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()
结果:(橙色为产生波,蓝色为原始波)
预期结果:
蓝色和橙色线条(原始和新创建的波浪)的值应该完全相同