//DFT.c DFT of N-point from lookup table. Output from watch window #include #include void dft(short *x, short k, int *out); //function prototype #define N 8 //number of data values float pi = 3.1416; short x[N] = {1000,707,0,-707,-1000,-707,0,707}; //1-cycle cosine //short x[N]={0,602,974,974,602,0,-602,-974,-974,-602, // 0,602,974,974,602,0,-602,-974,-974,-602}; //2-cycles sine int out[2] = {0,0}; //init Re and Im results void dft(short *x, short k, int *out) //DFT function { int sumRe = 0; //init real component int sumIm = 0; //init imaginary component int i = 0; float cs = 0; //init cosine component float sn = 0; //init sine component for (i = 0; i < N; i++) //for N-point DFT { cs = cos(2*pi*(k)*i/N); //real component sn = sin(2*pi*(k)*i/N); //imaginary component sumRe = sumRe + x[i]*cs; //sum of real components sumIm = sumIm - x[i]*sn; //sum of imaginary components } out[0] = sumRe; //sum of real components out[1] = sumIm; //sum of imaginary components } void main() { int j; for (j = 0; j < N; j++) { dft(x,j,out); //call DFT function } }