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.
i recently did a program in C for N point FFT calculation using radix -2 DIF algoithm as a part of my lab course..
i'll post the program here.. please acknowledge
/* Author : Ragavan N B.E, D.E.C.E, */
/* Institute : Madras institute of Technology, Madras*/
/* Phone : 9840806628*/
/* e-mail : imperial_amazon@yahoo.com*/
/* In case you aren't able to follow the logic I used, feel free*/
/* to mail me.. i'll explain you in detail*/
# include <alloc.h>
# include <stdio.h>
# include <conio.h>
# include <math.h>
float pi=3.141592654;
struct Complex
{float real,imag;};
int BITREV(int N,int bininp) /*function to do the Bit reversal*/
{
int i,num,bitrevd=0;
num=log10(N)/log10(2);
for(i=0;i<(int)num;i++)
{if( ( (bininp<<i) & (N/2) )!=0) bitrevd+=(int)pow(2,i);}
return (bitrevd);
}
float wreal(int Npt,int i) /*calculate the real part re{exp(-j2*pi*n/N)}*/
{
if ( fabs(cos(2*pi*(float)i / (float)Npt)) <.0001 )
{return 0;}
else {return (float) ( cos(2*pi*(float)i / (float)Npt) ); }
}
float wimag(int Npt, int i) /*calculate the real part im{exp(-j2*pi*n/N)}*/
{
if ( fabs(-sin(2*pi*(float)i / (float)Npt)) < .0001)
{return 0;}
else
{return (float) ( -sin(2*pi*(float)i / (float)Npt) ); }
}
void decompose(int Npt, int N,int v,struct Complex (*x_time)[1024],struct Complex (*mainX)[1024])
{
struct Complex *x_tmp;int i;
x_tmp=malloc(2*Npt*sizeof(float));
for(i=0;i<Npt;i++) {x_tmp.real=0;x_tmp.imag=0;}
for(i=0;i< (N/2); i++)
{
auto float a,b,c,d;
x_tmp.real=x_time[v].real+x_time[v][i+(N/2)].real;
x_tmp.imag=x_time[v].imag+x_time[v][i+(N/2)].imag;
a=(x_time[v].real-x_time[v][i+(N/2)].real);
b=(x_time[v].imag-x_time[v][i+(N/2)].imag);
c=wreal(Npt,Npt*i/N);d=wimag(Npt,Npt*i/N);
x_tmp[i+(N/2)].real=( (a * c) - (b * d) );
x_tmp[i+(N/2)].imag=( (a * d) + (b * c) );
}
for(i=N*v;i<(N+(N*v));i++)
{
auto int s;
s=i-N*v;
if(x_tmp.real==0)
{mainX[0].real=abs(x_tmp.real);}
else
{mainX[0].real=x_tmp.real;}
if(x_tmp.imag==0)
{mainX[0].imag=abs(x_tmp.imag);}
else
{mainX[0].imag=x_tmp.imag;}
}
/* printf("\n\nDecomposed\n\n");
for(i=0;i<Npt;i++)
{
printf("\n%f \t %f",mainX[0].real,mainX[0].imag);
} */
free(x_tmp);
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.