Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

DFT in C for understanding

Status
Not open for further replies.

melexia

Member level 2
Member level 2
Joined
Jun 2, 2008
Messages
43
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,620
Hi, I am writing a C code for understanding of discrete Fourier transform. I am taking one sine function as input signal e.g. x[n]=sin (2*3.14*50*n) where 50 is my frequency F. I am calculating it using dft formula and plotting real[w] vs. w and imag[w] vs. w, but not getting proper output. Please help.


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<stdlib.h>
void main()
{
float x[800],re[800],im[800],intre,intim;
int f,w,k,N,i;
float n;
int gdriver = DETECT, gmode;
initgraph(&gdriver,&gmode,"");
printf("maxx=%d,\tmaxy = %d",getmaxx(),getmaxy());
for(n=0,i=0;n < 0.02,i<800;n=n+0.000025,i++)
{
x = sin(2*3.14*50*n);//*0.5*sin(6.28*75*n);
// putpixel(10000*n,(100*x+100),2);
}
intre = 0;
intim = 0;
k= 0;
N=801;

do
{
for(i=0;i<800;i=i+1)
{

re[k] =x*cos(((6.28*k)/N)*i) + intre;
intre = re[k];
im[k] =x*sin(((6.28*k)/N)*i)+intim;
intim = im[k];
}
printf("\n%f\t%d",re[k],k);
printf("\t%f\t%d",im[k],k);
k = k+1;
}while(k<(N-1));

getch();
closegraph();

}






thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top