I need to take a .wav audio file that's noisy and filter out some noise. I have to do it using Fourier Transform. After some days researching and experimenting, I finally made a working function, the problem is that it doesn't work as I intend it to. Here is the function I made:

# Audio signal processing
from scipy.io.wavfile import read, write
import matplotlib.pyplot as plt
import numpy as np
from scipy.fft import fft, fftfreq, ifft

def AudioSignalProcessing(audio):

    # Import the .wav format audio into two variables: 
    # sampling (int)
    # audio signal (numpy array)
    sampling, signal = read(audio)
    # time duration of the audio
    length = signal.shape[0] / sampling

    # x axis based on the time duration
    time = np.linspace(0., length, signal.shape[0])
    # show original signal
    plt.plot(time, signal)
    plt.xlabel("Time (s)")
    plt.title("Original signal")

    # apply Fourier transform and normalize
    transform = fft(signal)
    # obtain frequencies
    xf = fftfreq(transform.size, 1/sampling) 
    # show transformed signal (frequencies domain)
    plt.plot(xf, abs(transform)/np.linalg.norm(transform))
    plt.xlabel("Frecuency (Hz)")
    plt.title("Frequency domain signal")

    # filter the transformed signal to a 40% of its maximum amplitude
    threshold = np.amax(transform)*0.4
    filtered = np.copy(transform)
    filtered[abs(transform) < 0.4 * max(abs(transform))] = 0
    # show filtered transformed signal
    plt.xlabel("Frecuency (Hz)")
    plt.title("FILTERED time domain signal")
    # transform the signal back to the time domain
    filtered = ifft(filtered)
    # show original signal filtered
    plt.plot(time, filtered)
    plt.xlabel("Time (s)")
    plt.title("Filtered signal")
    # convert audio signal to .wav format audio
    # write(audio.replace(".wav", " filtrado.wav"), sampling, filtrada.astype(signal.dtype))
    return None


The output plots are these:


When I listen to the filtered audio, it doesn't sound good. The voice that's talking seems like it's in another room.

I've read some related questions here and maybe it's not a code problem but a "theoretical" problem.

  • $\begingroup$ Well you can see from the spectrum that you've removed a lot of high frequency content, so it will sound filtered, too. Can you just lower the threshold? $\endgroup$
    – endolith
    Commented Mar 14, 2022 at 0:44
  • 2
    $\begingroup$ You do a lot of damage to your signal and of course it sounds bad. What type of analysis and research have you done that led you to this algorithm? Why do you think this should work ? $\endgroup$
    – Hilmar
    Commented Mar 14, 2022 at 6:57
  • $\begingroup$ @Hilmar well this class is very vague si they taught me basically that the FFT exists and how to use python, though the rest I had to learn it myself. Anyway, I couldn't go any further for this homework. $\endgroup$
    – Isaac
    Commented Mar 15, 2022 at 3:06
  • $\begingroup$ @endolith I did that and I guess I have to adjust it to every audio file I use, as I said one comment above, this should be enough for this homework. Thanks for the answer $\endgroup$
    – Isaac
    Commented Mar 15, 2022 at 3:07

1 Answer 1


I've heard that some sounds in most languages use some very high and low pitched frequencies, so it would make sense it doesn't sound complete after those frequencies are removed. Getting rid of the noise without compromising heavily is probably more complicated than cropping the frequencies.

  • $\begingroup$ Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. $\endgroup$
    – ZaellixA
    Commented Sep 26, 2023 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.