[pd] FFT sine to saw oscilator (was:[pd] hanning window + fft)

Charles Henry czhenry at gmail.com
Tue Sep 5 20:35:15 CEST 2006


to use the ifft for synthesis, you need to know the amplitude and
phase for each frequency, and you need to express it as a complex
number.

z=a+b*i, a=Amp*cos(phase)  and b=Amp*sin(phase)

fft~ gives two outlets, the left is the real part of the fourier
transform, the right is the imaginary part.
next thing is, the second half of your fourier coefficients are
complex conjugates of your first half (when dealing with real-valued
signals) according to the following pattern

F(0) is real (the imaginary part is zero) and so is F(N/2)
F(1)=F(N-1)*   where * denotes conjugate
F(2)=F(N-2)*
...
F(N/2-1)=F(N/2+1)*

for a block size of 64,
you've got 33 distinct real values (0 to N/2)
and 31 distinct imaginary values (1 to N/2-1)
to calculate before packing them all up into signals

and there's some limitations.  To do things cleanly all of your
frequencies need to be ingeter multiples of (sampling freq. fs/ N),
the lowest frequency you can achieve with Fourier series on N points

Luckily, your sawtooth and square waves are made up of frequencies in
just this way.  But you're still limited to JUST the frequencies in
your fourier transform (fs/N, 2*fs/N, 3*fs/N, ..., N/2 * fs/N)

It's probably not the best way to do it, for what you're describing.
You want to be able to continuously mix different levels of your saw,
sine and squares as a function of time, right?
I think you'll have better luck by just sync'ing up a phasor~ and an
osc~, and creating your square wave (in phase) by using >~ and <~ on
osc~ and summing the outputs together like
[osc~]
|     \
[>~][<~]
|      |
|      [*~] [sig~ -1]
|      |
[+~]
output square wave

then just mix your signals together.

Chuck




More information about the Pd-list mailing list