DSP C PROGRAM FOR IIR FILTER - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Thursday, November 10, 2011

DSP C PROGRAM FOR IIR FILTER


IIR FILTER
AIM: -                                               
To design and implement a low pass IIR filter using windowing technique.
APPARATUS: -
1.      TMS320C5416 DSK.
2.      USB Cable.
3.      Power Cord
4.      5V Adapter.

THEORY: -
The IIR filter can realize both the poles and zeroes of a system because it has a rational transfer function, described by polynomials in z in both the numerator and the denominator:
                                                                               (2)
The difference equation for such a system is described by the following:
                             (3)
M and N are order of the two polynomials
bk  and ak are the filter coefficients. These filter coefficients are generated using FDS (Filter Design software or Digital Filter design package).

LPF:

#include<stdio.h>
#include<math.h>
#define pi 3.1415
float Xmod[64],Xr[64],Xi[64];
float xr[64],xi[64],h[100],y[64];
      int n,k,i,N,w,wc;
void main()
{
for(k=0;k<=63;k++)
{
xr[k]=sin((2*pi*10*k)/64)+sin((2*pi*50*k)/64);
xi[k]=0.0;
}
for(k=0;k<=63;k++)
{
Xr[k]=0;
Xi[k]=0;
for(n=0;n<=63;n++)
{
Xr[k]+=xr[n]*cos((2*pi*k*n)/64.0)+xi[n]*sin((2*pi*k*n)/64.0);
Xi[k]+=xi[n]*cos((2*pi*k*n)/64.0)-xr[n]*sin((2*pi*k*n)/64.0);
}
Xmod[k]=sqrt(Xr[k]*Xr[k]+Xi[k]*Xi[k]);

}
printf("enter the order of the filter\n");
scanf("%d",&w);
printf("enter the cutoff frequency\n");
scanf("%d",&wc);
for(w=0;w<100;w++)
{
 h[w]=1/sqrt(1+pow(w/(float)wc,2*N));
printf("h[%d]=%f\n",w,h[w]);
}
for(k=0;k<=63;k++)
{
y[k]=Xmod[k]*h[k];
printf("y[%d]=%f\n",k,y[k]);
}}



                       INPUT                                                                            OUTPUT


HPF:

PROGRAM: -


#include<stdio.h>
#include<math.h>
#define pi 3.1415
float Xmod[64],Xr[64],Xi[64];
float xr[64],xi[64],h[100],y[64];
int n,k,i,N,w,wc;

void main()
{
for(k=0;k<=63;k++)
{
xr[k]=sin((2*pi*10*k)/64)+sin((2*pi*50*k)/64);
xi[k]=0.0;
}
for(k=0;k<=63;k++)
{
Xr[k]=0;
Xi[k]=0;
for(n=0;n<=63;n++)

{

Xr[k]+=xr[n]*cos((2*pi*k*n)/64.0)+xi[n]*sin((2*pi*k*n)/64.0);
Xi[k]+=xi[n]*cos((2*pi*k*n)/64.0)-xr[n]*sin((2*pi*k*n)/64.0);
}
Xmod[k]=sqrt(Xr[k]*Xr[k]+Xi[k]*Xi[k]);

}
printf("enter the order of the filter\n");
scanf("%d",&w);
printf("enter the cutoff frequency\n");
scanf("%d",&wc);
for(w=0;w<100;w++)
{
 h[w]=1/sqrt(1+pow(wc/(float)w,2*N));
printf("h[%d]=%f\n",w,h[w]);
}
for(k=0;k<=63;k++)
{
y[k]=Xmod[k]*h[k];
printf("y[%d]=%f\n",k,y[k]);
}}
  
               

                             INPUT                                                                      OUTPUT

RESULT: -
Thus the IIR Low pass filter with cut off frequency 12Hz has been designed.

No comments:

Post a Comment