Home » Archimedes archive » Archimedes World » AW-1996-02-Disc2.adf » !AcornAns_Trans1d » !Trans1d/c/main
!Trans1d/c/main
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 » Archimedes archive » Archimedes World » AW-1996-02-Disc2.adf » !AcornAns_Trans1d |
Filename: | !Trans1d/c/main |
Read OK: | ✔ |
File size: | 21E1 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
#include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> #include <time.h> #include <math.h> #include "wimpt.h" #include "werr.h" #include "bbc.h" #include "os.h" #include "swis.h" #define one (1<<16) #define rotone (1<<28) #define rotscale (rotone/one) #define dimsn(f) ((int)((f)-5)/5.0+1.0) typedef enum {multi, nonmulti} monitor; monitor monitortype; int linesep; typedef struct { int re; int im; } complex; /* Let x(t) be the function under consideration & a(s) be its Fourier Transform. */ /* This program generates an N point sample of x(t), for various test functions, */ /* evaluates the Discrete Fourier Transform (DFT) of this sample, using a Fast */ /* Fourier Transform algorithm, & then inverts this to try to get the original */ /* function x(t) back. */ /* For each such trial, the sample, its DFT & the inverted DFT (which should */ /* match the original sample) are graphed. */ /* A number of additional trials are then conducted in which the DFT is filtered */ /* after calculation to alter the nature of the inverted DFT, creating a fractal */ /* graph. */ /* Notes on relation of DFT to continuous FT & some global variables:*/ int N; int limit; /* Assume x(t) is appreciably non-zero only in range 0<t<T. */ double T; /* Define limit = log to base 2 of sample size N (ie N=1<<limit). */ complex *data = 0; /* We then sample x(t) at the N points: t=Tr/N for r=0,...,(N-1), storing each */ /* value in data[r]. */ /* Thus data[] stores an N point sample of x(t) over the range 0 to T, at */ /* sample interval T/N. */ /* The DFT A(s) then corresponds to the continuous transform a() with approx */ /* a(s/T) = A(s+N), for s = -N/2,...,-1 */ /* a(s/T) = A(s), for s = 0,...,(N/2-1) */ double F; /* Hence the FT is approximated in the range �F/2 where F is defined as N/T, */ /* at N points separated by frequency interval 1/T. */ char *fn_desc; char *ft_desc; char it_desc[256]; extern int rbbcinc(int r, int k); extern int div_frac16(int number, int divisor); extern int mul_frac16(int x, int a); extern int mul_frac16c(int x, int a); extern int sqrt_frac28(unsigned int x); extern int gauss16(void); extern void sgauss16(int seed); BOOL fft_1d(complex *data, int limit, int sign) { int i, j; int n = 1<<limit; complex t1; int t2; int k, l; int loop; int rotc, rots; int cos, sin; if (limit<2 || limit>32) return FALSE; for (i=j=0; j<n; i=rbbcinc(i, limit), j++) if (i>j) { t1 = data[i]; data[i] = data[j]; data[j] = t1; } rotc = -rotone; rots = 0; for (k=loop=1; loop<=limit; loop++, k<<=1, rots=sqrt_frac28((rotone-rotc)/2), rotc=sqrt_frac28((rotone+rotc)/2), rots=sign<0?-rots:rots) { for (sin=0, cos=one, i=1; i<=k; i++, t2 =mul_frac16c(cos, rotc/rotscale)-mul_frac16c(sin, rots/rotscale), sin=mul_frac16c(sin, rotc/rotscale)+mul_frac16c(cos, rots/rotscale), cos=t2) { for (j=i-1; j<n; j+=k<<1) { l = j+k; t1.re = mul_frac16c(data[l].re, cos)-mul_frac16c(data[l].im, sin); t1.im = mul_frac16c(data[l].re, sin)+mul_frac16c(data[l].im, cos); data[l].re = data[j].re-t1.re; data[l].im = data[j].im-t1.im; data[j].re += t1.re; data[j].im += t1.im; } } } return TRUE; } BOOL scale(complex *data, int limit, int s) { int n=1<<limit; int i; for (i=0; i<n; i++) { data[i].re = mul_frac16(data[i].re, s); data[i].im = mul_frac16(data[i].im, s); } return TRUE; } BOOL filter(complex *data, int limit, double dimension) { int n=1<<limit; int i, k; double mbbt = -(2.5-dimension); int scale; for (i=0; i<n; i++) { if (i==0) scale=0; else { k = i<n/2 ? i : n-i; scale = (int)(one*pow((double)k, mbbt)); } data[i].re = mul_frac16(data[i].re, scale); data[i].im = mul_frac16(data[i].im, scale); } return TRUE; } double assign(complex *data, int limit, int function) { int n=1<<limit; int i; double T; double dim; switch (function) { case 0: T = 1; fn_desc = "sine wave packet"; ft_desc = ""; *it_desc = 0; for (i=0; i<n; i++) { data[i].re = (int)(one*(double)sin(6.283185307*i*T/n)); data[i].im = 0; } break; case 1: T = 5; fn_desc = "damped sine wave"; ft_desc = ""; *it_desc = 0; for (i=0; i<n; i++) { data[i].re = i==0 ? one : (int)(one*(double)sin(6.283185307*i*T/n)/(6.283185307*i*T/n)); data[i].im = 0; } break; case 2: T = 1; fn_desc = "square wave packet"; ft_desc = ""; *it_desc = 0; for (i=0; i<n; i++) { data[i].re = i<n/2 ? one : 0; data[i].im = 0; } break; case 3: T = 1; fn_desc = "white noise"; ft_desc = ""; *it_desc = 0; for (i=0; i<n; i++) { data[i].re = (rand()>>15)-one/2; data[i].im = 0; } break; case 4: T = 1; fn_desc = "gaussian white noise"; ft_desc = ""; *it_desc = 0; for (i=0; i<n; i++) { data[i].re = gauss16(); data[i].im = 0; } break; default: /*for 6 cases, 5-10*/ T = 1; fn_desc = "gaussian white noise"; ft_desc = "Filtered by 1/(f^k)"; dim = dimsn(function); sprintf(it_desc, "k = %.3f, Fractal dim. = %.3f", 2.5-dim, dim); for (i=0; i<n; i++) { data[i].re = gauss16(); data[i].im = 0; } break; } return T; } #define reorder(i, n, flag) ((flag) ? ((i)<(n)/2 ? (i)+(n)/2 : (i)-(n)/2) : (i)) #define yscale 124 BOOL graph(complex *data, int limit, int yo, BOOL repos, char *text, ...) { int n=1<<limit; int i; int min=1<<30; int max=-min; int scale; va_list argp; for (i=0; i<n; i++) { if (data[i].re<min) min=data[i].re; if (data[i].im<min) min=data[i].im; if (data[i].re>max) max=data[i].re; if (data[i].im>max) max=data[i].im; } max = max>0 ? max : -max; min = min>0 ? min : -min; scale = max>min ? max : min; if (scale==0) scale=1; bbc_origin(640,yo); bbc_palette(1, 16, 51,51,51); bbc_gcol(0, 1); bbc_rectanglefill(-517,-4,1031,9); bbc_rectanglefill(repos?-5:-517,-yscale-4,9,2*yscale+7); bbc_vdu(5); bbc_move((repos?0:-512)-44,yscale+40); printf("%.3f", (double)scale/one); bbc_move(-512+96,yscale+40); va_start(argp, text); vprintf(text, argp); va_end(argp); bbc_move((repos?0:-512)-60,-yscale-20); printf("%.3f", -(double)scale/one); bbc_move(-512-128,linesep/4); printf("%.3f", repos?-F/2:0.0); bbc_move(520,linesep/4); printf("%.3f", repos?F/2:T); bbc_vdu(4); bbc_gcol(0, 2); bbc_move(-512,data[reorder(0, n, repos)].re*yscale/scale); for (i=1; i<n; i++) { bbc_plot(13, i*1024/n-512,data[reorder(i, n, repos)].re*yscale/scale); } bbc_gcol(0, 3); bbc_move(-512,data[reorder(0, n, repos)].im*yscale/scale); for (i=1; i<n; i++) { bbc_plot(13, i*1024/n-512,data[reorder(i, n, repos)].im*yscale/scale); } return TRUE; } monitor read_monitor_type(void) { int r2; os_swi3r(6, 161,133,0, 0,0,&r2); if ((r2/4 & 3) == 1) return multi; else return nonmulti; } int main(void) { int function, seed; char dummy; monitortype = read_monitor_type(); for (;;) { seed = -clock(); do { printf("Please enter power (suggest 7-10, though 2-15 permissible) "); scanf("%i", &limit); } while (limit<2 || limit>15); N = 1<<limit; data = calloc(N, sizeof(complex)); if (data==0) werr(1, "Insufficient memory"); for (function=0; function<11; function++) { sgauss16(seed); srand(seed); bbc_mode(monitortype==multi ? 20 : 12); linesep = monitortype==multi ? 20 : 40; T=assign(data, limit, function); F=N/T; graph(data, limit, 852, FALSE, "Source function '%s' (Sample size N=%i)", fn_desc, N); fft_1d(data, limit, 1); scale(data, limit, (int)(one*T/N)); if (function>4) filter(data, limit, dimsn(function)); graph(data, limit, 512, TRUE, "Fourier Transform %s", ft_desc); fft_1d(data, limit, -1); scale(data, limit, (int)(one/T)); graph(data, limit, 172, FALSE, "Inverted Transform %s", it_desc); bbc_vdu(5); bbc_origin(0,0); bbc_move(1152, 131); printf("Press a"); bbc_move(1152, 131-linesep); printf("key ..."); bbc_vdu(4); os_cli("fx 15 1"); bbc_cursor(0); dummy = bbc_get(); } free(data); bbc_cls(); } return 0; }
00000000 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e |#include <stdio.| 00000010 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 64 |h>.#include <std| 00000020 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 |lib.h>.#include | 00000030 3c 73 74 64 61 72 67 2e 68 3e 0a 23 69 6e 63 6c |<stdarg.h>.#incl| 00000040 75 64 65 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 23 |ude <string.h>.#| 00000050 69 6e 63 6c 75 64 65 20 3c 74 69 6d 65 2e 68 3e |include <time.h>| 00000060 0a 23 69 6e 63 6c 75 64 65 20 3c 6d 61 74 68 2e |.#include <math.| 00000070 68 3e 0a 0a 23 69 6e 63 6c 75 64 65 20 22 77 69 |h>..#include "wi| 00000080 6d 70 74 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 |mpt.h".#include | 00000090 22 77 65 72 72 2e 68 22 0a 23 69 6e 63 6c 75 64 |"werr.h".#includ| 000000a0 65 20 22 62 62 63 2e 68 22 0a 23 69 6e 63 6c 75 |e "bbc.h".#inclu| 000000b0 64 65 20 22 6f 73 2e 68 22 0a 0a 23 69 6e 63 6c |de "os.h"..#incl| 000000c0 75 64 65 20 22 73 77 69 73 2e 68 22 0a 23 64 65 |ude "swis.h".#de| 000000d0 66 69 6e 65 20 6f 6e 65 20 28 31 3c 3c 31 36 29 |fine one (1<<16)| 000000e0 0a 23 64 65 66 69 6e 65 20 72 6f 74 6f 6e 65 20 |.#define rotone | 000000f0 28 31 3c 3c 32 38 29 0a 23 64 65 66 69 6e 65 20 |(1<<28).#define | 00000100 72 6f 74 73 63 61 6c 65 20 28 72 6f 74 6f 6e 65 |rotscale (rotone| 00000110 2f 6f 6e 65 29 0a 0a 23 64 65 66 69 6e 65 20 64 |/one)..#define d| 00000120 69 6d 73 6e 28 66 29 20 28 28 69 6e 74 29 28 28 |imsn(f) ((int)((| 00000130 66 29 2d 35 29 2f 35 2e 30 2b 31 2e 30 29 0a 0a |f)-5)/5.0+1.0)..| 00000140 74 79 70 65 64 65 66 20 65 6e 75 6d 20 7b 6d 75 |typedef enum {mu| 00000150 6c 74 69 2c 20 6e 6f 6e 6d 75 6c 74 69 7d 20 6d |lti, nonmulti} m| 00000160 6f 6e 69 74 6f 72 3b 0a 6d 6f 6e 69 74 6f 72 20 |onitor;.monitor | 00000170 6d 6f 6e 69 74 6f 72 74 79 70 65 3b 0a 69 6e 74 |monitortype;.int| 00000180 20 6c 69 6e 65 73 65 70 3b 0a 0a 74 79 70 65 64 | linesep;..typed| 00000190 65 66 20 73 74 72 75 63 74 20 7b 0a 20 20 69 6e |ef struct {. in| 000001a0 74 20 72 65 3b 0a 20 20 69 6e 74 20 69 6d 3b 0a |t re;. int im;.| 000001b0 7d 20 63 6f 6d 70 6c 65 78 3b 0a 0a 09 09 09 2f |} complex;...../| 000001c0 2a 20 4c 65 74 20 78 28 74 29 20 62 65 20 74 68 |* Let x(t) be th| 000001d0 65 20 66 75 6e 63 74 69 6f 6e 20 75 6e 64 65 72 |e function under| 000001e0 20 63 6f 6e 73 69 64 65 72 61 74 69 6f 6e 20 26 | consideration &| 000001f0 20 61 28 73 29 20 62 65 20 69 74 73 20 46 6f 75 | a(s) be its Fou| 00000200 72 69 65 72 20 54 72 61 6e 73 66 6f 72 6d 2e 20 |rier Transform. | 00000210 2a 2f 0a 09 09 09 2f 2a 20 54 68 69 73 20 70 72 |*/..../* This pr| 00000220 6f 67 72 61 6d 20 67 65 6e 65 72 61 74 65 73 20 |ogram generates | 00000230 61 6e 20 4e 20 70 6f 69 6e 74 20 73 61 6d 70 6c |an N point sampl| 00000240 65 20 6f 66 20 78 28 74 29 2c 20 66 6f 72 20 76 |e of x(t), for v| 00000250 61 72 69 6f 75 73 20 74 65 73 74 20 66 75 6e 63 |arious test func| 00000260 74 69 6f 6e 73 2c 20 2a 2f 0a 09 09 09 2f 2a 20 |tions, */..../* | 00000270 65 76 61 6c 75 61 74 65 73 20 74 68 65 20 44 69 |evaluates the Di| 00000280 73 63 72 65 74 65 20 46 6f 75 72 69 65 72 20 54 |screte Fourier T| 00000290 72 61 6e 73 66 6f 72 6d 20 28 44 46 54 29 20 6f |ransform (DFT) o| 000002a0 66 20 74 68 69 73 20 73 61 6d 70 6c 65 2c 20 75 |f this sample, u| 000002b0 73 69 6e 67 20 61 20 46 61 73 74 09 20 2a 2f 0a |sing a Fast. */.| 000002c0 09 09 09 2f 2a 20 46 6f 75 72 69 65 72 20 54 72 |.../* Fourier Tr| 000002d0 61 6e 73 66 6f 72 6d 20 61 6c 67 6f 72 69 74 68 |ansform algorith| 000002e0 6d 2c 20 26 20 74 68 65 6e 20 69 6e 76 65 72 74 |m, & then invert| 000002f0 73 20 74 68 69 73 20 74 6f 20 74 72 79 20 74 6f |s this to try to| 00000300 20 67 65 74 20 74 68 65 20 6f 72 69 67 69 6e 61 | get the origina| 00000310 6c 09 20 2a 2f 0a 09 09 09 2f 2a 20 66 75 6e 63 |l. */..../* func| 00000320 74 69 6f 6e 20 78 28 74 29 20 62 61 63 6b 2e 20 |tion x(t) back. | 00000330 09 09 09 09 09 09 09 09 20 2a 2f 0a 09 09 09 2f |........ */..../| 00000340 2a 20 46 6f 72 20 65 61 63 68 20 73 75 63 68 20 |* For each such | 00000350 74 72 69 61 6c 2c 20 74 68 65 20 73 61 6d 70 6c |trial, the sampl| 00000360 65 2c 20 69 74 73 20 44 46 54 20 26 20 74 68 65 |e, its DFT & the| 00000370 20 69 6e 76 65 72 74 65 64 20 44 46 54 20 28 77 | inverted DFT (w| 00000380 68 69 63 68 20 73 68 6f 75 6c 64 09 20 2a 2f 0a |hich should. */.| 00000390 09 09 09 2f 2a 20 6d 61 74 63 68 20 74 68 65 20 |.../* match the | 000003a0 6f 72 69 67 69 6e 61 6c 20 73 61 6d 70 6c 65 29 |original sample)| 000003b0 20 61 72 65 20 67 72 61 70 68 65 64 2e 09 09 09 | are graphed....| 000003c0 09 09 20 2a 2f 0a 09 09 09 2f 2a 20 41 20 6e 75 |.. */..../* A nu| 000003d0 6d 62 65 72 20 6f 66 20 61 64 64 69 74 69 6f 6e |mber of addition| 000003e0 61 6c 20 74 72 69 61 6c 73 20 61 72 65 20 74 68 |al trials are th| 000003f0 65 6e 20 63 6f 6e 64 75 63 74 65 64 20 69 6e 20 |en conducted in | 00000400 77 68 69 63 68 20 74 68 65 20 44 46 54 20 69 73 |which the DFT is| 00000410 20 66 69 6c 74 65 72 65 64 20 2a 2f 0a 09 09 09 | filtered */....| 00000420 2f 2a 20 61 66 74 65 72 20 63 61 6c 63 75 6c 61 |/* after calcula| 00000430 74 69 6f 6e 20 74 6f 20 61 6c 74 65 72 20 74 68 |tion to alter th| 00000440 65 20 6e 61 74 75 72 65 20 6f 66 20 74 68 65 20 |e nature of the | 00000450 69 6e 76 65 72 74 65 64 20 44 46 54 2c 20 63 72 |inverted DFT, cr| 00000460 65 61 74 69 6e 67 20 61 20 66 72 61 63 74 61 6c |eating a fractal| 00000470 20 2a 2f 0a 09 09 09 2f 2a 20 67 72 61 70 68 2e | */..../* graph.| 00000480 09 09 09 09 09 09 09 09 09 20 2a 2f 0a 0a 09 09 |......... */....| 00000490 09 2f 2a 20 4e 6f 74 65 73 20 6f 6e 20 72 65 6c |./* Notes on rel| 000004a0 61 74 69 6f 6e 20 6f 66 20 44 46 54 20 74 6f 20 |ation of DFT to | 000004b0 63 6f 6e 74 69 6e 75 6f 75 73 20 46 54 20 26 20 |continuous FT & | 000004c0 73 6f 6d 65 20 67 6c 6f 62 61 6c 20 76 61 72 69 |some global vari| 000004d0 61 62 6c 65 73 3a 2a 2f 0a 69 6e 74 20 4e 3b 0a |ables:*/.int N;.| 000004e0 69 6e 74 20 6c 69 6d 69 74 3b 09 09 2f 2a 20 41 |int limit;../* A| 000004f0 73 73 75 6d 65 20 78 28 74 29 20 69 73 20 61 70 |ssume x(t) is ap| 00000500 70 72 65 63 69 61 62 6c 79 20 6e 6f 6e 2d 7a 65 |preciably non-ze| 00000510 72 6f 20 6f 6e 6c 79 20 69 6e 20 72 61 6e 67 65 |ro only in range| 00000520 20 30 3c 74 3c 54 2e 09 09 09 20 2a 2f 0a 64 6f | 0<t<T.... */.do| 00000530 75 62 6c 65 20 54 3b 09 09 2f 2a 20 44 65 66 69 |uble T;../* Defi| 00000540 6e 65 20 6c 69 6d 69 74 20 3d 20 6c 6f 67 20 74 |ne limit = log t| 00000550 6f 20 62 61 73 65 20 32 20 6f 66 20 73 61 6d 70 |o base 2 of samp| 00000560 6c 65 20 73 69 7a 65 20 4e 20 28 69 65 20 4e 3d |le size N (ie N=| 00000570 31 3c 3c 6c 69 6d 69 74 29 2e 09 09 20 2a 2f 0a |1<<limit)... */.| 00000580 63 6f 6d 70 6c 65 78 20 2a 64 61 74 61 20 3d 20 |complex *data = | 00000590 30 3b 09 2f 2a 20 57 65 20 74 68 65 6e 20 73 61 |0;./* We then sa| 000005a0 6d 70 6c 65 20 78 28 74 29 20 61 74 20 74 68 65 |mple x(t) at the| 000005b0 20 4e 20 70 6f 69 6e 74 73 3a 20 74 3d 54 72 2f | N points: t=Tr/| 000005c0 4e 20 66 6f 72 20 72 3d 30 2c 2e 2e 2e 2c 28 4e |N for r=0,...,(N| 000005d0 2d 31 29 2c 20 73 74 6f 72 69 6e 67 20 65 61 63 |-1), storing eac| 000005e0 68 09 20 2a 2f 0a 09 09 09 2f 2a 20 76 61 6c 75 |h. */..../* valu| 000005f0 65 20 69 6e 20 64 61 74 61 5b 72 5d 2e 09 09 09 |e in data[r]....| 00000600 09 09 09 09 09 20 2a 2f 0a 09 09 09 2f 2a 20 54 |..... */..../* T| 00000610 68 75 73 20 64 61 74 61 5b 5d 20 73 74 6f 72 65 |hus data[] store| 00000620 73 20 61 6e 20 4e 20 70 6f 69 6e 74 20 73 61 6d |s an N point sam| 00000630 70 6c 65 20 6f 66 20 78 28 74 29 20 6f 76 65 72 |ple of x(t) over| 00000640 20 74 68 65 20 72 61 6e 67 65 20 30 20 74 6f 20 | the range 0 to | 00000650 54 2c 20 61 74 09 20 2a 2f 0a 09 09 09 2f 2a 20 |T, at. */..../* | 00000660 73 61 6d 70 6c 65 20 69 6e 74 65 72 76 61 6c 20 |sample interval | 00000670 54 2f 4e 2e 09 09 09 09 09 09 09 09 20 2a 2f 0a |T/N......... */.| 00000680 09 09 09 2f 2a 20 54 68 65 20 44 46 54 20 41 28 |.../* The DFT A(| 00000690 73 29 20 74 68 65 6e 20 63 6f 72 72 65 73 70 6f |s) then correspo| 000006a0 6e 64 73 20 74 6f 20 74 68 65 20 63 6f 6e 74 69 |nds to the conti| 000006b0 6e 75 6f 75 73 20 74 72 61 6e 73 66 6f 72 6d 20 |nuous transform | 000006c0 61 28 29 20 77 69 74 68 20 61 70 70 72 6f 78 09 |a() with approx.| 000006d0 20 2a 2f 0a 09 09 09 2f 2a 20 61 28 73 2f 54 29 | */..../* a(s/T)| 000006e0 20 3d 20 41 28 73 2b 4e 29 2c 20 66 6f 72 20 73 | = A(s+N), for s| 000006f0 20 3d 20 2d 4e 2f 32 2c 2e 2e 2e 2c 2d 31 09 09 | = -N/2,...,-1..| 00000700 09 09 09 09 20 2a 2f 0a 09 09 09 2f 2a 20 61 28 |.... */..../* a(| 00000710 73 2f 54 29 20 3d 20 41 28 73 29 2c 20 20 20 66 |s/T) = A(s), f| 00000720 6f 72 20 73 20 3d 20 30 2c 2e 2e 2e 2c 28 4e 2f |or s = 0,...,(N/| 00000730 32 2d 31 29 09 09 09 09 09 20 2a 2f 0a 64 6f 75 |2-1)..... */.dou| 00000740 62 6c 65 20 46 3b 09 09 2f 2a 20 48 65 6e 63 65 |ble F;../* Hence| 00000750 20 74 68 65 20 46 54 20 69 73 20 61 70 70 72 6f | the FT is appro| 00000760 78 69 6d 61 74 65 64 20 69 6e 20 74 68 65 20 72 |ximated in the r| 00000770 61 6e 67 65 20 b1 46 2f 32 20 77 68 65 72 65 20 |ange .F/2 where | 00000780 46 20 69 73 20 64 65 66 69 6e 65 64 20 61 73 20 |F is defined as | 00000790 4e 2f 54 2c 09 20 2a 2f 0a 09 09 09 2f 2a 20 61 |N/T,. */..../* a| 000007a0 74 20 4e 20 70 6f 69 6e 74 73 20 73 65 70 61 72 |t N points separ| 000007b0 61 74 65 64 20 62 79 20 66 72 65 71 75 65 6e 63 |ated by frequenc| 000007c0 79 20 69 6e 74 65 72 76 61 6c 20 31 2f 54 2e 09 |y interval 1/T..| 000007d0 09 09 09 20 2a 2f 0a 63 68 61 72 20 2a 66 6e 5f |... */.char *fn_| 000007e0 64 65 73 63 3b 0a 63 68 61 72 20 2a 66 74 5f 64 |desc;.char *ft_d| 000007f0 65 73 63 3b 0a 63 68 61 72 20 69 74 5f 64 65 73 |esc;.char it_des| 00000800 63 5b 32 35 36 5d 3b 0a 0a 65 78 74 65 72 6e 20 |c[256];..extern | 00000810 69 6e 74 20 72 62 62 63 69 6e 63 28 69 6e 74 20 |int rbbcinc(int | 00000820 72 2c 20 69 6e 74 20 6b 29 3b 0a 65 78 74 65 72 |r, int k);.exter| 00000830 6e 20 69 6e 74 20 64 69 76 5f 66 72 61 63 31 36 |n int div_frac16| 00000840 28 69 6e 74 20 6e 75 6d 62 65 72 2c 20 69 6e 74 |(int number, int| 00000850 20 64 69 76 69 73 6f 72 29 3b 0a 65 78 74 65 72 | divisor);.exter| 00000860 6e 20 69 6e 74 20 6d 75 6c 5f 66 72 61 63 31 36 |n int mul_frac16| 00000870 28 69 6e 74 20 78 2c 20 69 6e 74 20 61 29 3b 0a |(int x, int a);.| 00000880 65 78 74 65 72 6e 20 69 6e 74 20 6d 75 6c 5f 66 |extern int mul_f| 00000890 72 61 63 31 36 63 28 69 6e 74 20 78 2c 20 69 6e |rac16c(int x, in| 000008a0 74 20 61 29 3b 0a 65 78 74 65 72 6e 20 69 6e 74 |t a);.extern int| 000008b0 20 73 71 72 74 5f 66 72 61 63 32 38 28 75 6e 73 | sqrt_frac28(uns| 000008c0 69 67 6e 65 64 20 69 6e 74 20 78 29 3b 0a 65 78 |igned int x);.ex| 000008d0 74 65 72 6e 20 69 6e 74 20 67 61 75 73 73 31 36 |tern int gauss16| 000008e0 28 76 6f 69 64 29 3b 0a 65 78 74 65 72 6e 20 76 |(void);.extern v| 000008f0 6f 69 64 20 73 67 61 75 73 73 31 36 28 69 6e 74 |oid sgauss16(int| 00000900 20 73 65 65 64 29 3b 0a 0a 42 4f 4f 4c 20 66 66 | seed);..BOOL ff| 00000910 74 5f 31 64 28 63 6f 6d 70 6c 65 78 20 2a 64 61 |t_1d(complex *da| 00000920 74 61 2c 20 69 6e 74 20 6c 69 6d 69 74 2c 20 69 |ta, int limit, i| 00000930 6e 74 20 73 69 67 6e 29 0a 7b 0a 20 20 69 6e 74 |nt sign).{. int| 00000940 20 69 2c 20 6a 3b 0a 20 20 69 6e 74 20 6e 20 3d | i, j;. int n =| 00000950 20 31 3c 3c 6c 69 6d 69 74 3b 0a 20 20 63 6f 6d | 1<<limit;. com| 00000960 70 6c 65 78 20 74 31 3b 0a 20 20 69 6e 74 20 74 |plex t1;. int t| 00000970 32 3b 0a 20 20 69 6e 74 20 6b 2c 20 6c 3b 0a 20 |2;. int k, l;. | 00000980 20 69 6e 74 20 6c 6f 6f 70 3b 0a 20 20 69 6e 74 | int loop;. int| 00000990 20 72 6f 74 63 2c 20 72 6f 74 73 3b 0a 20 20 69 | rotc, rots;. i| 000009a0 6e 74 20 63 6f 73 2c 20 73 69 6e 3b 0a 0a 20 20 |nt cos, sin;.. | 000009b0 69 66 20 28 6c 69 6d 69 74 3c 32 20 7c 7c 20 6c |if (limit<2 || l| 000009c0 69 6d 69 74 3e 33 32 29 20 72 65 74 75 72 6e 20 |imit>32) return | 000009d0 46 41 4c 53 45 3b 0a 0a 20 20 66 6f 72 20 28 69 |FALSE;.. for (i| 000009e0 3d 6a 3d 30 3b 20 6a 3c 6e 3b 20 69 3d 72 62 62 |=j=0; j<n; i=rbb| 000009f0 63 69 6e 63 28 69 2c 20 6c 69 6d 69 74 29 2c 20 |cinc(i, limit), | 00000a00 6a 2b 2b 29 20 69 66 20 28 69 3e 6a 29 20 7b 0a |j++) if (i>j) {.| 00000a10 20 20 20 20 74 31 20 3d 20 64 61 74 61 5b 69 5d | t1 = data[i]| 00000a20 3b 0a 20 20 20 20 64 61 74 61 5b 69 5d 20 3d 20 |;. data[i] = | 00000a30 64 61 74 61 5b 6a 5d 3b 0a 20 20 20 20 64 61 74 |data[j];. dat| 00000a40 61 5b 6a 5d 20 3d 20 74 31 3b 0a 20 20 7d 0a 0a |a[j] = t1;. }..| 00000a50 20 20 72 6f 74 63 20 3d 20 2d 72 6f 74 6f 6e 65 | rotc = -rotone| 00000a60 3b 0a 20 20 72 6f 74 73 20 3d 20 20 30 3b 0a 20 |;. rots = 0;. | 00000a70 20 66 6f 72 20 28 6b 3d 6c 6f 6f 70 3d 31 3b 20 | for (k=loop=1; | 00000a80 6c 6f 6f 70 3c 3d 6c 69 6d 69 74 3b 20 6c 6f 6f |loop<=limit; loo| 00000a90 70 2b 2b 2c 20 6b 3c 3c 3d 31 2c 20 72 6f 74 73 |p++, k<<=1, rots| 00000aa0 3d 73 71 72 74 5f 66 72 61 63 32 38 28 28 72 6f |=sqrt_frac28((ro| 00000ab0 74 6f 6e 65 2d 72 6f 74 63 29 2f 32 29 2c 20 72 |tone-rotc)/2), r| 00000ac0 6f 74 63 3d 73 71 72 74 5f 66 72 61 63 32 38 28 |otc=sqrt_frac28(| 00000ad0 28 72 6f 74 6f 6e 65 2b 72 6f 74 63 29 2f 32 29 |(rotone+rotc)/2)| 00000ae0 2c 0a 09 09 09 09 09 20 72 6f 74 73 3d 73 69 67 |,...... rots=sig| 00000af0 6e 3c 30 3f 2d 72 6f 74 73 3a 72 6f 74 73 29 09 |n<0?-rots:rots).| 00000b00 09 09 09 09 20 7b 0a 20 20 20 20 66 6f 72 20 28 |.... {. for (| 00000b10 73 69 6e 3d 30 2c 20 63 6f 73 3d 6f 6e 65 2c 20 |sin=0, cos=one, | 00000b20 69 3d 31 3b 20 69 3c 3d 6b 3b 20 69 2b 2b 2c 20 |i=1; i<=k; i++, | 00000b30 74 32 20 3d 6d 75 6c 5f 66 72 61 63 31 36 63 28 |t2 =mul_frac16c(| 00000b40 63 6f 73 2c 20 72 6f 74 63 2f 72 6f 74 73 63 61 |cos, rotc/rotsca| 00000b50 6c 65 29 2d 6d 75 6c 5f 66 72 61 63 31 36 63 28 |le)-mul_frac16c(| 00000b60 73 69 6e 2c 20 72 6f 74 73 2f 72 6f 74 73 63 61 |sin, rots/rotsca| 00000b70 6c 65 29 2c 0a 09 09 09 09 09 20 73 69 6e 3d 6d |le),...... sin=m| 00000b80 75 6c 5f 66 72 61 63 31 36 63 28 73 69 6e 2c 20 |ul_frac16c(sin, | 00000b90 72 6f 74 63 2f 72 6f 74 73 63 61 6c 65 29 2b 6d |rotc/rotscale)+m| 00000ba0 75 6c 5f 66 72 61 63 31 36 63 28 63 6f 73 2c 20 |ul_frac16c(cos, | 00000bb0 72 6f 74 73 2f 72 6f 74 73 63 61 6c 65 29 2c 20 |rots/rotscale), | 00000bc0 63 6f 73 3d 74 32 29 20 7b 0a 20 20 20 20 20 20 |cos=t2) {. | 00000bd0 66 6f 72 20 28 6a 3d 69 2d 31 3b 20 6a 3c 6e 3b |for (j=i-1; j<n;| 00000be0 20 6a 2b 3d 6b 3c 3c 31 29 20 7b 0a 20 20 20 20 | j+=k<<1) {. | 00000bf0 20 20 20 20 6c 20 3d 20 6a 2b 6b 3b 0a 20 20 20 | l = j+k;. | 00000c00 20 20 20 20 20 74 31 2e 72 65 20 3d 20 6d 75 6c | t1.re = mul| 00000c10 5f 66 72 61 63 31 36 63 28 64 61 74 61 5b 6c 5d |_frac16c(data[l]| 00000c20 2e 72 65 2c 20 63 6f 73 29 2d 6d 75 6c 5f 66 72 |.re, cos)-mul_fr| 00000c30 61 63 31 36 63 28 64 61 74 61 5b 6c 5d 2e 69 6d |ac16c(data[l].im| 00000c40 2c 20 73 69 6e 29 3b 0a 20 20 20 20 20 20 20 20 |, sin);. | 00000c50 74 31 2e 69 6d 20 3d 20 6d 75 6c 5f 66 72 61 63 |t1.im = mul_frac| 00000c60 31 36 63 28 64 61 74 61 5b 6c 5d 2e 72 65 2c 20 |16c(data[l].re, | 00000c70 73 69 6e 29 2b 6d 75 6c 5f 66 72 61 63 31 36 63 |sin)+mul_frac16c| 00000c80 28 64 61 74 61 5b 6c 5d 2e 69 6d 2c 20 63 6f 73 |(data[l].im, cos| 00000c90 29 3b 0a 20 20 20 20 20 20 20 20 64 61 74 61 5b |);. data[| 00000ca0 6c 5d 2e 72 65 20 20 3d 20 64 61 74 61 5b 6a 5d |l].re = data[j]| 00000cb0 2e 72 65 2d 74 31 2e 72 65 3b 0a 20 20 20 20 20 |.re-t1.re;. | 00000cc0 20 20 20 64 61 74 61 5b 6c 5d 2e 69 6d 20 20 3d | data[l].im =| 00000cd0 20 64 61 74 61 5b 6a 5d 2e 69 6d 2d 74 31 2e 69 | data[j].im-t1.i| 00000ce0 6d 3b 0a 20 20 20 20 20 20 20 20 64 61 74 61 5b |m;. data[| 00000cf0 6a 5d 2e 72 65 20 2b 3d 20 74 31 2e 72 65 3b 0a |j].re += t1.re;.| 00000d00 20 20 20 20 20 20 20 20 64 61 74 61 5b 6a 5d 2e | data[j].| 00000d10 69 6d 20 2b 3d 20 74 31 2e 69 6d 3b 0a 20 20 20 |im += t1.im;. | 00000d20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 7d 0a 0a | }. }. }..| 00000d30 20 20 72 65 74 75 72 6e 20 54 52 55 45 3b 0a 7d | return TRUE;.}| 00000d40 0a 0a 42 4f 4f 4c 20 73 63 61 6c 65 28 63 6f 6d |..BOOL scale(com| 00000d50 70 6c 65 78 20 2a 64 61 74 61 2c 20 69 6e 74 20 |plex *data, int | 00000d60 6c 69 6d 69 74 2c 20 69 6e 74 20 73 29 0a 7b 0a |limit, int s).{.| 00000d70 20 20 69 6e 74 20 6e 3d 31 3c 3c 6c 69 6d 69 74 | int n=1<<limit| 00000d80 3b 0a 20 20 69 6e 74 20 69 3b 0a 0a 20 20 66 6f |;. int i;.. fo| 00000d90 72 20 28 69 3d 30 3b 20 69 3c 6e 3b 20 69 2b 2b |r (i=0; i<n; i++| 00000da0 29 20 7b 0a 20 20 20 20 64 61 74 61 5b 69 5d 2e |) {. data[i].| 00000db0 72 65 20 3d 20 6d 75 6c 5f 66 72 61 63 31 36 28 |re = mul_frac16(| 00000dc0 64 61 74 61 5b 69 5d 2e 72 65 2c 20 73 29 3b 0a |data[i].re, s);.| 00000dd0 20 20 20 20 64 61 74 61 5b 69 5d 2e 69 6d 20 3d | data[i].im =| 00000de0 20 6d 75 6c 5f 66 72 61 63 31 36 28 64 61 74 61 | mul_frac16(data| 00000df0 5b 69 5d 2e 69 6d 2c 20 73 29 3b 0a 20 20 7d 0a |[i].im, s);. }.| 00000e00 0a 20 20 72 65 74 75 72 6e 20 54 52 55 45 3b 0a |. return TRUE;.| 00000e10 7d 0a 0a 42 4f 4f 4c 20 66 69 6c 74 65 72 28 63 |}..BOOL filter(c| 00000e20 6f 6d 70 6c 65 78 20 2a 64 61 74 61 2c 20 69 6e |omplex *data, in| 00000e30 74 20 6c 69 6d 69 74 2c 20 64 6f 75 62 6c 65 20 |t limit, double | 00000e40 64 69 6d 65 6e 73 69 6f 6e 29 0a 7b 0a 20 20 69 |dimension).{. i| 00000e50 6e 74 20 6e 3d 31 3c 3c 6c 69 6d 69 74 3b 0a 20 |nt n=1<<limit;. | 00000e60 20 69 6e 74 20 69 2c 20 6b 3b 0a 20 20 64 6f 75 | int i, k;. dou| 00000e70 62 6c 65 20 6d 62 62 74 20 3d 20 2d 28 32 2e 35 |ble mbbt = -(2.5| 00000e80 2d 64 69 6d 65 6e 73 69 6f 6e 29 3b 0a 20 20 69 |-dimension);. i| 00000e90 6e 74 20 73 63 61 6c 65 3b 0a 0a 20 20 66 6f 72 |nt scale;.. for| 00000ea0 20 28 69 3d 30 3b 20 69 3c 6e 3b 20 69 2b 2b 29 | (i=0; i<n; i++)| 00000eb0 20 7b 0a 20 20 20 20 69 66 20 28 69 3d 3d 30 29 | {. if (i==0)| 00000ec0 20 73 63 61 6c 65 3d 30 3b 0a 20 20 20 20 65 6c | scale=0;. el| 00000ed0 73 65 20 7b 0a 20 20 20 20 20 20 6b 20 3d 20 69 |se {. k = i| 00000ee0 3c 6e 2f 32 20 3f 20 69 20 3a 20 6e 2d 69 3b 0a |<n/2 ? i : n-i;.| 00000ef0 20 20 20 20 20 20 73 63 61 6c 65 20 3d 20 28 69 | scale = (i| 00000f00 6e 74 29 28 6f 6e 65 2a 70 6f 77 28 28 64 6f 75 |nt)(one*pow((dou| 00000f10 62 6c 65 29 6b 2c 20 6d 62 62 74 29 29 3b 0a 20 |ble)k, mbbt));. | 00000f20 20 20 20 7d 0a 20 20 20 20 64 61 74 61 5b 69 5d | }. data[i]| 00000f30 2e 72 65 20 3d 20 6d 75 6c 5f 66 72 61 63 31 36 |.re = mul_frac16| 00000f40 28 64 61 74 61 5b 69 5d 2e 72 65 2c 20 73 63 61 |(data[i].re, sca| 00000f50 6c 65 29 3b 0a 20 20 20 20 64 61 74 61 5b 69 5d |le);. data[i]| 00000f60 2e 69 6d 20 3d 20 6d 75 6c 5f 66 72 61 63 31 36 |.im = mul_frac16| 00000f70 28 64 61 74 61 5b 69 5d 2e 69 6d 2c 20 73 63 61 |(data[i].im, sca| 00000f80 6c 65 29 3b 0a 20 20 7d 0a 0a 20 20 72 65 74 75 |le);. }.. retu| 00000f90 72 6e 20 54 52 55 45 3b 0a 7d 0a 0a 64 6f 75 62 |rn TRUE;.}..doub| 00000fa0 6c 65 20 61 73 73 69 67 6e 28 63 6f 6d 70 6c 65 |le assign(comple| 00000fb0 78 20 2a 64 61 74 61 2c 20 69 6e 74 20 6c 69 6d |x *data, int lim| 00000fc0 69 74 2c 20 69 6e 74 20 66 75 6e 63 74 69 6f 6e |it, int function| 00000fd0 29 0a 7b 0a 20 20 69 6e 74 20 6e 3d 31 3c 3c 6c |).{. int n=1<<l| 00000fe0 69 6d 69 74 3b 0a 20 20 69 6e 74 20 69 3b 0a 20 |imit;. int i;. | 00000ff0 20 64 6f 75 62 6c 65 20 54 3b 0a 20 20 64 6f 75 | double T;. dou| 00001000 62 6c 65 20 64 69 6d 3b 0a 0a 20 20 73 77 69 74 |ble dim;.. swit| 00001010 63 68 20 28 66 75 6e 63 74 69 6f 6e 29 0a 20 20 |ch (function). | 00001020 7b 0a 20 20 20 20 63 61 73 65 20 30 3a 0a 20 20 |{. case 0:. | 00001030 20 20 20 20 54 20 3d 20 31 3b 0a 20 20 20 20 20 | T = 1;. | 00001040 20 66 6e 5f 64 65 73 63 20 3d 20 22 73 69 6e 65 | fn_desc = "sine| 00001050 20 77 61 76 65 20 70 61 63 6b 65 74 22 3b 0a 20 | wave packet";. | 00001060 20 20 20 20 20 66 74 5f 64 65 73 63 20 3d 20 22 | ft_desc = "| 00001070 22 3b 0a 20 20 20 20 20 20 2a 69 74 5f 64 65 73 |";. *it_des| 00001080 63 20 3d 20 30 3b 0a 20 20 20 20 20 20 66 6f 72 |c = 0;. for| 00001090 20 28 69 3d 30 3b 20 69 3c 6e 3b 20 69 2b 2b 29 | (i=0; i<n; i++)| 000010a0 20 7b 0a 20 20 20 20 20 20 20 20 64 61 74 61 5b | {. data[| 000010b0 69 5d 2e 72 65 20 3d 20 28 69 6e 74 29 28 6f 6e |i].re = (int)(on| 000010c0 65 2a 28 64 6f 75 62 6c 65 29 73 69 6e 28 36 2e |e*(double)sin(6.| 000010d0 32 38 33 31 38 35 33 30 37 2a 69 2a 54 2f 6e 29 |283185307*i*T/n)| 000010e0 29 3b 0a 20 20 20 20 20 20 20 20 64 61 74 61 5b |);. data[| 000010f0 69 5d 2e 69 6d 20 3d 20 30 3b 0a 20 20 20 20 20 |i].im = 0;. | 00001100 20 7d 0a 20 20 20 20 20 20 62 72 65 61 6b 3b 0a | }. break;.| 00001110 20 20 20 20 63 61 73 65 20 31 3a 0a 20 20 20 20 | case 1:. | 00001120 20 20 54 20 3d 20 35 3b 0a 20 20 20 20 20 20 66 | T = 5;. f| 00001130 6e 5f 64 65 73 63 20 3d 20 22 64 61 6d 70 65 64 |n_desc = "damped| 00001140 20 73 69 6e 65 20 77 61 76 65 22 3b 0a 20 20 20 | sine wave";. | 00001150 20 20 20 66 74 5f 64 65 73 63 20 3d 20 22 22 3b | ft_desc = "";| 00001160 0a 20 20 20 20 20 20 2a 69 74 5f 64 65 73 63 20 |. *it_desc | 00001170 3d 20 30 3b 0a 20 20 20 20 20 20 66 6f 72 20 28 |= 0;. for (| 00001180 69 3d 30 3b 20 69 3c 6e 3b 20 69 2b 2b 29 20 7b |i=0; i<n; i++) {| 00001190 0a 20 20 20 20 20 20 20 20 64 61 74 61 5b 69 5d |. data[i]| 000011a0 2e 72 65 20 3d 20 69 3d 3d 30 20 3f 20 6f 6e 65 |.re = i==0 ? one| 000011b0 20 3a 20 28 69 6e 74 29 28 6f 6e 65 2a 28 64 6f | : (int)(one*(do| 000011c0 75 62 6c 65 29 73 69 6e 28 36 2e 32 38 33 31 38 |uble)sin(6.28318| 000011d0 35 33 30 37 2a 69 2a 54 2f 6e 29 2f 28 36 2e 32 |5307*i*T/n)/(6.2| 000011e0 38 33 31 38 35 33 30 37 2a 69 2a 54 2f 6e 29 29 |83185307*i*T/n))| 000011f0 3b 0a 20 20 20 20 20 20 20 20 64 61 74 61 5b 69 |;. data[i| 00001200 5d 2e 69 6d 20 3d 20 30 3b 0a 20 20 20 20 20 20 |].im = 0;. | 00001210 7d 0a 20 20 20 20 20 20 62 72 65 61 6b 3b 0a 20 |}. break;. | 00001220 20 20 20 63 61 73 65 20 32 3a 0a 20 20 20 20 20 | case 2:. | 00001230 20 54 20 3d 20 31 3b 0a 20 20 20 20 20 20 66 6e | T = 1;. fn| 00001240 5f 64 65 73 63 20 3d 20 22 73 71 75 61 72 65 20 |_desc = "square | 00001250 77 61 76 65 20 70 61 63 6b 65 74 22 3b 0a 20 20 |wave packet";. | 00001260 20 20 20 20 66 74 5f 64 65 73 63 20 3d 20 22 22 | ft_desc = ""| 00001270 3b 0a 20 20 20 20 20 20 2a 69 74 5f 64 65 73 63 |;. *it_desc| 00001280 20 3d 20 30 3b 0a 20 20 20 20 20 20 66 6f 72 20 | = 0;. for | 00001290 28 69 3d 30 3b 20 69 3c 6e 3b 20 69 2b 2b 29 20 |(i=0; i<n; i++) | 000012a0 7b 0a 20 20 20 20 20 20 20 20 64 61 74 61 5b 69 |{. data[i| 000012b0 5d 2e 72 65 20 3d 20 69 3c 6e 2f 32 20 3f 20 6f |].re = i<n/2 ? o| 000012c0 6e 65 20 3a 20 30 3b 0a 20 20 20 20 20 20 20 20 |ne : 0;. | 000012d0 64 61 74 61 5b 69 5d 2e 69 6d 20 3d 20 30 3b 0a |data[i].im = 0;.| 000012e0 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 62 72 | }. br| 000012f0 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 33 3a |eak;. case 3:| 00001300 0a 20 20 20 20 20 20 54 20 3d 20 31 3b 0a 20 20 |. T = 1;. | 00001310 20 20 20 20 66 6e 5f 64 65 73 63 20 3d 20 22 77 | fn_desc = "w| 00001320 68 69 74 65 20 6e 6f 69 73 65 22 3b 0a 20 20 20 |hite noise";. | 00001330 20 20 20 66 74 5f 64 65 73 63 20 3d 20 22 22 3b | ft_desc = "";| 00001340 0a 20 20 20 20 20 20 2a 69 74 5f 64 65 73 63 20 |. *it_desc | 00001350 3d 20 30 3b 0a 20 20 20 20 20 20 66 6f 72 20 28 |= 0;. for (| 00001360 69 3d 30 3b 20 69 3c 6e 3b 20 69 2b 2b 29 20 7b |i=0; i<n; i++) {| 00001370 0a 20 20 20 20 20 20 20 20 64 61 74 61 5b 69 5d |. data[i]| 00001380 2e 72 65 20 3d 20 28 72 61 6e 64 28 29 3e 3e 31 |.re = (rand()>>1| 00001390 35 29 2d 6f 6e 65 2f 32 3b 0a 20 20 20 20 20 20 |5)-one/2;. | 000013a0 20 20 64 61 74 61 5b 69 5d 2e 69 6d 20 3d 20 30 | data[i].im = 0| 000013b0 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 |;. }. | 000013c0 62 72 65 61 6b 3b 0a 20 20 20 20 63 61 73 65 20 |break;. case | 000013d0 34 3a 0a 20 20 20 20 20 20 54 20 3d 20 31 3b 0a |4:. T = 1;.| 000013e0 20 20 20 20 20 20 66 6e 5f 64 65 73 63 20 3d 20 | fn_desc = | 000013f0 22 67 61 75 73 73 69 61 6e 20 77 68 69 74 65 20 |"gaussian white | 00001400 6e 6f 69 73 65 22 3b 0a 20 20 20 20 20 20 66 74 |noise";. ft| 00001410 5f 64 65 73 63 20 3d 20 22 22 3b 0a 20 20 20 20 |_desc = "";. | 00001420 20 20 2a 69 74 5f 64 65 73 63 20 3d 20 30 3b 0a | *it_desc = 0;.| 00001430 20 20 20 20 20 20 66 6f 72 20 28 69 3d 30 3b 20 | for (i=0; | 00001440 69 3c 6e 3b 20 69 2b 2b 29 20 7b 0a 20 20 20 20 |i<n; i++) {. | 00001450 20 20 20 20 64 61 74 61 5b 69 5d 2e 72 65 20 3d | data[i].re =| 00001460 20 67 61 75 73 73 31 36 28 29 3b 0a 20 20 20 20 | gauss16();. | 00001470 20 20 20 20 64 61 74 61 5b 69 5d 2e 69 6d 20 3d | data[i].im =| 00001480 20 30 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 | 0;. }. | 00001490 20 20 62 72 65 61 6b 3b 0a 20 20 20 20 64 65 66 | break;. def| 000014a0 61 75 6c 74 3a 20 2f 2a 66 6f 72 20 36 20 63 61 |ault: /*for 6 ca| 000014b0 73 65 73 2c 20 35 2d 31 30 2a 2f 0a 20 20 20 20 |ses, 5-10*/. | 000014c0 20 20 54 20 3d 20 31 3b 0a 20 20 20 20 20 20 66 | T = 1;. f| 000014d0 6e 5f 64 65 73 63 20 3d 20 22 67 61 75 73 73 69 |n_desc = "gaussi| 000014e0 61 6e 20 77 68 69 74 65 20 6e 6f 69 73 65 22 3b |an white noise";| 000014f0 0a 20 20 20 20 20 20 66 74 5f 64 65 73 63 20 3d |. ft_desc =| 00001500 20 22 46 69 6c 74 65 72 65 64 20 62 79 20 31 2f | "Filtered by 1/| 00001510 28 66 5e 6b 29 22 3b 0a 20 20 20 20 20 20 64 69 |(f^k)";. di| 00001520 6d 20 3d 20 64 69 6d 73 6e 28 66 75 6e 63 74 69 |m = dimsn(functi| 00001530 6f 6e 29 3b 0a 20 20 20 20 20 20 73 70 72 69 6e |on);. sprin| 00001540 74 66 28 69 74 5f 64 65 73 63 2c 20 22 6b 20 3d |tf(it_desc, "k =| 00001550 20 25 2e 33 66 2c 20 46 72 61 63 74 61 6c 20 64 | %.3f, Fractal d| 00001560 69 6d 2e 20 3d 20 25 2e 33 66 22 2c 20 32 2e 35 |im. = %.3f", 2.5| 00001570 2d 64 69 6d 2c 20 64 69 6d 29 3b 0a 20 20 20 20 |-dim, dim);. | 00001580 20 20 66 6f 72 20 28 69 3d 30 3b 20 69 3c 6e 3b | for (i=0; i<n;| 00001590 20 69 2b 2b 29 20 7b 0a 20 20 20 20 20 20 20 20 | i++) {. | 000015a0 64 61 74 61 5b 69 5d 2e 72 65 20 3d 20 67 61 75 |data[i].re = gau| 000015b0 73 73 31 36 28 29 3b 0a 20 20 20 20 20 20 20 20 |ss16();. | 000015c0 64 61 74 61 5b 69 5d 2e 69 6d 20 3d 20 30 3b 0a |data[i].im = 0;.| 000015d0 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 62 72 | }. br| 000015e0 65 61 6b 3b 0a 20 20 7d 0a 0a 20 20 72 65 74 75 |eak;. }.. retu| 000015f0 72 6e 20 54 3b 0a 7d 0a 0a 23 64 65 66 69 6e 65 |rn T;.}..#define| 00001600 20 72 65 6f 72 64 65 72 28 69 2c 20 6e 2c 20 66 | reorder(i, n, f| 00001610 6c 61 67 29 20 28 28 66 6c 61 67 29 20 3f 20 28 |lag) ((flag) ? (| 00001620 28 69 29 3c 28 6e 29 2f 32 20 3f 20 28 69 29 2b |(i)<(n)/2 ? (i)+| 00001630 28 6e 29 2f 32 20 3a 20 28 69 29 2d 28 6e 29 2f |(n)/2 : (i)-(n)/| 00001640 32 29 20 3a 20 28 69 29 29 0a 23 64 65 66 69 6e |2) : (i)).#defin| 00001650 65 20 79 73 63 61 6c 65 20 31 32 34 0a 0a 42 4f |e yscale 124..BO| 00001660 4f 4c 20 67 72 61 70 68 28 63 6f 6d 70 6c 65 78 |OL graph(complex| 00001670 20 2a 64 61 74 61 2c 20 69 6e 74 20 6c 69 6d 69 | *data, int limi| 00001680 74 2c 20 69 6e 74 20 79 6f 2c 20 42 4f 4f 4c 20 |t, int yo, BOOL | 00001690 72 65 70 6f 73 2c 20 63 68 61 72 20 2a 74 65 78 |repos, char *tex| 000016a0 74 2c 20 2e 2e 2e 29 0a 7b 0a 20 20 69 6e 74 20 |t, ...).{. int | 000016b0 6e 3d 31 3c 3c 6c 69 6d 69 74 3b 0a 20 20 69 6e |n=1<<limit;. in| 000016c0 74 20 69 3b 0a 20 20 69 6e 74 20 6d 69 6e 3d 31 |t i;. int min=1| 000016d0 3c 3c 33 30 3b 0a 20 20 69 6e 74 20 6d 61 78 3d |<<30;. int max=| 000016e0 2d 6d 69 6e 3b 0a 20 20 69 6e 74 20 73 63 61 6c |-min;. int scal| 000016f0 65 3b 0a 20 20 76 61 5f 6c 69 73 74 20 61 72 67 |e;. va_list arg| 00001700 70 3b 0a 0a 20 20 66 6f 72 20 28 69 3d 30 3b 20 |p;.. for (i=0; | 00001710 69 3c 6e 3b 20 69 2b 2b 29 20 7b 0a 20 20 20 20 |i<n; i++) {. | 00001720 69 66 20 28 64 61 74 61 5b 69 5d 2e 72 65 3c 6d |if (data[i].re<m| 00001730 69 6e 29 20 6d 69 6e 3d 64 61 74 61 5b 69 5d 2e |in) min=data[i].| 00001740 72 65 3b 0a 20 20 20 20 69 66 20 28 64 61 74 61 |re;. if (data| 00001750 5b 69 5d 2e 69 6d 3c 6d 69 6e 29 20 6d 69 6e 3d |[i].im<min) min=| 00001760 64 61 74 61 5b 69 5d 2e 69 6d 3b 0a 20 20 20 20 |data[i].im;. | 00001770 69 66 20 28 64 61 74 61 5b 69 5d 2e 72 65 3e 6d |if (data[i].re>m| 00001780 61 78 29 20 6d 61 78 3d 64 61 74 61 5b 69 5d 2e |ax) max=data[i].| 00001790 72 65 3b 0a 20 20 20 20 69 66 20 28 64 61 74 61 |re;. if (data| 000017a0 5b 69 5d 2e 69 6d 3e 6d 61 78 29 20 6d 61 78 3d |[i].im>max) max=| 000017b0 64 61 74 61 5b 69 5d 2e 69 6d 3b 0a 20 20 7d 0a |data[i].im;. }.| 000017c0 20 20 6d 61 78 20 3d 20 6d 61 78 3e 30 20 3f 20 | max = max>0 ? | 000017d0 6d 61 78 20 3a 20 2d 6d 61 78 3b 0a 20 20 6d 69 |max : -max;. mi| 000017e0 6e 20 3d 20 6d 69 6e 3e 30 20 3f 20 6d 69 6e 20 |n = min>0 ? min | 000017f0 3a 20 2d 6d 69 6e 3b 0a 20 20 73 63 61 6c 65 20 |: -min;. scale | 00001800 3d 20 6d 61 78 3e 6d 69 6e 20 3f 20 6d 61 78 20 |= max>min ? max | 00001810 3a 20 6d 69 6e 3b 0a 20 20 69 66 20 28 73 63 61 |: min;. if (sca| 00001820 6c 65 3d 3d 30 29 20 73 63 61 6c 65 3d 31 3b 0a |le==0) scale=1;.| 00001830 0a 20 20 62 62 63 5f 6f 72 69 67 69 6e 28 36 34 |. bbc_origin(64| 00001840 30 2c 79 6f 29 3b 0a 20 20 62 62 63 5f 70 61 6c |0,yo);. bbc_pal| 00001850 65 74 74 65 28 31 2c 20 31 36 2c 20 35 31 2c 35 |ette(1, 16, 51,5| 00001860 31 2c 35 31 29 3b 0a 20 20 62 62 63 5f 67 63 6f |1,51);. bbc_gco| 00001870 6c 28 30 2c 20 31 29 3b 0a 20 20 62 62 63 5f 72 |l(0, 1);. bbc_r| 00001880 65 63 74 61 6e 67 6c 65 66 69 6c 6c 28 2d 35 31 |ectanglefill(-51| 00001890 37 2c 2d 34 2c 31 30 33 31 2c 39 29 3b 0a 20 20 |7,-4,1031,9);. | 000018a0 62 62 63 5f 72 65 63 74 61 6e 67 6c 65 66 69 6c |bbc_rectanglefil| 000018b0 6c 28 72 65 70 6f 73 3f 2d 35 3a 2d 35 31 37 2c |l(repos?-5:-517,| 000018c0 2d 79 73 63 61 6c 65 2d 34 2c 39 2c 32 2a 79 73 |-yscale-4,9,2*ys| 000018d0 63 61 6c 65 2b 37 29 3b 0a 20 20 62 62 63 5f 76 |cale+7);. bbc_v| 000018e0 64 75 28 35 29 3b 0a 20 20 62 62 63 5f 6d 6f 76 |du(5);. bbc_mov| 000018f0 65 28 28 72 65 70 6f 73 3f 30 3a 2d 35 31 32 29 |e((repos?0:-512)| 00001900 2d 34 34 2c 79 73 63 61 6c 65 2b 34 30 29 3b 0a |-44,yscale+40);.| 00001910 20 20 70 72 69 6e 74 66 28 22 25 2e 33 66 22 2c | printf("%.3f",| 00001920 20 28 64 6f 75 62 6c 65 29 73 63 61 6c 65 2f 6f | (double)scale/o| 00001930 6e 65 29 3b 0a 20 20 62 62 63 5f 6d 6f 76 65 28 |ne);. bbc_move(| 00001940 2d 35 31 32 2b 39 36 2c 79 73 63 61 6c 65 2b 34 |-512+96,yscale+4| 00001950 30 29 3b 0a 20 20 76 61 5f 73 74 61 72 74 28 61 |0);. va_start(a| 00001960 72 67 70 2c 20 74 65 78 74 29 3b 0a 20 20 76 70 |rgp, text);. vp| 00001970 72 69 6e 74 66 28 74 65 78 74 2c 20 61 72 67 70 |rintf(text, argp| 00001980 29 3b 0a 20 20 76 61 5f 65 6e 64 28 61 72 67 70 |);. va_end(argp| 00001990 29 3b 0a 20 20 62 62 63 5f 6d 6f 76 65 28 28 72 |);. bbc_move((r| 000019a0 65 70 6f 73 3f 30 3a 2d 35 31 32 29 2d 36 30 2c |epos?0:-512)-60,| 000019b0 2d 79 73 63 61 6c 65 2d 32 30 29 3b 0a 20 20 70 |-yscale-20);. p| 000019c0 72 69 6e 74 66 28 22 25 2e 33 66 22 2c 20 2d 28 |rintf("%.3f", -(| 000019d0 64 6f 75 62 6c 65 29 73 63 61 6c 65 2f 6f 6e 65 |double)scale/one| 000019e0 29 3b 0a 20 20 62 62 63 5f 6d 6f 76 65 28 2d 35 |);. bbc_move(-5| 000019f0 31 32 2d 31 32 38 2c 6c 69 6e 65 73 65 70 2f 34 |12-128,linesep/4| 00001a00 29 3b 0a 20 20 70 72 69 6e 74 66 28 22 25 2e 33 |);. printf("%.3| 00001a10 66 22 2c 20 72 65 70 6f 73 3f 2d 46 2f 32 3a 30 |f", repos?-F/2:0| 00001a20 2e 30 29 3b 0a 20 20 62 62 63 5f 6d 6f 76 65 28 |.0);. bbc_move(| 00001a30 35 32 30 2c 6c 69 6e 65 73 65 70 2f 34 29 3b 0a |520,linesep/4);.| 00001a40 20 20 70 72 69 6e 74 66 28 22 25 2e 33 66 22 2c | printf("%.3f",| 00001a50 20 72 65 70 6f 73 3f 46 2f 32 3a 54 29 3b 0a 20 | repos?F/2:T);. | 00001a60 20 62 62 63 5f 76 64 75 28 34 29 3b 0a 20 20 62 | bbc_vdu(4);. b| 00001a70 62 63 5f 67 63 6f 6c 28 30 2c 20 32 29 3b 0a 20 |bc_gcol(0, 2);. | 00001a80 20 62 62 63 5f 6d 6f 76 65 28 2d 35 31 32 2c 64 | bbc_move(-512,d| 00001a90 61 74 61 5b 72 65 6f 72 64 65 72 28 30 2c 20 6e |ata[reorder(0, n| 00001aa0 2c 20 72 65 70 6f 73 29 5d 2e 72 65 2a 79 73 63 |, repos)].re*ysc| 00001ab0 61 6c 65 2f 73 63 61 6c 65 29 3b 0a 20 20 66 6f |ale/scale);. fo| 00001ac0 72 20 28 69 3d 31 3b 20 69 3c 6e 3b 20 69 2b 2b |r (i=1; i<n; i++| 00001ad0 29 20 7b 0a 20 20 20 20 62 62 63 5f 70 6c 6f 74 |) {. bbc_plot| 00001ae0 28 31 33 2c 20 69 2a 31 30 32 34 2f 6e 2d 35 31 |(13, i*1024/n-51| 00001af0 32 2c 64 61 74 61 5b 72 65 6f 72 64 65 72 28 69 |2,data[reorder(i| 00001b00 2c 20 6e 2c 20 72 65 70 6f 73 29 5d 2e 72 65 2a |, n, repos)].re*| 00001b10 79 73 63 61 6c 65 2f 73 63 61 6c 65 29 3b 0a 20 |yscale/scale);. | 00001b20 20 7d 0a 20 20 62 62 63 5f 67 63 6f 6c 28 30 2c | }. bbc_gcol(0,| 00001b30 20 33 29 3b 0a 20 20 62 62 63 5f 6d 6f 76 65 28 | 3);. bbc_move(| 00001b40 2d 35 31 32 2c 64 61 74 61 5b 72 65 6f 72 64 65 |-512,data[reorde| 00001b50 72 28 30 2c 20 6e 2c 20 72 65 70 6f 73 29 5d 2e |r(0, n, repos)].| 00001b60 69 6d 2a 79 73 63 61 6c 65 2f 73 63 61 6c 65 29 |im*yscale/scale)| 00001b70 3b 0a 20 20 66 6f 72 20 28 69 3d 31 3b 20 69 3c |;. for (i=1; i<| 00001b80 6e 3b 20 69 2b 2b 29 20 7b 0a 20 20 20 20 62 62 |n; i++) {. bb| 00001b90 63 5f 70 6c 6f 74 28 31 33 2c 20 69 2a 31 30 32 |c_plot(13, i*102| 00001ba0 34 2f 6e 2d 35 31 32 2c 64 61 74 61 5b 72 65 6f |4/n-512,data[reo| 00001bb0 72 64 65 72 28 69 2c 20 6e 2c 20 72 65 70 6f 73 |rder(i, n, repos| 00001bc0 29 5d 2e 69 6d 2a 79 73 63 61 6c 65 2f 73 63 61 |)].im*yscale/sca| 00001bd0 6c 65 29 3b 0a 20 20 7d 0a 0a 20 20 72 65 74 75 |le);. }.. retu| 00001be0 72 6e 20 54 52 55 45 3b 0a 7d 0a 0a 6d 6f 6e 69 |rn TRUE;.}..moni| 00001bf0 74 6f 72 20 72 65 61 64 5f 6d 6f 6e 69 74 6f 72 |tor read_monitor| 00001c00 5f 74 79 70 65 28 76 6f 69 64 29 0a 7b 0a 20 20 |_type(void).{. | 00001c10 69 6e 74 20 72 32 3b 0a 20 20 6f 73 5f 73 77 69 |int r2;. os_swi| 00001c20 33 72 28 36 2c 20 31 36 31 2c 31 33 33 2c 30 2c |3r(6, 161,133,0,| 00001c30 20 30 2c 30 2c 26 72 32 29 3b 0a 20 20 69 66 20 | 0,0,&r2);. if | 00001c40 28 28 72 32 2f 34 20 26 20 33 29 20 3d 3d 20 31 |((r2/4 & 3) == 1| 00001c50 29 20 72 65 74 75 72 6e 20 6d 75 6c 74 69 3b 0a |) return multi;.| 00001c60 20 20 65 6c 73 65 20 72 65 74 75 72 6e 20 6e 6f | else return no| 00001c70 6e 6d 75 6c 74 69 3b 0a 7d 0a 0a 69 6e 74 20 6d |nmulti;.}..int m| 00001c80 61 69 6e 28 76 6f 69 64 29 0a 7b 0a 20 20 69 6e |ain(void).{. in| 00001c90 74 20 66 75 6e 63 74 69 6f 6e 2c 20 73 65 65 64 |t function, seed| 00001ca0 3b 0a 20 20 63 68 61 72 20 64 75 6d 6d 79 3b 0a |;. char dummy;.| 00001cb0 20 20 6d 6f 6e 69 74 6f 72 74 79 70 65 20 3d 20 | monitortype = | 00001cc0 72 65 61 64 5f 6d 6f 6e 69 74 6f 72 5f 74 79 70 |read_monitor_typ| 00001cd0 65 28 29 3b 0a 0a 20 20 66 6f 72 20 28 3b 3b 29 |e();.. for (;;)| 00001ce0 20 7b 0a 0a 20 20 20 20 73 65 65 64 20 3d 20 2d | {.. seed = -| 00001cf0 63 6c 6f 63 6b 28 29 3b 0a 20 20 20 20 64 6f 20 |clock();. do | 00001d00 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 |{. printf("| 00001d10 50 6c 65 61 73 65 20 65 6e 74 65 72 20 70 6f 77 |Please enter pow| 00001d20 65 72 20 28 73 75 67 67 65 73 74 20 37 2d 31 30 |er (suggest 7-10| 00001d30 2c 20 74 68 6f 75 67 68 20 32 2d 31 35 20 70 65 |, though 2-15 pe| 00001d40 72 6d 69 73 73 69 62 6c 65 29 20 22 29 3b 0a 20 |rmissible) ");. | 00001d50 20 20 20 20 20 73 63 61 6e 66 28 22 25 69 22 2c | scanf("%i",| 00001d60 20 26 6c 69 6d 69 74 29 3b 0a 20 20 20 20 7d 20 | &limit);. } | 00001d70 77 68 69 6c 65 20 28 6c 69 6d 69 74 3c 32 20 7c |while (limit<2 || 00001d80 7c 20 6c 69 6d 69 74 3e 31 35 29 3b 0a 20 20 20 || limit>15);. | 00001d90 20 4e 20 3d 20 31 3c 3c 6c 69 6d 69 74 3b 0a 0a | N = 1<<limit;..| 00001da0 20 20 20 20 64 61 74 61 20 3d 20 63 61 6c 6c 6f | data = callo| 00001db0 63 28 4e 2c 20 73 69 7a 65 6f 66 28 63 6f 6d 70 |c(N, sizeof(comp| 00001dc0 6c 65 78 29 29 3b 0a 20 20 20 20 69 66 20 28 64 |lex));. if (d| 00001dd0 61 74 61 3d 3d 30 29 20 77 65 72 72 28 31 2c 20 |ata==0) werr(1, | 00001de0 22 49 6e 73 75 66 66 69 63 69 65 6e 74 20 6d 65 |"Insufficient me| 00001df0 6d 6f 72 79 22 29 3b 0a 0a 20 20 20 20 66 6f 72 |mory");.. for| 00001e00 20 28 66 75 6e 63 74 69 6f 6e 3d 30 3b 20 66 75 | (function=0; fu| 00001e10 6e 63 74 69 6f 6e 3c 31 31 3b 20 66 75 6e 63 74 |nction<11; funct| 00001e20 69 6f 6e 2b 2b 29 20 7b 0a 20 20 20 20 20 20 73 |ion++) {. s| 00001e30 67 61 75 73 73 31 36 28 73 65 65 64 29 3b 0a 20 |gauss16(seed);. | 00001e40 20 20 20 20 20 73 72 61 6e 64 28 73 65 65 64 29 | srand(seed)| 00001e50 3b 0a 20 20 20 20 20 20 62 62 63 5f 6d 6f 64 65 |;. bbc_mode| 00001e60 28 6d 6f 6e 69 74 6f 72 74 79 70 65 3d 3d 6d 75 |(monitortype==mu| 00001e70 6c 74 69 20 3f 20 32 30 20 3a 20 31 32 29 3b 0a |lti ? 20 : 12);.| 00001e80 20 20 20 20 20 20 6c 69 6e 65 73 65 70 20 3d 20 | linesep = | 00001e90 6d 6f 6e 69 74 6f 72 74 79 70 65 3d 3d 6d 75 6c |monitortype==mul| 00001ea0 74 69 20 3f 20 32 30 20 3a 20 34 30 3b 0a 20 20 |ti ? 20 : 40;. | 00001eb0 20 20 20 20 54 3d 61 73 73 69 67 6e 28 64 61 74 | T=assign(dat| 00001ec0 61 2c 20 6c 69 6d 69 74 2c 20 66 75 6e 63 74 69 |a, limit, functi| 00001ed0 6f 6e 29 3b 0a 20 20 20 20 20 20 46 3d 4e 2f 54 |on);. F=N/T| 00001ee0 3b 0a 20 20 20 20 20 20 67 72 61 70 68 28 64 61 |;. graph(da| 00001ef0 74 61 2c 20 6c 69 6d 69 74 2c 20 38 35 32 2c 20 |ta, limit, 852, | 00001f00 46 41 4c 53 45 2c 20 22 53 6f 75 72 63 65 20 66 |FALSE, "Source f| 00001f10 75 6e 63 74 69 6f 6e 20 27 25 73 27 20 20 28 53 |unction '%s' (S| 00001f20 61 6d 70 6c 65 20 73 69 7a 65 20 4e 3d 25 69 29 |ample size N=%i)| 00001f30 22 2c 20 66 6e 5f 64 65 73 63 2c 20 4e 29 3b 0a |", fn_desc, N);.| 00001f40 20 20 20 20 20 20 66 66 74 5f 31 64 28 64 61 74 | fft_1d(dat| 00001f50 61 2c 20 6c 69 6d 69 74 2c 20 31 29 3b 0a 20 20 |a, limit, 1);. | 00001f60 20 20 20 20 73 63 61 6c 65 28 64 61 74 61 2c 20 | scale(data, | 00001f70 6c 69 6d 69 74 2c 20 28 69 6e 74 29 28 6f 6e 65 |limit, (int)(one| 00001f80 2a 54 2f 4e 29 29 3b 0a 20 20 20 20 20 20 69 66 |*T/N));. if| 00001f90 20 28 66 75 6e 63 74 69 6f 6e 3e 34 29 20 66 69 | (function>4) fi| 00001fa0 6c 74 65 72 28 64 61 74 61 2c 20 6c 69 6d 69 74 |lter(data, limit| 00001fb0 2c 20 64 69 6d 73 6e 28 66 75 6e 63 74 69 6f 6e |, dimsn(function| 00001fc0 29 29 3b 0a 20 20 20 20 20 20 67 72 61 70 68 28 |));. graph(| 00001fd0 64 61 74 61 2c 20 6c 69 6d 69 74 2c 20 35 31 32 |data, limit, 512| 00001fe0 2c 20 54 52 55 45 2c 20 22 46 6f 75 72 69 65 72 |, TRUE, "Fourier| 00001ff0 20 54 72 61 6e 73 66 6f 72 6d 20 20 20 20 20 20 | Transform | 00002000 20 20 20 20 20 20 20 20 20 20 20 25 73 22 2c 20 | %s", | 00002010 66 74 5f 64 65 73 63 29 3b 0a 20 20 20 20 20 20 |ft_desc);. | 00002020 66 66 74 5f 31 64 28 64 61 74 61 2c 20 6c 69 6d |fft_1d(data, lim| 00002030 69 74 2c 20 2d 31 29 3b 0a 20 20 20 20 20 20 73 |it, -1);. s| 00002040 63 61 6c 65 28 64 61 74 61 2c 20 6c 69 6d 69 74 |cale(data, limit| 00002050 2c 20 28 69 6e 74 29 28 6f 6e 65 2f 54 29 29 3b |, (int)(one/T));| 00002060 0a 20 20 20 20 20 20 67 72 61 70 68 28 64 61 74 |. graph(dat| 00002070 61 2c 20 6c 69 6d 69 74 2c 20 31 37 32 2c 20 46 |a, limit, 172, F| 00002080 41 4c 53 45 2c 20 22 49 6e 76 65 72 74 65 64 20 |ALSE, "Inverted | 00002090 54 72 61 6e 73 66 6f 72 6d 20 20 20 20 20 20 20 |Transform | 000020a0 20 20 20 20 20 20 20 25 73 22 2c 20 69 74 5f 64 | %s", it_d| 000020b0 65 73 63 29 3b 0a 20 20 20 20 20 20 62 62 63 5f |esc);. bbc_| 000020c0 76 64 75 28 35 29 3b 0a 20 20 20 20 20 20 62 62 |vdu(5);. bb| 000020d0 63 5f 6f 72 69 67 69 6e 28 30 2c 30 29 3b 0a 20 |c_origin(0,0);. | 000020e0 20 20 20 20 20 62 62 63 5f 6d 6f 76 65 28 31 31 | bbc_move(11| 000020f0 35 32 2c 20 31 33 31 29 3b 0a 20 20 20 20 20 20 |52, 131);. | 00002100 70 72 69 6e 74 66 28 22 50 72 65 73 73 20 61 22 |printf("Press a"| 00002110 29 3b 0a 20 20 20 20 20 20 62 62 63 5f 6d 6f 76 |);. bbc_mov| 00002120 65 28 31 31 35 32 2c 20 31 33 31 2d 6c 69 6e 65 |e(1152, 131-line| 00002130 73 65 70 29 3b 0a 20 20 20 20 20 20 70 72 69 6e |sep);. prin| 00002140 74 66 28 22 6b 65 79 20 2e 2e 2e 22 29 3b 0a 20 |tf("key ...");. | 00002150 20 20 20 20 20 62 62 63 5f 76 64 75 28 34 29 3b | bbc_vdu(4);| 00002160 0a 20 20 20 20 20 20 6f 73 5f 63 6c 69 28 22 66 |. os_cli("f| 00002170 78 20 31 35 20 31 22 29 3b 0a 20 20 20 20 20 20 |x 15 1");. | 00002180 62 62 63 5f 63 75 72 73 6f 72 28 30 29 3b 0a 20 |bbc_cursor(0);. | 00002190 20 20 20 20 20 64 75 6d 6d 79 20 3d 20 62 62 63 | dummy = bbc| 000021a0 5f 67 65 74 28 29 3b 0a 20 20 20 20 7d 0a 0a 20 |_get();. }.. | 000021b0 20 20 20 66 72 65 65 28 64 61 74 61 29 3b 0a 20 | free(data);. | 000021c0 20 20 20 62 62 63 5f 63 6c 73 28 29 3b 0a 0a 20 | bbc_cls();.. | 000021d0 7d 0a 0a 20 20 72 65 74 75 72 6e 20 30 3b 0a 7d |}.. return 0;.}| 000021e0 0a |.| 000021e1