0

I've been getting really confused with FFT in python. What I'm trying to do is plot the FFT of the note number 61 (or middle C#). Here is the code that I tried to use which I found here using this wav file. After running that code, I got this output after zooming in a bit.

output

I think that this is completely wrong due to the fact that after looking online, the note number 61 has a frequency of 277.2hz. This means that there should be a peak around that value right? But to me, it seems like that the values are completely off. This is the code that I'm running right now to get the plot.

import matplotlib.pyplot as plt
from scipy.fftpack import fft
from scipy.io import wavfile # get the api
fs, data = wavfile.read("MAPS_ISOL_NO_P_S0_M61_AkPnBsdf.wav") # load the data
a = data.T[0] # this is a two channel soundtrack, I get the first track
b=[(ele/2**8.)*2-1 for ele in a] # this is 8-bit track, b is now normalized on [-1,1)
c = fft(b) # create a list of complex number
d = len(c)/2  # you only need half of the fft list
plt.plot(abs(c[:(d-1)]),'r') 
plt.xlabel('Frequency')
plt.ylabel('Magnitude')
plt.show()

I'm also not sure if I have the axis labeled correctly for the x and y axis as I believe each entry in the array is a bin of size Fs / N where Fs is the sample rate and N is the size of the FFT? I'm just really confused and overwhelmed after looking online for weeks about all this. Thanks for any help!

Steven T
  • 83
  • 9
  • are you using numpy or scipy fft? You should show your imports too. – Ignacio Vergara Kausel Nov 16 '17 at 09:38
  • 1
    Your X axis looks like bin indices rather than frequencies to me ? – Paul R Nov 16 '17 at 10:03
  • 1
    Indeed as @PaulR mentions, in your line `plt.plot(abs(c[:(d-1)]),'r') ` you provide just one array, meaning that the X axis will be assumed to be the index and not frequency. – Ignacio Vergara Kausel Nov 16 '17 at 10:11
  • 2
    See [this question](https://stackoverflow.com/a/4371627/253056) for an explanation of the relationship between FFT bin index and frequency. – Paul R Nov 16 '17 at 10:26
  • Right I mentioned I wasn't sure if it was bins or frequencies so that confirmed it for me. How would I go about converting the bin indicies to frequencies? I also added the packages I imported. – Steven T Nov 16 '17 at 18:36

0 Answers0