annotate modules/bluespec/Pygar/common/DFT.cpp @ 65:cf8bb3038cbd pygar svn.66

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