On 11/1/07, Ray S <subscriber100@rjs.org> wrote:
At 09:00 AM 11/1/2007, Chuck wrote:

In Python, collections.deque makes a pretty good circular buffer.
Numpy will
make an array out of it, which involves a copy, but it might be
better than what you are doing now.

hmmm, I'll think more about that - and the copy is only at program
start, it seems
the fft can always be fft(d[:-N])
>>> from collections import deque
>>> import numpy as N
>>> d = deque( N.zeros(10,))
>>> d.extend(N.ones(4,))
>>> d
deque([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0,
1.0, 1.0])
>>> [d.pop() for i in range(4)]
[1.0, 1.0, 1.0, 1.0 ]

Yeah, I noticed that  inconvenience.

>>> d
deque([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])

An additional complication is that I pass the numpy (or Numeric)
array address to the ctypes library call so that the data is placed
directly into the array from the call. I use the if/else end wrap
logic to determine whether I need to do a split and copy if the new
data wraps.

OK. Hmm, I wonder if you would lose much by taking a straight forward radix-2 fft and teaching it to use modular indices? Probably not worth the trouble, but an fft tailored to a  ring buffer might be useful for other things. Probably the easiest thing is to just copy the ring buffer out into a linear array.

Chuck