DISCRETE FOURIER TRANSFORM

//DISCRETE FOURIER TRANSFORM
#include<iostream.h>
#include<math.h>
void main()
{
int n,N,i,k;
float a,b,C,S;
double x1[10],x2[10],x[10];
double pi=3.141592654;
cout<<“Enter the period of x[n]:”;
cin>>N;
cout<<“Enter the values of x[n]:”;
for(i=0;i<=N-1;i++)
{
cin>>x[i];
}
cout<<“By analytical method of DFT:\n”;
cout<<“X[K]:”;
for(k=0;k<=N-1;k++)
{
x1[k]=0,x2[k]=0;
for(n=0;n<=N-1;n++)
{
C=cos(2*pi*k*n/N);
S=sin(2*pi*k*n/N);
if(fabs(C)<0.001)
{
C=0;
}
else
{
C=C;
}
if(fabs(S)<0.001)
{
S=0;
}
else
{
S=S;
}
x1[k]=x1[k]+(x[n]*C);
x2[k]=x2[k]+(x[n]*S);
}
a=x1[k];
b=x2[k];
if(b<=0)
{
cout<<“\t”<<a<<“+”<<fabs(b)<<“j\n”;
}
else
{
cout<<“\t”<<a<<“-“<<b<<“j\n”;
}
}
}

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s