[Numpy-discussion] Code Question

Saqib bin Sohail Saqib.Sohail at colorado.edu
Sun Apr 16 14:02:04 CDT 2006


Thanks Guys for all your prompt responses. I have tried to use the provided
solutions but I am had my share of issues mixed with my lack of knowledge to
the point that I feel quite embarrassed to bother you guys.

Issue 1

I am running FC 3 with native python-2.3 and then I installed python-2.4 in it.
numarray-1.5.1 seems to have installed with success in python-2.3. I have tried
to install numpy-0.9.6-1.i586.rpm but I don't have python-base and when I try
to install python-base I get a long list of dependency lists which I need. I
haven't further pursued down that line, unfortunately I haven't been able to
use numarray, I don't know how to use it because ppl have repeatedly told me to
use numpy but I can't seem to get that installed.

Issue 2

To input the file, Ryan suggested to use scipy, I don't want to go down that
path, if only there is a simple way to input the file, (i can clean up the file
and format it in the right way in perl, I can do that in a heartbeat)

Issue 3

I don't want to use gnuplot functionality, or mathplot, if only I am able to
write the file then again I can use perl to format it and use gnuplot then,


So if there is the simplest of ways in which I can just
i) read the file (formatting will be done in perl)
ii) get the fft
iii) write the file or files (and then use perl to format for gnuplot)

I am sure all of you will say why not use the existing functionalities, but
after 3 days I haven't gotten anywhere. All I need to do is get FFT of some
sound files so that I can verify the result of FFT's and compare them with my
FFT code in VxWorks.



An Pierre, I started reading diveintopython.pdf but got nowhere when I tried
two of its examples, the attached image shows that when I tried to run one of
the examples on python-2.3 and the output wasn't according to what the guide
suggested. (no output to be precise)

http://jobim.colorado.edu/~sohail/pythonExample.JPG

Thanks again guys.

Quoting Ryan Krauss <ryanlists at gmail.com>:

> I guess it depends on how much you want to learn and what you want to do.
>
> I was able to load your data using
> data=scipy.io.read_array('monkey.dat')
>
> I had to comment out the first line to make it work.  I couldn't make
> the fromfile method of numpy work because the data is actually fixed
> width.
>
> If you don't want to install scipy, you would need to learn enough
> Python to read the file and clean it up a little by hand.
>
> It seems like the first column is time and the second is the signal
> you want to fft.  I was able to fft it with:
> myfft=numpy.fft(data[:,1])
> (I don't have the latest version of numpy and don't seem to have the
> refft function Robert mentioned).
>
> t=data[:,0]
> df=1/max(t)
> df
> maxf=8012
> fvect=arange(0,maxf+df,df)
>
> plot(fvect,abs(myfft))
>
> I am plotting using matplotlib and the resulting figures are attached.
>
> If you really want to learn python for scientific and plotting
> applications, I would highly recommend a few packages:
> SciPy - some additional capabilities beyond Numpy (optimization, ode's , ...)
> ipython - it is a really good interactive python shell
> matplotlib - the best python 2d plotting package I am aware of
>
> Let me know if you have any additional questions.  You can find out
> about each package by googling it.  They are all closely related to
> Numpy and all have good mailing lists to help you.
>
> Ryan
>
> On 4/15/06, Saqib bin Sohail <Saqib.Sohail at colorado.edu> wrote:
> > Do let me know if you get somewhere.
> >
> > Thanks
> >
> >
> > Quoting Ryan Krauss <ryanlists at gmail.com>:
> >
> > > email me the dat file and I could play with it a bit.  If I can read
> > > your input file, the rest should be easy.
> > >
> > > Ryan
> > >
> > > On 4/15/06, Saqib bin Sohail <Saqib.Sohail at colorado.edu> wrote:
> > > > 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
> > > >
> > > >
> > > > -------------------------------------------------------
> > > > This SF.Net email is sponsored by xPML, a groundbreaking scripting
> language
> > > > that extends applications into web and mobile media. Attend the live
> > > webcast
> > > > and join the prime developer group breaking into this new coding
> territory!
> > > >
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
> > > > _______________________________________________
> > > > Numpy-discussion mailing list
> > > > Numpy-discussion at lists.sourceforge.net
> > > > https://lists.sourceforge.net/lists/listinfo/numpy-discussion
> > > >
> > >
> >
> >
> > --
> > Saqib bin Sohail
> > PhD ECE
> > University of Colorado at Boulder
> > Res: (303) 786 0636
> > http://ucsu.colorado.edu/~sohail/index.html
> >
> >
>


--
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