Python NumPy

编程入门 行业动态 更新时间:2024-10-15 22:30:24
本文介绍了Python NumPy-FFT和逆FFT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

因此,我一直在使用FFT,目前我正在尝试使用FFT从文件中获取声音波形(最终对其进行修改),然后将修改后的波形输出回文件中.我已经获得了声波的FFT,然后在其上使用了逆FFT函数,但是输出文件听起来根本不正确.我没有对波形进行任何滤波-我只是测试要获取频率数据,然后将其放回文件中-听起来应该一样,但是听起来却截然不同.有什么想法吗?

So I've been working with FFT, and I'm currently trying to get a sound waveform from a file with FFT, (modify it eventually), but then output that modified waveform back to a file. I've gotten the FFT of the soundwave and then used an inverse FFT function on it, but the output file doesn't sound right at all. I haven't done any filtering on the waveform - I'm just testing out getting the frequency data and then putting it back into a file - it should sound the same, but it sounds wildly different. Any ideas?

-编辑-

此后我一直在从事这个项目,但尚未获得理想的结果.输出的声音文件嘈杂(声音更大,并且原始文件中不存在额外的噪音),并且一个声道的声音泄漏到另一个声道(以前是静音的).输入的声音文件是立体声2声道文件,声音仅来自一个声道.这是我的代码:

I have since been working on this project a bit, but haven't yet gotten desired results. The outputted sound file is noisy (both more loud, as well as extra noise that wasn't present in the original file), and sound from one channel leaked into the other channel (which was previously silent). The input sound file is a stereo, 2-channel file with sound only coming from one channel. Here's my code:

import scipy import wave import struct import numpy import pylab from scipy.io import wavfile rate, data = wavfile.read('./TriLeftChannel.wav') filtereddata = numpy.fft.rfft(data, axis=0) print (data) filteredwrite = numpy.fft.irfft(filtereddata, axis=0) print (filteredwrite) wavfile.write('TestFiltered.wav', rate, filteredwrite)

我不太明白为什么这行不通...?

I don't quite see why this doesn't work...?

如果可以帮助解决问题,我已经压缩了问题.py文件和音频文件这里.

I've zipped up the problem .py file and audio file, if that can help solve the issue here.

推荐答案

>>> import numpy as np >>> a = np.vstack([np.ones(11), np.arange(11)]) # We have two channels along axis 0, the signals are along axis 1 >>> a array([[ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.], [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]]) >>> np.fft.irfft(np.fft.rfft(a, axis=1), axis=1) array([[ 1.1 , 1.1 , 1.1 , 1.1 , 1.1 , 1.1 , 1.1 , 1.1 , 1.1 , 1.1 ], [ 0.55 , 1.01836542, 2.51904294, 3.57565618, 4.86463721, 6.05 , 7.23536279, 8.52434382, 9.58095706, 11.08163458]]) # irfft returns an even number along axis=1, even though a was (2, 11) # When a is even along axis 1, we get a back after the irfft. >>> a = np.vstack([np.ones(10), np.arange(10)]) >>> np.fft.irfft(np.fft.rfft(a, axis=1), axis=1) array([[ 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00], [ 7.10542736e-16, 1.00000000e+00, 2.00000000e+00, 3.00000000e+00, 4.00000000e+00, 5.00000000e+00, 6.00000000e+00, 7.00000000e+00, 8.00000000e+00, 9.00000000e+00]]) # It seems like you signals are along axis 0, here is an example where the signals are on axis 0 >>> a = np.vstack([np.ones(10), np.arange(10)]).T >>> a array([[ 1., 0.], [ 1., 1.], [ 1., 2.], [ 1., 3.], [ 1., 4.], [ 1., 5.], [ 1., 6.], [ 1., 7.], [ 1., 8.], [ 1., 9.]]) >>> np.fft.irfft(np.fft.rfft(a, axis=0), axis=0) array([[ 1.00000000e+00, 7.10542736e-16], [ 1.00000000e+00, 1.00000000e+00], [ 1.00000000e+00, 2.00000000e+00], [ 1.00000000e+00, 3.00000000e+00], [ 1.00000000e+00, 4.00000000e+00], [ 1.00000000e+00, 5.00000000e+00], [ 1.00000000e+00, 6.00000000e+00], [ 1.00000000e+00, 7.00000000e+00], [ 1.00000000e+00, 8.00000000e+00], [ 1.00000000e+00, 9.00000000e+00]])

更多推荐

Python NumPy

本文发布于:2023-11-30 03:50:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648622.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Python   NumPy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!