0% found this document useful (0 votes)
40 views2 pages

FFT

The document contains a C program that implements the Discrete Fourier Transform (DFT) for 8 input samples. It defines a complex number structure and uses various arrays to store intermediate results and the final DFT values. The program calculates and prints the DFT values in a formatted manner.

Uploaded by

malyadri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

FFT

The document contains a C program that implements the Discrete Fourier Transform (DFT) for 8 input samples. It defines a complex number structure and uses various arrays to store intermediate results and the final DFT values. The program calculates and prints the DFT values in a formatted manner.

Uploaded by

malyadri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<stdio.

h>
#include<math.h>
#define PI 3.14

typedef struct
{
float real,imag;
}com;
void main()
{
com xx[8],x[8],temp[8],temp1[8],y[8],a[8],b[8],w[4];
int i,j=0;//loop counter variables
printf("\nEnter 8 input samples==");
for(i=0;i<8;i++)

scanf("%f",&xx[i].real);

j=0;
for(i=0;i<8;i=i+2)
{
x[j].real=xx[i].real;
x[j+1].real=xx[i+4].real;
if(i==2)
i=-1;
j=j+2;
}
for(i=0;i<4;i++)
{
w[i].real=cos(2*PI*i/8);
w[i].imag=-sin(2*PI*i/8);
}

for(i=0;i<8;i=i+2)
{
temp[i].real=x[i].real+x[i+1].real;
temp[i].imag=x[i].imag+x[i+1].imag;
temp[i+1].real=x[i].real-x[i+1].real;
temp[i+1].imag=x[i].imag-x[i+1].imag;
}
for(i=2;i<8;i=3*i)
{
a[i].real=temp[i].real*w[0].real-temp[i].imag*w[0].imag;
a[i].imag=temp[i].real*w[0].imag+temp[i].imag*w[0].real;
a[i+1].real=temp[i+1].real*w[2].real-temp[i+1].imag*w[2].imag;
a[i+1].imag=temp[i+1].real*w[2].imag+temp[i+1].imag*w[2].real;
temp[i].real=a[i].real;
temp[i].imag=a[i].imag;
temp[i+1].real=a[i+1].real;
temp[i+1].imag=a[i+1].imag;

}
for(i=0;i<6;i++)
{
temp1[i].real=temp[i].real+temp[i+2].real;
temp1[i].imag=temp[i].imag+temp[i+2].imag;
temp1[i+2].real=temp[i].real-temp[i+2].real;
temp1[i+2].imag=temp[i].imag-temp[i+2].imag;
if(i==1)
i=3;
}
for(i=4;i<8;i++)
{
b[i].real=temp1[i].real*w[i-4].real-temp1[i].imag*w[i-4].imag;
b[i].imag=temp1[i].real*w[i-4].imag+temp1[i].imag*w[i-4].real;
temp1[i].real=b[i].real;
temp1[i].imag=b[i].imag;
}
for(i=0;i<4;i++)
{
y[i].real=temp1[i].real+temp1[i+4].real;
y[i].imag=temp1[i].imag+temp1[i+4].imag;
y[i+4].real=temp1[i].real-temp1[i+4].real;
y[i+4].imag=temp1[i].imag-temp1[i+4].imag;
}
printf("\nDFT values==\n");
for(i=0;i<8;i++)
printf("\nF(%d)=(%0.1f)+j(%0.1f)\n",i,y[i].real,y[i].imag);
}

You might also like