BRL-CAD
fftest.c
Go to the documentation of this file.
1 /* F F T E S T . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libfft/fftest.c
21  *
22  * Complex Number and FFT Library
23  *
24  */
25 
26 #include "common.h"
27 
28 #include <stdio.h>
29 #include <math.h>
30 
31 #include "fft.h"
32 
33 /***** TEST ROUTINES *****/
35 
36 
37 void
38 display(COMPLEX *dat, int num)
39 {
40  int i;
41 
42  for (i = 0; i < num; i++) {
43  printf("%3d : ", i);
44  printf("%f, %f\n", dat[i].re, dat[i].im);
45  }
46 }
47 
48 int
49 main(int ac, char *av[])
50 {
51  extern void cfft(COMPLEX *, int);
52  extern void icfft(COMPLEX *, int);
53 
54  int i;
55 
56  if (ac > 1)
57  fprintf(stderr,"Usage: %s\n", av[0]);
58 
59  for (i = 0; i < 64; i++) {
60 /* Original and simplified expressions in next 4 lines of file you are reading. */
61 /* data[i].re = sin((double)2.0 * M_PI * i / 64.0); */
62  data[i].re = sin( M_PI * (double) i / 32.0);
63 /* data[i].re += 3 * cos((double)2.0 * M_PI * i / 32.0); */
64  data[i].re += 3 * cos( M_PI * (double) i / 16.0);
65  data[i].im = (double)0.0;
66  }
67 
68  printf("Original Data:\n\n");
69  display(data, 64);
70 
71  cfft(data, 64);
72  printf("\n\nTransformed Data:\n\n");
73  display(data, 64);
74 
75  icfft(data, 64);
76  printf("\n\nInversed Data:\n\n");
77  display(data, 64);
78 
79  return 0;
80 }
81 
82 
83 /*
84  * Local Variables:
85  * mode: C
86  * tab-width: 8
87  * indent-tabs-mode: t
88  * c-file-style: "stroustrup"
89  * End:
90  * ex: shiftwidth=4 tabstop=8
91  */
double im
Definition: fft.h:56
#define M_PI
Definition: fft.h:35
Header file for the BRL-CAD common definitions.
COMPLEX data[64]
Definition: fftest.c:34
Definition: fft.h:54
void cfft(COMPLEX *dat, int num)
Definition: fftfast.c:55
void icfft(COMPLEX *dat, int num)
Definition: fftfast.c:73
double re
Definition: fft.h:55
void display(COMPLEX *dat, int num)
Definition: fftest.c:38
int main(int ac, char *av[])
Definition: fftest.c:49