Python NumPy - FFT and Inverse FFT?

2024/9/30 1:35:48

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.

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 pylabfrom scipy.io import wavfilerate, 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.

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

Answer
  1. You don't appear to be applying any filter here
  2. You probably want to take the ifft of the fft (post-filtering), not of the input waveform.
https://en.xdnf.cn/q/71146.html

Related Q&A

Tools to help developers reading class hierarchy faster

I mostly spend time on Python/Django and Objective-C/CocoaTouch and js/jQuery in the course of my daily work.My editor of choice is vim for Python/Django and js/jQuery and xcode for Objective-C/CocoaTo…

Python Last Iteration in For Loop [duplicate]

This question already has answers here:What is the pythonic way to detect the last element in a for loop?(34 answers)How do I read and write CSV files?(7 answers)Closed 9 months ago.Is there any simp…

Django 1.7 multisite User model

I want to serve a Django application that serves multiple web sites by single database but different user sets. Think like a blog application, it will be used by several domains with different themes, …

Does for key in dict in python always iterate in a fixed order?

Does the python codefor key in dict:..., where dict is a dict data type, always iterate in a fixed order with regrard to key? For example, suppose dict={"aaa":1,"bbb",2}, will the …

Kinesis Firehose lambda transformation

I have the following lambda function as part of Kinesis firehose record transformation which transforms msgpack record from the kinesis input stream to json.Lambda Runtime: python 3.6from __future__ im…

Python: find out whether a list of integers is coherent

I am trying to find out whether a list of integers is coherent or at one stretch, meaning that the difference between two neighboring elements must be exactly one and that the numbers must be increasin…

Create resizable/multiline Tkinter/ttk Labels with word wrap

Is it possible to create a multi-line label with word wrap that resizes in sync with the width of its parent? In other words the wordwrap behavior of Notepad as you change the width of the NotePad win…

Unicode, regular expressions and PyPy

I wrote a program to add (limited) unicode support to Python regexes, and while its working fine on CPython 2.5.2 its not working on PyPy (1.5.0-alpha0 1.8.0, implementing Python 2.7.1 2.7.2), both run…

Python str object has no attribute read

Python 3.3.2 import json & urllib.requestJson[{"link":"www.google.com","orderid":"100000222"}, {"link":"www.google.com","orderid&quo…

Efficient upsert of pandas dataframe to MS SQL Server using pyodbc

Im trying to upsert a pandas dataframe to a MS SQL Server using pyodbc. Ive used a similar approach before to do straight inserts, but the solution Ive tried this time is incredibly slow. Is there a mo…