Hi all,
I am reading Curtis Roads book "The Computer Music Tutorial" trying to understand fft. I get a little lost at times but I think I basically get it. Now how does this information match with the fft~ or rfft~ object in PD I wonder? The help for fft~ says (for that rfft~ at least) the left and right outputs can be considered as the coefficents of cosine and sine respectively. Does this mean that if frequency and phase of a sinusoid can br represented as A*sin(2*PI*f*t)+B*cos(2*PI*f*t), then the left output of fft~ is B and the right output is A? If so, how do I get frequency and phase? (My calculus book is back in Boulder) If I am going to convolve the two signals - multiply in the frequency domain - what happens to phase?
I know that I could open the convo-bros patch and copy/paste, but I would really rather understand the process and write my own patch from scratch.
Thank you for the help! -thewade PS: also, for bug reporting purposes: sometimes if I have a patch running and I open/edit/save an abstraction within that patch i can no longer close that bastraction as PD claims that there is no .X874598743 object (or some number). And feature requests: i would like to be able to decare default font size and level of dialogs in the .pdrc. For example whe I close a window I always get a dialog "are you sure you want to close this window". I would rather close the window and kick myself later for not saving, then get that dialog all the time. PD-devel from CVS
Hallo!
The help for fft~ says (for that rfft~ at least) the left and right outputs can be considered as the coefficents of cosine and sine respectively. Does this mean that if frequency and phase of a sinusoid can br represented as A*sin(2*PI*f*t)+B*cos(2*PI*f*t), then the left output of fft~ is B and the right output is A? If so, how do I get frequency and phase? (My calculus book is back in Boulder)
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.
If I am going to convolve the two signals - multiply in the frequency domain - what happens to phase?
convolution is a simply multiplication, but it's a multiplication of complex numbers ... (and it's of course different, when you use rectangular or polar representation)
LG Georg
Georg Holzmann wrote:
Hallo!
The help for fft~ says (for that rfft~ at least) the left and right outputs can be considered as the coefficents of cosine and sine respectively. Does this mean that if frequency and phase of a sinusoid can br represented as A*sin(2*PI*f*t)+B*cos(2*PI*f*t), then the left output of fft~ is B and the right output is A? If so, how do I get frequency and phase? (My calculus book is back in Boulder)
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. 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) for f, R and phase (arctangent part), but basically I am interested in whatever method is fastest so that I can do more processing to the output.
If I am going to convolve the two signals - multiply in the frequency domain - what happens to phase?
convolution is a simply multiplication, but it's a multiplication of complex numbers ... (and it's of course different, when you use rectangular or polar representation)
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) convert to polar, multiply the frequencies, divide by niquist (I have no idea here), then use one of the the signal phases and convert back to rectangular for rifft~, or is there some oter way?
Thanks for the help! -thewade
Hallo!
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)
and: (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 ...
LG Georg
Guten abend,
Georg Holzmann wrote:
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)
and: (a+b*i) = r*e^(i*phi) = r*(cos(phi) + i*sin(phi)) and you have r and phi now ...
Wait, (a+b*i) = frequency? If so that makes more sense as to why even use imaginary numbers. I don't really understand imaginary numbers - there more difficult for me then when I learned about inclusion in jr. high. So if I want to solve for frequency I need to know what sqrt(-1) = i is?
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 ...
It seems like if I multiply the two signals frequencies togeather all the frequencies would shift way up, so I have to scale them back down somehow, right? Isin't convolution freq(sig1)*freq(sig2) and freq-mag(sig1)*freq-mag(sig2)? Maybe I just don't understand what convolution is trying to achieve.
Thanks again for all the help! -thewade
Hallo!
Wait, (a+b*i) = frequency? If so that makes more sense as to why even
hm, frequency ... the bins are the frequencies. If you have e.g. a FFT size of 1024 you will get 1024 different frequencies (well, 512, because the other half is the negative spectrum ...) e.g. 44100/1024 = 43, so the first sample of the 1024-block out of the fft will give you a and b (or r and phi = Magnitude and Phase) of the frequencies from 0 to 43 Hz (this is the first bin), the next bin is 43 to 86 Hz and so on ...
that to mean more then just frequency. For example in the xy plane if you add two vectors you don't neccessarily just get a y value back.
how do you add 2 vectors and don't get a y value ?
Multiplication in the frequency domain involves frequency magnitude, but also frequency phase and frequency value. It seems to me that frequency space is 3D where as time space is 2D also.
I don't understand what you mean with frequency value, both time and frequency space can be real or complex ...
I think AM is only time domain...Having looked at www.dspguide.com the correct equations are, unlike the last thing I posted (sorry!):
ReY[f] = ReX[f]ReH[f] - ImX[f]ImH[f] ImY[f] = ImX[f]ReH[f] + ReX[f]ImH[f]
yes, that's what I wrote before: (a1 + b1*i)*(a2 + b2*i) = a1*a2 - b1*b2 + (a1*b2 + a2*b1)*i real imaginary
LG Georg
On Tue, 29 Nov 2005, thewade wrote:
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) convert to polar, multiply the frequencies, divide by niquist (I have no idea here), then use one of the the signal phases and convert back to rectangular for rifft~, or is there some oter way?
excuse me? multiplying the frequencies? i think you mean, for each frequency, multiply the amplitudes together.
multiplication of two complexes x+y*i and x'+y'*i in cartesian representation is:
x'' = x*x' - y*y' y'' = x*y' + y*x'
Then with a polar representation:
x = r*cos(a) y = r*sin(a)
It becomes as easy as:
a'' = a+a' r'' = r*r'
Or even easier in complex log representation:
s+a*i = log(x+y*i) s = log r a'' = a+a' s'' = s+s'
However, it only makes sense if you are going to make many multiplications between polar forms. If not, then the sin,cos conversions and their inverses r=sqrt(x*x+y*y),a=atan2(y,x) become more of a burden than a shortcut.
Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju Freelance Digital Arts Engineer, Montréal QC Canada