I want to get the frequency with maximum power for every moment in the wav file. So I wrote STFT in Python using fft from scipy. I used the Kaiser window function from scipy. Everything looks great, but my result looks strange. It has some very small numbers and some very high.
here is the output for one wav file: http://pastebin.com/5Ryd2uXj
and here is the code in python:
import scipy, pylab
import wave
import struct
import sys
def stft(data, cp, do, hop):
dos = int(do*cp)
w = scipy.kaiser(dos,12) //12 is very high for kaiser window
temp=[]
wyn=[]
for i in range(0, len(data)-dos, hop):
temp=scipy.fft(w*data[i:i+dos])
max=-1
for j in range(0, len(temp),1):
licz=temp[j].real**2+temp[j].imag**2
if( licz>max ):
max = licz
maxj = j
wyn.append(maxj)
return wyn
file = wave.open(sys.argv[1])
bity = file.readframes(file.getnframes())
data=struct.unpack('{n}h'.format(n=file.getnframes()), bity)
file.close()
cp=44100
do=0.05
hop = 5
wyn=stft(data,cp,do,hop)
print len(wyn)
for i in range(0, len(wyn), 1):
print wyn[i]
source
share