简体   繁体   English

FFT后如何获得原始声音?

[英]How to get original sound after FFT?

I am applying a FFT to my sound like this:我正在对我的声音应用 FFT,如下所示:

from scipy.fft import fft

samplerate, data = wavfile.read('./sound.wav')
fft_sound = fft(data)

Is there a reversal method which I can use to go from fft_sound back to data ?有没有可以用来从fft_sound返回到data的反转方法?

Here's what I did:这是我所做的:

samplerate, data = wavfile.read('./StarWars3.wav')

print(data)
print(ifft(fft(data)))

But the outcome looks completely different:但结果看起来完全不同:

[    0     0     0 ... -1502    26   414]
[ 0.00000000e+00-1.17911210e-13j -6.75789623e-13-4.22368515e-14j
  0.00000000e+00+7.03947524e-14j ... -1.50200000e+03-5.15824216e-14j
  2.60000000e+01+3.23030463e-13j  4.14000000e+02+9.36792340e-13j]

Did I use it correctly?我是否正确使用它?

Is there a reversal method which I can use to go from fft_sound back to data ?有没有可以用来从fft_sound返回到data的反转方法?

Yes, it's called inverse discrete Fourier transform .是的,它被称为逆离散傅立叶变换

Just like the fft function, SciPy has a function for it;就像fft函数一样,SciPy 也有一个函数; unsurprisingly named ifft . ifft命名为ifft

Did I use it correctly?我是否正确使用它?

It returns a complex-valued array, where the j suffix denotes the imaginary part (see Complex numbers in python and https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex ).它返回一个复数值数组,其中j后缀表示虚部(请参阅python 中的复数https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex )。

As its documentation says,正如其文档所说,

[...] ifft(fft(x)) == x to within numerical accuracy. [...] ifft(fft(x)) == x在数值精度范围内。

The outcome is shown in scientific notation, so it looks different but numerically it is very close:结果以科学记数法显示,因此看起来不同,但在数字上非常接近:

  • -1502 became -1.50200000e+03-5.15824216e-14j (real part is -1.50200000e+03 , which is -1502; imaginary part is -5.15824216e-14 , which is very close to 0) -1502变成了-1.50200000e+03-5.15824216e-14j (实部是-1.50200000e+03 ,即 -1502;虚部是-5.15824216e-14 ,非常接近于 0)

  • 26 became 2.60000000e+01+3.23030463e-13j (real part is 2.60000000e+01 , which is 26; imaginary part is 3.23030463e-13 , which is very close to 0) 26变成了2.60000000e+01+3.23030463e-13j (实部是2.60000000e+01 ,即 26;虚部是3.23030463e-13 ,非常接近于 0)

etc.等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM