0

I try to design a simple tool to analysis frequency from wav file. Here is the simple example I try:

import numpy as np
import wavio
from matplotlib import pyplot as plt
from scipy.fft import fft

input_wav_path = "song.wav"

signal = wavio.read(input_wav_path)

X = fft(signal.data)

sr = signal.rate
N = len(X)
n = np.arange(N)
T = N / sr
freq = n / T

plt.figure()
plt.plot(freq, np.abs(X))
plt.xlabel('Freq (Hz)')
plt.ylabel('FFT Amplitude |X(freq)|')
plt.show()

Here is the wav file I use:

I compare the result to the Frequency analysys in Audacity. In Audacity :

enter image description here

And in my tool:

enter image description here

Here is the file I use: http://sendanywhe.re/5YPATLC1

Why the FFT in my tool and Audacity are so different ?

dev dev
  • 109
  • 15
  • 1
    There's probably many things at play here, but one obvious one is that your Audacity plot is on a logarithmic scale (see the decibels on the vertical axis), while your self-made plot is on an ordinary linear scale. – gspr Sep 12 '22 at 11:36
  • I’m voting to close this question because it's not a programming question, but rather one about signal processing and/or mathematics. – gspr Sep 12 '22 at 11:44
  • 2
    Like @gspr mentionned there are a few things at play (log scale, Audacity uses frequency averaging on windows of size 128 while you do an FFT of your whole signal, etc). Your question can be answered, but please ask at : https://dsp.stackexchange.com/ – Jdip Sep 12 '22 at 16:48

0 Answers0