## PSN-L Email List Message

Subject: FFT Code
From: Bobhelenmcclure@.......
Date: Sat, 14 Jul 2007 21:46:27 EDT

```Hi Geoff,

I write my code in Visual Basic, and also have another FFT routine  written
in QBasic. The code listing below is what I use in my FFTDemo program,  which
you can access from _http://www.jclahr.com/science/psn/mcclure/index.html_
(http://www.jclahr.com/science/psn/mcclure/index.html)

Cheers,

Bob
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Private Sub FFT(Z() As Single)
Inv = 0
Call  FT(Inv, Npwr, Z())
End Sub

Private Sub IFT(Z() As Single)
Inv =  1
Call FT(Inv, Npwr, Z())
End Sub

Private Sub FT(Inv As Long, Npwr As Long, Z()  As Single)
Dim PI As Single, Isi As Long, ex As Single
Dim I As Long, n As  Long, J As Long, m As Long, Mmax As Long
Dim Ang As Single, wr As Single, wi  As Single, tr As Single
Dim ti As Single, istep As Long
PI = 4# *  Atn(1#)
Isi = -1
If Inv > 0 Then Isi = 1
n =  1
For I = 1 To Npwr
n = 2 * n
Next I
J =  0
For I = 0 To n - 2
If I < J Then
ex =  Z(0, I)
Z(0, I) = Z(0, J)
Z(0, J) =  ex
ex = Z(1, I)
Z(1, I) = Z(1,  J)
Z(1, J) = ex
End If
m = n / 2
While m <= J
J = J - m
m = m / 2
Wend
J = J + m
Next I
Mmax = 1
While Mmax  <> n
istep = 2 * Mmax
For m = 0 To Mmax -  1
Ang = PI * Isi * m / Mmax
wr =  Cos(Ang)
wi = Sin(Ang)
For I = m To  n - 1 Step istep
J = I +  Mmax
tr = wr * Z(0, J) - wi * Z(1,  J)
ti = wi * Z(0, J) + wr * Z(1,  J)
Z(0, J) = Z(0, I) -  tr
Z(1, J) = Z(1, I) -  ti
Z(0, I) = Z(0, I) +  tr
Z(1, I) = Z(1, I) + ti
Next  I
Next m
Mmax = istep
Wend
If Isi  > 0 Then
For I = 0 To n - 1
Z(0, I) =  (1 / n) * Z(0, I)
Z(1, I) = (1 / n) * Z(1,  I)
Next I
End If
End Sub

************************************** Get a sneak peak of the all-new AOL at
http://discover.aol.com/memed/aolcom30tour

Hi Geoff,

I write my code in Visual Basic, and also have another FFT routi=
ne=20
written in QBasic. The code listing below is what I use in my FFTDemo progra=
m,=20
which you can access from http://www.jcl=
ahr.com/science/psn/mcclure/index.html=20

Cheers,

Bob
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Private Sub FFT(Z() As Single)Inv =3D 0<=
BR>Call=20
FT(Inv, Npwr, Z())End Sub

Private Sub IFT(Z() As Single)Inv=20=
=3D=20
1Call FT(Inv, Npwr, Z())End Sub

Private Sub FT(Inv As Long, Npwr As Long=
, Z()=20
As Single)Dim PI As Single, Isi As Long, ex As SingleDim I As Long,=20=
n As=20
Long, J As Long, m As Long, Mmax As LongDim Ang As Single, wr As Single,=
wi=20
As Single, tr As SingleDim ti As Single, istep As Long PI =3D 4=
# *=20
Atn(1#) Isi =3D -1 If Inv > 0 Then Isi =3D 1 n=
=3D=20
1 For I =3D 1 To Npwr  n =3D 2 * n Next I&nbs=
p;J =3D=20
0 For I =3D 0 To n - 2  If I < J Then   e=
x =3D=20
Z(0, I)   Z(0, I) =3D Z(0, J)   Z(0, J) =3D=20
ex   ex =3D Z(1, I)   Z(1, I) =3D Z(1,=20
J)   Z(1, J) =3D ex  End If  m =3D n / 2=
=20
While m <=3D J   J =3D J - m   m =3D m / 2 =20
Wend  J =3D J + m  Next I  Mmax =3D 1 Wh=
ile Mmax=20
<> n   istep =3D 2 * Mmax   For m =3D 0 To=
Mmax -=20
1    Ang =3D PI * Isi * m / Mmax    wr=
=3D=20
Cos(Ang)    wi =3D Sin(Ang)    For I=20=
=3D m To=20
n - 1 Step istep     J =3D I +=20
Mmax     tr =3D wr * Z(0, J) - wi * Z(1,=20
J)     ti =3D wi * Z(0, J) + wr * Z(1,=20
J)     Z(0, J) =3D Z(0, I) -=20
tr     Z(1, J) =3D Z(1, I) -=20
ti     Z(0, I) =3D Z(0, I) +=20
tr     Z(1, I) =3D Z(1, I) + ti   =
; Next=20
I   Next m   Mmax =3D istep  WendIf=
Isi=20
> 0 Then   For I =3D 0 To n - 1    Z(0,=20=
I) =3D=20
(1 / n) * Z(0, I)    Z(1, I) =3D (1 / n) * Z(1,=20
I)   Next I  End If End Sub

Get a sneak pe=
ak of the all-new AOL.com.<=
/BODY>
```