Reputation: 7259
I'm suppose to do some work with Fourier transformations and I'm still really confused.
I'm given a signal (in this case it is f[t] = sin(2 pi s t / N) where s = 8 and N = 128)
And I'm suppose to find the Real, Imaginary, Phase, and Magnitude.
I understand how to get the Real and Imaginary, but the Phase and the Magnitude are beyond me...
the sudo code for getting the Real and the Imaginary is:
for u = 0 to M-1 do
F[u].real = 0
F[u].imag = 0
for x = 0 to M-1 do
F[u].real += f[x] * cos(- 2 * pi * u * x / M)
F[u].imag += f[x] * sin(- 2 * pi * u * x / M)
end do
F[u].real /= M
F[u].imag /= M
end do
Now somewhere in there is the phase and the magnitude, but where?!
Thanks!
Also, some programmer-equse explination of the basics of FTs would be wonderful as well!
Upvotes: 1
Views: 225
Reputation: 272497
From http://en.wikipedia.org/wiki/Complex_number#Absolute_value_and_argument:
sqrt(real^2 + imag^2)
(where ^
denotes "squared").atan2(imag, real)
(where atan2()
denotes the two-argument arctan function).That Wikipedia article explains why better than I can do justice here.
Upvotes: 3
Reputation: 114481
If you think to real and imaginary components as coordinates in an XY plane then the phase is the angle between the vector and the X+ axis, and the magnitude is the length of the vector. To compute then you just need
magnitude = sqrt(real*real + imag*imag)
phase = atan2(imag, real)
Upvotes: 3