Monday, 13 January 2014

dsp.Write a C program to find DFT of a given sequences using Goertzel algorithm

/* Write a C program to find DFT of a given sequences using Goertzel algorithm. */

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
int k,n,N;
float static X[100],X_Real[100],X_Imag[100];

clrscr();
printf("\tDiscrete Fourier Transform(DFT)\n");

printf("\n Enter the number samples in the sequence X(n)=");
scanf("%d",&N);
printf("Enter the number samples of sequence X(n)\n");

for(n=0;n<N;n++)
{
printf("X(%d)=",n);
scanf("%f",&X[n]);
}

for(k=0;k<N;k++)
 {
  X_Real[k] = X_Imag[k]=0.0;
    for(n=0;n<N;n++)
     {
       X_Real[k]=X_Real[k]+X[n]*cos((2*M_PI*k*(n-N))/N);
       X_Imag[k]=X_Imag[k]+X[n]*sin((2*M_PI*k*(n-N))/N);
     }
     X_Imag[k]=X_Imag[k]*(-1.0);
 }

printf("\nThe %d point DFT of given sequence is:\n",N);
printf("\n\n\tReal X(k)\t\tImaginary X(k)\n");
   for(k=0;k<N;k++)
   printf("\nX(%d)= %f\t\t\t%f\t\t",k,X_Real[k],X_Imag[k]);

getch();
}

***op**

        Discrete Fourier Transform(DFT)

 Enter the number samples in the sequence X(n)=8
Enter the number samples of sequence X(n)
X(0)=-1
X(1)=0
X(2)=2
X(3)=0
X(4)=-4
X(5)=0
X(6)=2
X(7)=0

The 8 point DFT of given sequence is:


        Real X(k)               Imaginary X(k)

X(0)= -1.000000                 -0.000000               
X(1)= 3.000000                  -0.000000               
X(2)= -9.000000                  0.000000                
X(3)= 3.000000                  -0.000000               
X(4)= -1.000000                  0.000000                
X(5)= 3.000000                  -0.000000               
X(6)= -9.000000                  0.000000                

No comments:

Post a Comment