Short Fourier transform in python

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)
    #wyn = scipy.array([scipy.fft(w*data[i:i+dos])
        #for i in range(0, len(data)-dos, 1)])
    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 #sampling frequency
do=0.05 #window size
hop = 5

wyn=stft(data,cp,do,hop)
print len(wyn)
for i in range(0, len(wyn), 1):
    print wyn[i]
+5
source share
1 answer

FT -, 0-. () fs ( ) . FFT , (FT ) , .

scipy FFT [0, fs]. ( ) , [-fs/2, fs/2] - fftshift . , , FFT.

scipy.fftpack.fft:

"": A = fft (a, n), A [0] , A [1: n/2 + 1] , A [n/2 + 1:] - . , 8- [0, 1, 2, 3, 4, -3, -2, -1].

+5

All Articles