annotate DFT.cpp @ 17:9d1f38722f5b pygar svn.18

[svn r18] changed config file to not use mit-6.375 anymore
author rlm
date Tue, 27 Apr 2010 22:55:55 -0400
parents 7e1510b47336
children
rev   line source
punk@16 1 #include <stdio.h>
punk@16 2 #include <stdlib.h>
punk@16 3 #include <math.h>
punk@16 4
punk@16 5
punk@16 6 int DFT(int dir,int m,double *x1,double *y1)
punk@16 7 {
punk@16 8 long i,k;
punk@16 9 double arg;
punk@16 10 double cosarg,sinarg;
punk@16 11 double *x2=NULL,*y2=NULL;
punk@16 12
punk@16 13 x2 = (double *)(malloc(m*sizeof(double)));
punk@16 14 y2 = (double *)(malloc(m*sizeof(double)));
punk@16 15 if (x2 == NULL || y2 == NULL)
punk@16 16 return 0;
punk@16 17
punk@16 18 for (i=0;i<m;i++) {
punk@16 19 x2[i] = 0;
punk@16 20 y2[i] = 0;
punk@16 21 arg = - dir * 2.0 * 3.141592654 * (double)i / (double)m;
punk@16 22 for (k=0;k<m;k++) {
punk@16 23 cosarg = cos(k * arg);
punk@16 24 sinarg = sin(k * arg);
punk@16 25 x2[i] += (x1[k] * cosarg - y1[k] * sinarg);
punk@16 26 y2[i] += (x1[k] * sinarg + y1[k] * cosarg);
punk@16 27 }
punk@16 28 }
punk@16 29
punk@16 30 /* Copy the data back */
punk@16 31 if (dir == 1) {
punk@16 32 for (i=0;i<m;i++) {
punk@16 33 x1[i] = x2[i];
punk@16 34 y1[i] = y2[i];
punk@16 35 }
punk@16 36 } else {
punk@16 37 for (i=0;i<m;i++) {
punk@16 38 x1[i] = x2[i];
punk@16 39 y1[i] = y2[i];
punk@16 40 }
punk@16 41 }
punk@16 42
punk@16 43 free(x2);
punk@16 44 free(y2);
punk@16 45 return 1;
punk@16 46 }