diff DFT.cpp @ 16:7e1510b47336 pygar svn.17

[svn r17] added rest of items for core
author punk
date Tue, 27 Apr 2010 22:54:50 -0400
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/DFT.cpp	Tue Apr 27 22:54:50 2010 -0400
     1.3 @@ -0,0 +1,46 @@
     1.4 +#include <stdio.h>
     1.5 +#include <stdlib.h>
     1.6 +#include <math.h>
     1.7 +
     1.8 +
     1.9 +int DFT(int dir,int m,double *x1,double *y1)
    1.10 +{
    1.11 +   long i,k;
    1.12 +   double arg;
    1.13 +   double cosarg,sinarg;
    1.14 +   double *x2=NULL,*y2=NULL;
    1.15 +
    1.16 +   x2 = (double *)(malloc(m*sizeof(double)));
    1.17 +   y2 = (double *)(malloc(m*sizeof(double)));
    1.18 +   if (x2 == NULL || y2 == NULL)
    1.19 +      return 0;
    1.20 +
    1.21 +   for (i=0;i<m;i++) {
    1.22 +      x2[i] = 0;
    1.23 +      y2[i] = 0;
    1.24 +      arg = - dir * 2.0 * 3.141592654 * (double)i / (double)m;
    1.25 +      for (k=0;k<m;k++) {
    1.26 +         cosarg = cos(k * arg);
    1.27 +         sinarg = sin(k * arg);
    1.28 +         x2[i] += (x1[k] * cosarg - y1[k] * sinarg);
    1.29 +         y2[i] += (x1[k] * sinarg + y1[k] * cosarg);
    1.30 +      }
    1.31 +   }
    1.32 +
    1.33 +   /* Copy the data back */
    1.34 +   if (dir == 1) {
    1.35 +      for (i=0;i<m;i++) {
    1.36 +         x1[i] = x2[i];
    1.37 +         y1[i] = y2[i];
    1.38 +      }
    1.39 +   } else {
    1.40 +      for (i=0;i<m;i++) {
    1.41 +         x1[i] = x2[i];
    1.42 +         y1[i] = y2[i];
    1.43 +      }
    1.44 +   }
    1.45 +
    1.46 +   free(x2);
    1.47 +   free(y2);
    1.48 +   return 1;
    1.49 +}