Home » Recent acquisitions » Acorn ADFS disks » adfs_ArchimedesWorld_199201.adf » January92 » !AWJan92/Goodies/ProgTheARM/FFT2

!AWJan92/Goodies/ProgTheARM/FFT2

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Recent acquisitions » Acorn ADFS disks » adfs_ArchimedesWorld_199201.adf » January92
Filename: !AWJan92/Goodies/ProgTheARM/FFT2
Read OK:
File size: 0794 bytes
Load address: 0000
Exec address: 0000
File contents
   10REM > FFT2
   20
   30MODE 12
   40
   50N%=64
   60
   70n2%=2*N%
   80
   90DIM data(n2%)
  100
  110REPEAT
  120
  130K=RND(20)
  140J=RND(50)+50
  150CLS
  160PRINT"Frequencies: "K,J
  170
  180GCOL7
  190
  200FOR I%=0TO N%-1
  210  ii%=2*I%+1
  220  data(ii%)   = SINRAD(I%*K) + SINRAD(I%*J)
  230  data(ii%+1) = 0
  240  RECTANGLEFILL 8*I%,512,7,256*data(ii%)
  250NEXT
  260
  270PROCfour1(N%,1)
  280
  290GCOL1
  300
  310FOR I%=0 TO (N%-1) DIV 2
  320  ii%=2*I%+1
  350  RECTANGLEFILL 16*I%,0,15,8*ABS(data(ii%))
  360NEXT
  370
  380QQ=GET
  390
  400UNTIL.
  410
  420END
  430
  440
  450REM data() accessed by refernece
  460DEFPROCfour1(nn%,isign%)
  470
  480LOCALii%,jj%,n%,mmax%,m%,j%,istep%,i%
  490LOCALwtemp,wr,wpr,wpi,wi,theta
  500LOCALtempr,tempi,wrs,wis
  510
  520LOCALs
  530
  540n%=2*nn%
  550j%=1
  560REM This is the bit-reversal section of the routine
  570FOR ii%=1 TO nn%
  580  i%=2*ii%-1
  590  IF j% > i% THEN
  600    REM Swap the real and imarinary parts of the two
  610    tempr      = data(j%) : tempi      = data(j%+1)
  620    data(j%)   = data(i%) : data(j%+1) = data(i%+1)
  630    data(i%)   = tempr    : data(i%+1) = tempi
  640  ENDIF
  650  m% = n% DIV 2
  660  WHILE (m%>=2) AND (j%>m%)
  670    j% = j% - m%
  680    m% = m% DIV 2
  690  ENDWHILE
  700  j% = j% + m%
  710NEXT
  720
  730mmax% = 2
  740
  750REM Now the Danielson-Lanczos recurrence
  760
  770WHILE n% > mmax%
  780  istep% = 2*mmax%
  790  theta  = 2 * PI / (isign%*mmax%)
  800
  810        s=SIN(0.5*theta)
  820  wpr    = -2.0 * s*s
  830  wpi    = SIN(theta)
  840
  850  wr = 1.0
  860  wi = 0.0
  870  FOR ii% = 1 TO mmax% DIV 2
  880    m% = 2*ii%-1
  890    wrs = wr
  900    wis = wi
  910    FOR jj%=0 TO (n%-m%) DIV istep%
  920      i% = m% + jj%*istep%
  930      j% = i%+mmax%
  940      tempr = wrs*data(j%)   - wis*data(j%+1)
  950      tempi = wrs*data(j%+1) + wis*data(j%)
  960      data(j%)   = data(i%)   - tempr
  970      data(j%+1) = data(i%+1) - tempi
  980      data(i%)   = data(i%)   + tempr
  990      data(i%+1) = data(i%+1) + tempi
 1000    NEXT
 1010    wtemp = wr
 1020    wr = wr*wpr -    wi*wpi + wr
 1030    wi = wi*wpr + wtemp*wpi  +wi
 1040  NEXT
 1050  mmax% = istep%
 1060ENDWHILE
 1070ENDPROC
 1080
 1090
 1100
 1110
 1120
 1130
 1140
 1150
 1160
 1170
 1180
 1190
 1200
 1210
 1220
 1230

