[Numpy-discussion] Code Question
Saqib bin Sohail
Saqib.Sohail at colorado.edu
Sat Apr 15 13:42:02 CDT 2006
Thanks a lot for your detailed email, unfortunately both of the following
imports don't work
import Gnuplot
import fft as FFT
from numarray import *
I think I need Gnuplot package but what I can't understand is why, fft is not
being imported, do I need to install the NumPy package with special options to
install fft.
Quoting René Bastian <rbastian at free.fr>:
> Le Samedi 15 Avril 2006 17:50, Saqib bin Sohail a écrit :
> > 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.
>
> With the module Gnuplot.py you can plot arrays
>
> import Gnuplot
>
> g =Gnuplot.Gnuplot()
> g.plot(w) # w is an array
> raw_input("Enter")
> g.reset()
>
> I use numarray
>
> Some code :
> ----------------
>
> import fft as FFT
> from numarray import *
>
> T = arrayrange(0.0, 2*pi, 1.0/1000)
> a = sin(2*pi*440.0*T)
>
> r = FFT.fft(a)
> print r
> g.plot(r)
> raw_input("Enter")
> ....
> r = FFT.inverse_real_fft(a)
> r = FFT.real_fft(a)
> r = FFT.hermite_fft(a)
>
> g.reset()
> ----------------
>
>
> >
> > 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)
>
> Read the manual how to load a file of floats
> I think there is a mistake
>
> > /* 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)
>
> hmmm ...
>
> >
> > 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
> >
> >
> > -------------------------------------------------------
>
> --
> René Bastian
> http://pythoneon.musiques-rb.org "Musique en Python"
>
>
--
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