view modules/bluespec/Pygar/common/DFT.cpp @ 36:99519a031813 pygar svn.37

[svn r37] moved the server into audioCorePipeline
author punk
date Tue, 04 May 2010 18:54:54 -0400
parents 74716e9a81cc
children
line wrap: on
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
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;
13 x2 = (double *)(malloc(m*sizeof(double)));
14 y2 = (double *)(malloc(m*sizeof(double)));
15 if (x2 == NULL || y2 == NULL)
16 return 0;
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 }
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 }
43 free(x2);
44 free(y2);
45 return 1;
46 }