[Numpy-discussion] Code Question

Saqib bin Sohail Saqib.Sohail at colorado.edu
Sat Apr 15 08:51:02 EDT 2006


Hi guys

I have never used python, but I wanted to compute FFT of audio files, I came
upon a page which had python code, so I installed Numpy but after beating the
bush for a few days, I have finally come in here to ask. After taking the FFT I
want to output it to a file and the use gnuplot to plot it.

When I instaled NumPy, and ran the tests, it seemed that all passed without a
problem. My input is a .dat file converted from .wav file by sox.

Here is the code which obviously doesn't work because it seems that changes
have occured since this code was written. (not my code, just from some website
where a guy had written on how to do things which i require)

import Numeric
import FFT
out_array=Numeric.array(out)
out_fft=FFT.fft(out)

offt=open('outfile_fft.dat','w')
for x in range(len(out_fft)/2):
    offt.write('%f %f\n'%(1.0*x/wtime,abs(out_fft[x].real)))


I do the following at the python prompt

import numarray
myFile = open('test.dat', 'r')
my_array = numarray.arra(myFile)

/* at this stage I wanted to see if it was correctly read */

print myArray
[1632837691 1701605485 1952535072 ...,  538976288  538976288  168632368]

it seems that these values do not correspond to the values in the file (but I
guess the array is considering these as ints when infact these are floats)

anyway the problem starts when i try to do fft, because I can't seem to find
module or how to invoke it,

the second problem is writing to the file, that code obviously doesn't work,
and in my search through various documentations, i found arrayrange() but
couldn't make it to work, call me stupid, but despite going through several
examples, i haven't been able to make the for loop worked in any case,

it would be very kind of someone if he could at least tell me what i am doing
wrong and reply a simple example so that I can modify my code or at least be
able to understand .

Thanks



--
Saqib bin Sohail
PhD ECE
University of Colorado at Boulder
Res: (303) 786 0636
http://ucsu.colorado.edu/~sohail/index.html




More information about the NumPy-Discussion mailing list