1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Function FFT (X,N,way)
'with the Cooley-Tukey method, N must be a power of 2
'if way = 1 the forward fourier transform is computed
'if way = 0 the backward fourier transform is computed
TWOPI = 6.2831853071
Dim FX()
Dim E()
Dim O()
'Compute the even and odd parts of the fourier transform
for k = 0 to N-1
redim preserve E(k)
redim preserve O(k)
for m = 0 to (N/2)-1
c = cos(TWOPI*2*m*k/N)
Ekm = Ekm + X(2*m)*c
Okm = Okm + X(2*m+1)*c
next
E(k) = Ekm
O(k) = Okm
next
'assembly
for k = 0 to N-1
redim preserve FX(k)
if (way = 1) then
if (k<(N/2)) then
FX(k) = E(k) + cos(TWOPI*k/N)*O(k)
else
FX(k) = E(k-(N/2)) + cos(TWOPI*(k*N/2)/N)*O(k-(N/2))
end if
else
if (k<(N/2)) then
FX(k) = (E(k) + cos(TWOPI*k/N)*O(k))/N
else
FX(k) = (E(k-(N/2)) + cos(TWOPI*(k*N/2)/N)*O(k-(N/2)))/N
end if
end if
next
FFT = FX
end function |
Partager