- Hey all,

Well, I've got some code that generates some fake data and

runs the FFT on it to produce a spectogram, but I need some

help.

The good news is that even with the FFT it still runs quite

quickly. The bad news is that it doesn't show what it ought

to be showing.

What I tried to do was create 10 seconds of fake data,

simulating "pure" brainwaves (such as a steady 6Hz for

theta), as well as some contrived mixtures. Then, I

ran an FFT on them to get the spectrogram.

The output bears some resemblance to what I wanted, but

it's grossly distorted, and I'm not sure what's wrong.

I think the code *MIGHT* be working fine except that it's

using the wrong scale for the "bins", because it looks like

it might be right, except it's all squished into the top

bars and there seems to be a lot of noise. The code is

short, so the bugs can't be in too many places... :)

Can someone take a look? The new code is here:

http://cvs.sabren.com/sixthdev/cvsweb.cgi/openeeg/proto.py?rev=1.2

I used this article on analyzing sound files with

python as my gude, so it might help:

http://www.onlamp.com/pub/a/python/2001/01/31/numerically.html

The dislin package uses for plotting is free, cross-platform

and very quick, btw... Maybe it's possible to use it for an

oscilliscope display? Or even a better spectrogram. By default,

though, it pops up its own window. Maybe there's some way to

just generate the graph to a sprite and blit it onto the screen

ourselves as we animate?

Anyway, if someone with DSP skill can help me figure out

what's wrong with my code, that would really be great!

[Even if you don't know python, the code should be pretty

straightforward]

Thanks,

- Michal http://www.sabren.net/ sabren@...

------------------------------------------------------------

Switch to Cornerhost! http://www.cornerhost.com/

High Powered Hosting - With a Human Touch. :)

------------------------------------------------------------ - On Mon, 17 Jun 2002, larryjanow wrote:

> --- In buildcheapeeg@y..., Jim Peters <jim@u...> wrote:

Larry: I was wondering how I'd figure out amplitude. Thanks! :)

>

> > If real_fft is returning 33 values from a 64-sample input, then it

> > seems to me that it must be returning complex numbers. If so, then

> > the abs() function should automatically do the square root you

> > mention (i.e. sqrt(r*r+i*i)).

> >

> > Perhaps this needs checking. However, obviously the Python

> > FFT.real_fft is not returning the imaginary parts as real numbers

> > in the places you are expecting it to, so your method won't work in

> > this particular case, and is based on some other FFT algorithm's output

> > layout.

>

> I made my comments based on Michal's statement about discarding the

> imaginary bins and just using the real ones. While my example might

> not work for his FFT's output format, the method is still valid:

> a=sqrt(r*r+i*i)/(N/2). If the compiler or library handles this (I

> know nothing about Python...), that is cool!

Here's the deal. The FFT module has several functions avaliable:

http://pfdubois.com/numpy/doc/FFT/FFT.py.html

I used real_fft because the sound processing in python

article said the real and imaginary parts would be mirror

images. I didn't check that assertion or try to see if it

worked in my case. I just chopped it off and saw that the

right thing seemed to be happening. But there's a plain

fft() function that returns a list of the same length as the

input.

I should say that complex numbers are a primitive type in

python, so the fft() function returns an array of complex

numbers, and you can take the .imaginary attribute or the

.real attribute to get an array with only the axis you want.

I've got some work-related stuff I need to get done today,

but I should have some time to play around with this

tomorrow.

If anyone wants to tak a look in the meantime, be my guest.

Cheers,

- Michal http://www.sabren.net/ sabren@...

------------------------------------------------------------

Switch to Cornerhost! http://www.cornerhost.com/

High Powered Hosting - With a Human Touch. :)

------------------------------------------------------------