Mercurial > pygar
comparison modules/bluespec/Pygar/common/DFT.cpp @ 8:74716e9a81cc pygar svn.9
[svn r9] Pygar now has the proper directory structure to play nicely with awb. Also, the apm file for audio-core willcompile successfully.
author | rlm |
---|---|
date | Fri, 23 Apr 2010 02:32:05 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:7393cd19371e | 8:74716e9a81cc |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <math.h> | |
4 | |
5 | |
6 int DFT(int dir,int m,double *x1,double *y1) | |
7 { | |
8 long i,k; | |
9 double arg; | |
10 double cosarg,sinarg; | |
11 double *x2=NULL,*y2=NULL; | |
12 | |
13 x2 = (double *)(malloc(m*sizeof(double))); | |
14 y2 = (double *)(malloc(m*sizeof(double))); | |
15 if (x2 == NULL || y2 == NULL) | |
16 return 0; | |
17 | |
18 for (i=0;i<m;i++) { | |
19 x2[i] = 0; | |
20 y2[i] = 0; | |
21 arg = - dir * 2.0 * 3.141592654 * (double)i / (double)m; | |
22 for (k=0;k<m;k++) { | |
23 cosarg = cos(k * arg); | |
24 sinarg = sin(k * arg); | |
25 x2[i] += (x1[k] * cosarg - y1[k] * sinarg); | |
26 y2[i] += (x1[k] * sinarg + y1[k] * cosarg); | |
27 } | |
28 } | |
29 | |
30 /* Copy the data back */ | |
31 if (dir == 1) { | |
32 for (i=0;i<m;i++) { | |
33 x1[i] = x2[i]; | |
34 y1[i] = y2[i]; | |
35 } | |
36 } else { | |
37 for (i=0;i<m;i++) { | |
38 x1[i] = x2[i]; | |
39 y1[i] = y2[i]; | |
40 } | |
41 } | |
42 | |
43 free(x2); | |
44 free(y2); | |
45 return 1; | |
46 } |