� > FFT2

� 12
(
2	N%=64
<
Fn2%=2*N%
P
Z� data(n2%)
d
n�
x
�K=�(20)
�J=�(50)+50
��
��"Frequencies: "K,J
�
��7
�
�� I%=0� N%-1
�  ii%=2*I%+1
�'  data(ii%)   = ��(I%*K) + ��(I%*J)
�  data(ii%+1) = 0
�#  ȓȐ 8*I%,512,7,256*data(ii%)
��

�four1(N%,1)

"�1
,
6� I%=0 � (N%-1) � 2
@  ii%=2*I%+1
^$  ȓȐ 16*I%,0,15,8*�(data(ii%))
h�
r
|QQ=�
�
��.
�
��
�
�
�"� data() accessed by refernece
���four1(nn%,isign%)
�
�%�ii%,jj%,n%,mmax%,m%,j%,istep%,i%
��wtemp,wr,wpr,wpi,wi,theta
��tempr,tempi,wrs,wis
�
�s

n%=2*nn%
&j%=1
05� This is the bit-reversal section of the routine
:� ii%=1 � nn%
D  i%=2*ii%-1
N  � j% > i% �
X6    � Swap the real and imarinary parts of the two
b7    tempr      = data(j%) : tempi      = data(j%+1)
l7    data(j%)   = data(i%) : data(j%+1) = data(i%+1)
v2    data(i%)   = tempr    : data(i%+1) = tempi
�  �
�  m% = n% � 2
�  ȕ (m%>=2) � (j%>m%)
�    j% = j% - m%
�    m% = m% � 2
�  �
�  j% = j% + m%
��
�
�
mmax% = 2
�
�*� Now the Danielson-Lanczos recurrence
�
ȕ n% > mmax%
  istep% = 2*mmax%
%  theta  = 2 * � / (isign%*mmax%)
 
*        s=�(0.5*theta)
4  wpr    = -2.0 * s*s
>  wpi    = �(theta)
H
R  wr = 1.0
\  wi = 0.0
f  � ii% = 1 � mmax% � 2
p    m% = 2*ii%-1
z    wrs = wr
�    wis = wi
�"    � jj%=0 � (n%-m%) � istep%
�      i% = m% + jj%*istep%
�      j% = i%+mmax%
�1      tempr = wrs*data(j%)   - wis*data(j%+1)
�/      tempi = wrs*data(j%+1) + wis*data(j%)
�)      data(j%)   = data(i%)   - tempr
�)      data(j%+1) = data(i%+1) - tempi
�)      data(i%)   = data(i%)   + tempr
�)      data(i%+1) = data(i%+1) + tempi
�	    �
�    wtemp = wr
�$    wr = wr*wpr -    wi*wpi + wr
$    wi = wi*wpr + wtemp*wpi  +wi
  �
  mmax% = istep%
