[PD] help with rfft~

Georg Holzmann grhPD at gmx.at
Tue Nov 29 12:25:25 CET 2005


>> well, the output of a fft (or rfft) are complex numbers - the left 
>> output is the real part, right the imaginary part.
>> And as you can represent complex numbers with cos + sin - you have the 
>> representation from above.
>> If you want the amplitude+phase you have to convert these numbers from 
>> rectangular to polar coordinates.
> But you can represent any sinusoid as above, not just complex ones.
of course - I meant the output of fft are complex numbers

> There is probably some nifty trignometric relation that quickly solves:
> Rsin(2 pi f t + arctan(B/A))=Asin(2 pi f t)+Bcos(2 pi f t)

the relation is easy:
from fft or rfft you get for each bin a complex number, let's say (a + 
b*i) - so a is the left outlet, b the right one ...
if you want polar notation:
magnitude = r = sqrt(a^2+b^2)
phase = phi = arctan2(a/b)

(a+b*i) = r*e^(i*phi) = r*(cos(phi) + i*sin(phi))
and you have r and phi now ...

> So which is better for convolution: polar or rectangular? Some 
> processing must happen for convolution, because just multiplying the 
> real outputs of two rfft~ objects and the two complex outputs makes for 
> very poor convolution. Do most convolution tools (PD or otherwise) 
you cannot simply multiply the real and the imaginary part, because 
thats wrong:
(a1 + b1*i)*(a2 + b2*i) = a1*a2 - b1*b2 + (a1*b2 + a2*b1)*i
or in polar form:
r1*e^(i*phi1) * r2*e^(i*phi2) = ...

> convert to polar, multiply the frequencies, divide by niquist (I have no 
you don't have to divide by nyquist, you have to divide by the 
blocksize, only to normalize it ...
and you will also need a window (hanning or so) for your signal, if you 
want to avoid artifacts ...


More information about the Pd-list mailing list