$�
.�
8
B
L
V
`
j
t
~
�
�
�
�
�
�
�
�
�
00000000  0d 00 0a 0c f4 20 3e 20  46 46 54 32 0d 00 14 04  |..... > FFT2....|
00000010  0d 00 1e 08 eb 20 31 32  0d 00 28 04 0d 00 32 09  |..... 12..(...2.|
00000020  4e 25 3d 36 34 0d 00 3c  04 0d 00 46 0c 6e 32 25  |N%=64..<...F.n2%|
00000030  3d 32 2a 4e 25 0d 00 50  04 0d 00 5a 0f de 20 64  |=2*N%..P...Z.. d|
00000040  61 74 61 28 6e 32 25 29  0d 00 64 04 0d 00 6e 05  |ata(n2%)..d...n.|
00000050  f5 0d 00 78 04 0d 00 82  0b 4b 3d b3 28 32 30 29  |...x.....K=.(20)|
00000060  0d 00 8c 0e 4a 3d b3 28  35 30 29 2b 35 30 0d 00  |....J=.(50)+50..|
00000070  96 05 db 0d 00 a0 17 f1  22 46 72 65 71 75 65 6e  |........"Frequen|
00000080  63 69 65 73 3a 20 22 4b  2c 4a 0d 00 aa 04 0d 00  |cies: "K,J......|
00000090  b4 06 e6 37 0d 00 be 04  0d 00 c8 10 e3 20 49 25  |...7......... I%|
000000a0  3d 30 b8 20 4e 25 2d 31  0d 00 d2 10 20 20 69 69  |=0. N%-1....  ii|
000000b0  25 3d 32 2a 49 25 2b 31  0d 00 dc 27 20 20 64 61  |%=2*I%+1...'  da|
000000c0  74 61 28 69 69 25 29 20  20 20 3d 20 b5 b2 28 49  |ta(ii%)   = ..(I|
000000d0  25 2a 4b 29 20 2b 20 b5  b2 28 49 25 2a 4a 29 0d  |%*K) + ..(I%*J).|
000000e0  00 e6 15 20 20 64 61 74  61 28 69 69 25 2b 31 29  |...  data(ii%+1)|
000000f0  20 3d 20 30 0d 00 f0 23  20 20 c8 93 c8 90 20 38  | = 0...#  .... 8|
00000100  2a 49 25 2c 35 31 32 2c  37 2c 32 35 36 2a 64 61  |*I%,512,7,256*da|
00000110  74 61 28 69 69 25 29 0d  00 fa 05 ed 0d 01 04 04  |ta(ii%).........|
00000120  0d 01 0e 10 f2 66 6f 75  72 31 28 4e 25 2c 31 29  |.....four1(N%,1)|
00000130  0d 01 18 04 0d 01 22 06  e6 31 0d 01 2c 04 0d 01  |......"..1..,...|
00000140  36 17 e3 20 49 25 3d 30  20 b8 20 28 4e 25 2d 31  |6.. I%=0 . (N%-1|
00000150  29 20 81 20 32 0d 01 40  10 20 20 69 69 25 3d 32  |) . 2..@.  ii%=2|
00000160  2a 49 25 2b 31 0d 01 5e  24 20 20 c8 93 c8 90 20  |*I%+1..^$  .... |
00000170  31 36 2a 49 25 2c 30 2c  31 35 2c 38 2a 94 28 64  |16*I%,0,15,8*.(d|
00000180  61 74 61 28 69 69 25 29  29 0d 01 68 05 ed 0d 01  |ata(ii%))..h....|
00000190  72 04 0d 01 7c 08 51 51  3d a5 0d 01 86 04 0d 01  |r...|.QQ=.......|
000001a0  90 06 fd 2e 0d 01 9a 04  0d 01 a4 05 e0 0d 01 ae  |................|
000001b0  04 0d 01 b8 04 0d 01 c2  22 f4 20 64 61 74 61 28  |........". data(|
000001c0  29 20 61 63 63 65 73 73  65 64 20 62 79 20 72 65  |) accessed by re|
000001d0  66 65 72 6e 65 63 65 0d  01 cc 17 dd f2 66 6f 75  |fernece......fou|
000001e0  72 31 28 6e 6e 25 2c 69  73 69 67 6e 25 29 0d 01  |r1(nn%,isign%)..|
000001f0  d6 04 0d 01 e0 25 ea 69  69 25 2c 6a 6a 25 2c 6e  |.....%.ii%,jj%,n|
00000200  25 2c 6d 6d 61 78 25 2c  6d 25 2c 6a 25 2c 69 73  |%,mmax%,m%,j%,is|
00000210  74 65 70 25 2c 69 25 0d  01 ea 1e ea 77 74 65 6d  |tep%,i%.....wtem|
00000220  70 2c 77 72 2c 77 70 72  2c 77 70 69 2c 77 69 2c  |p,wr,wpr,wpi,wi,|
00000230  74 68 65 74 61 0d 01 f4  18 ea 74 65 6d 70 72 2c  |theta.....tempr,|
00000240  74 65 6d 70 69 2c 77 72  73 2c 77 69 73 0d 01 fe  |tempi,wrs,wis...|
00000250  04 0d 02 08 06 ea 73 0d  02 12 04 0d 02 1c 0c 6e  |......s........n|
00000260  25 3d 32 2a 6e 6e 25 0d  02 26 08 6a 25 3d 31 0d  |%=2*nn%..&.j%=1.|
00000270  02 30 35 f4 20 54 68 69  73 20 69 73 20 74 68 65  |.05. This is the|
00000280  20 62 69 74 2d 72 65 76  65 72 73 61 6c 20 73 65  | bit-reversal se|
00000290  63 74 69 6f 6e 20 6f 66  20 74 68 65 20 72 6f 75  |ction of the rou|
000002a0  74 69 6e 65 0d 02 3a 11  e3 20 69 69 25 3d 31 20  |tine..:.. ii%=1 |
000002b0  b8 20 6e 6e 25 0d 02 44  10 20 20 69 25 3d 32 2a  |. nn%..D.  i%=2*|
000002c0  69 69 25 2d 31 0d 02 4e  11 20 20 e7 20 6a 25 20  |ii%-1..N.  . j% |
000002d0  3e 20 69 25 20 8c 0d 02  58 36 20 20 20 20 f4 20  |> i% ...X6    . |
000002e0  53 77 61 70 20 74 68 65  20 72 65 61 6c 20 61 6e  |Swap the real an|
000002f0  64 20 69 6d 61 72 69 6e  61 72 79 20 70 61 72 74  |d imarinary part|
00000300  73 20 6f 66 20 74 68 65  20 74 77 6f 0d 02 62 37  |s of the two..b7|
00000310  20 20 20 20 74 65 6d 70  72 20 20 20 20 20 20 3d  |    tempr      =|
00000320  20 64 61 74 61 28 6a 25  29 20 3a 20 74 65 6d 70  | data(j%) : temp|
00000330  69 20 20 20 20 20 20 3d  20 64 61 74 61 28 6a 25  |i      = data(j%|
00000340  2b 31 29 0d 02 6c 37 20  20 20 20 64 61 74 61 28  |+1)..l7    data(|
00000350  6a 25 29 20 20 20 3d 20  64 61 74 61 28 69 25 29  |j%)   = data(i%)|
00000360  20 3a 20 64 61 74 61 28  6a 25 2b 31 29 20 3d 20  | : data(j%+1) = |
00000370  64 61 74 61 28 69 25 2b  31 29 0d 02 76 32 20 20  |data(i%+1)..v2  |
00000380  20 20 64 61 74 61 28 69  25 29 20 20 20 3d 20 74  |  data(i%)   = t|
00000390  65 6d 70 72 20 20 20 20  3a 20 64 61 74 61 28 69  |empr    : data(i|
000003a0  25 2b 31 29 20 3d 20 74  65 6d 70 69 0d 02 80 07  |%+1) = tempi....|
000003b0  20 20 cd 0d 02 8a 11 20  20 6d 25 20 3d 20 6e 25  |  .....  m% = n%|
000003c0  20 81 20 32 0d 02 94 1a  20 20 c8 95 20 28 6d 25  | . 2....  .. (m%|
000003d0  3e 3d 32 29 20 80 20 28  6a 25 3e 6d 25 29 0d 02  |>=2) . (j%>m%)..|
000003e0  9e 14 20 20 20 20 6a 25  20 3d 20 6a 25 20 2d 20  |..    j% = j% - |
000003f0  6d 25 0d 02 a8 13 20 20  20 20 6d 25 20 3d 20 6d  |m%....    m% = m|
00000400  25 20 81 20 32 0d 02 b2  07 20 20 ce 0d 02 bc 12  |% . 2....  .....|
00000410  20 20 6a 25 20 3d 20 6a  25 20 2b 20 6d 25 0d 02  |  j% = j% + m%..|
00000420  c6 05 ed 0d 02 d0 04 0d  02 da 0d 6d 6d 61 78 25  |...........mmax%|
00000430  20 3d 20 32 0d 02 e4 04  0d 02 ee 2a f4 20 4e 6f  | = 2.......*. No|
00000440  77 20 74 68 65 20 44 61  6e 69 65 6c 73 6f 6e 2d  |w the Danielson-|
00000450  4c 61 6e 63 7a 6f 73 20  72 65 63 75 72 72 65 6e  |Lanczos recurren|
00000460  63 65 0d 02 f8 04 0d 03  02 11 c8 95 20 6e 25 20  |ce.......... n% |
00000470  3e 20 6d 6d 61 78 25 0d  03 0c 16 20 20 69 73 74  |> mmax%....  ist|
00000480  65 70 25 20 3d 20 32 2a  6d 6d 61 78 25 0d 03 16  |ep% = 2*mmax%...|
00000490  25 20 20 74 68 65 74 61  20 20 3d 20 32 20 2a 20  |%  theta  = 2 * |
000004a0  af 20 2f 20 28 69 73 69  67 6e 25 2a 6d 6d 61 78  |. / (isign%*mmax|
000004b0  25 29 0d 03 20 04 0d 03  2a 1a 20 20 20 20 20 20  |%).. ...*.      |
000004c0  20 20 73 3d b5 28 30 2e  35 2a 74 68 65 74 61 29  |  s=.(0.5*theta)|
000004d0  0d 03 34 19 20 20 77 70  72 20 20 20 20 3d 20 2d  |..4.  wpr    = -|
000004e0  32 2e 30 20 2a 20 73 2a  73 0d 03 3e 17 20 20 77  |2.0 * s*s..>.  w|
000004f0  70 69 20 20 20 20 3d 20  b5 28 74 68 65 74 61 29  |pi    = .(theta)|
00000500  0d 03 48 04 0d 03 52 0e  20 20 77 72 20 3d 20 31  |..H...R.  wr = 1|
00000510  2e 30 0d 03 5c 0e 20 20  77 69 20 3d 20 30 2e 30  |.0..\.  wi = 0.0|
00000520  0d 03 66 1b 20 20 e3 20  69 69 25 20 3d 20 31 20  |..f.  . ii% = 1 |
00000530  b8 20 6d 6d 61 78 25 20  81 20 32 0d 03 70 14 20  |. mmax% . 2..p. |
00000540  20 20 20 6d 25 20 3d 20  32 2a 69 69 25 2d 31 0d  |   m% = 2*ii%-1.|
00000550  03 7a 10 20 20 20 20 77  72 73 20 3d 20 77 72 0d  |.z.    wrs = wr.|
00000560  03 84 10 20 20 20 20 77  69 73 20 3d 20 77 69 0d  |...    wis = wi.|
00000570  03 8e 22 20 20 20 20 e3  20 6a 6a 25 3d 30 20 b8  |.."    . jj%=0 .|
00000580  20 28 6e 25 2d 6d 25 29  20 81 20 69 73 74 65 70  | (n%-m%) . istep|
00000590  25 0d 03 98 1e 20 20 20  20 20 20 69 25 20 3d 20  |%....      i% = |
000005a0  6d 25 20 2b 20 6a 6a 25  2a 69 73 74 65 70 25 0d  |m% + jj%*istep%.|
000005b0  03 a2 17 20 20 20 20 20  20 6a 25 20 3d 20 69 25  |...      j% = i%|
000005c0  2b 6d 6d 61 78 25 0d 03  ac 31 20 20 20 20 20 20  |+mmax%...1      |
000005d0  74 65 6d 70 72 20 3d 20  77 72 73 2a 64 61 74 61  |tempr = wrs*data|
000005e0  28 6a 25 29 20 20 20 2d  20 77 69 73 2a 64 61 74  |(j%)   - wis*dat|
000005f0  61 28 6a 25 2b 31 29 0d  03 b6 2f 20 20 20 20 20  |a(j%+1).../     |
00000600  20 74 65 6d 70 69 20 3d  20 77 72 73 2a 64 61 74  | tempi = wrs*dat|
00000610  61 28 6a 25 2b 31 29 20  2b 20 77 69 73 2a 64 61  |a(j%+1) + wis*da|
00000620  74 61 28 6a 25 29 0d 03  c0 29 20 20 20 20 20 20  |ta(j%)...)      |
00000630  64 61 74 61 28 6a 25 29  20 20 20 3d 20 64 61 74  |data(j%)   = dat|
00000640  61 28 69 25 29 20 20 20  2d 20 74 65 6d 70 72 0d  |a(i%)   - tempr.|
00000650  03 ca 29 20 20 20 20 20  20 64 61 74 61 28 6a 25  |..)      data(j%|
00000660  2b 31 29 20 3d 20 64 61  74 61 28 69 25 2b 31 29  |+1) = data(i%+1)|
00000670  20 2d 20 74 65 6d 70 69  0d 03 d4 29 20 20 20 20  | - tempi...)    |
00000680  20 20 64 61 74 61 28 69  25 29 20 20 20 3d 20 64  |  data(i%)   = d|
00000690  61 74 61 28 69 25 29 20  20 20 2b 20 74 65 6d 70  |ata(i%)   + temp|
000006a0  72 0d 03 de 29 20 20 20  20 20 20 64 61 74 61 28  |r...)      data(|
000006b0  69 25 2b 31 29 20 3d 20  64 61 74 61 28 69 25 2b  |i%+1) = data(i%+|
000006c0  31 29 20 2b 20 74 65 6d  70 69 0d 03 e8 09 20 20  |1) + tempi....  |
000006d0  20 20 ed 0d 03 f2 12 20  20 20 20 77 74 65 6d 70  |  .....    wtemp|
000006e0  20 3d 20 77 72 0d 03 fc  24 20 20 20 20 77 72 20  | = wr...$    wr |
000006f0  3d 20 77 72 2a 77 70 72  20 2d 20 20 20 20 77 69  |= wr*wpr -    wi|
00000700  2a 77 70 69 20 2b 20 77  72 0d 04 06 24 20 20 20  |*wpi + wr...$   |
00000710  20 77 69 20 3d 20 77 69  2a 77 70 72 20 2b 20 77  | wi = wi*wpr + w|
00000720  74 65 6d 70 2a 77 70 69  20 20 2b 77 69 0d 04 10  |temp*wpi  +wi...|
00000730  07 20 20 ed 0d 04 1a 14  20 20 6d 6d 61 78 25 20  |.  .....  mmax% |
00000740  3d 20 69 73 74 65 70 25  0d 04 24 05 ce 0d 04 2e  |= istep%..$.....|
00000750  05 e1 0d 04 38 04 0d 04  42 04 0d 04 4c 04 0d 04  |....8...B...L...|
00000760  56 04 0d 04 60 04 0d 04  6a 04 0d 04 74 04 0d 04  |V...`...j...t...|
00000770  7e 04 0d 04 88 04 0d 04  92 04 0d 04 9c 04 0d 04  |~...............|
00000780  a6 04 0d 04 b0 04 0d 04  ba 04 0d 04 c4 04 0d 04  |................|
00000790  ce 04 0d ff                                       |....|
00000794