Monday, 13 January 2014

dsp.C program to design Butterworth filter design using Bilinear Transformation

/* C program to design Butterworth filter design using Bilinear
   Transformation.

   Inputs: 1.Order of the butterworth filter (N)
  2.Cutoff frequency of digital filter (Wc).
 Outputs: Coefficients of digital filter(cascaded second order).
   The cascaded second order sections
 H(z)=H1(z)*H2(z)*H3(z)...
               b00+b01z^-1+b02z^-2     b10+b11z^-1+b12z^-2
   H(z)=B0-------------------- *B1---------------------*...
  a00+a01z^-1+a02z^-2     a10+a11z^-1+a12z^-2
=====================================================================*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
 int i;
 float bi[20],b[20][3],a[20][3],p_real,p_imag;
 float wc,N,theta,OmegaC,Den;
 clrscr();
 printf("\t\t Butterworth filter design using Billinear Transformation\n");
 printf("\n\n Enter the order of the filter N= ");
 scanf("%f",&N);
 printf("\n Enter the cutoff frequency of digital filter Wc:");
 scanf("%f",&wc);
 OmegaC=tan(wc/2);
 for(i=0;i<N/2;i++)
 {
  theta=((N+2*i+1)*M_PI)/(2*N);
  p_real=-1*OmegaC*cos(theta);
  p_imag=OmegaC*sin(theta);
  Den=1+2*p_real+p_real*p_real+p_imag*p_imag;
  bi[i]=(OmegaC*OmegaC)/Den;
  b[i][0]=1;
  b[i][1]=2;
  b[i][2]=1;
  a[i][0]=1;
  a[i][1]=(2*(p_real*p_real+p_imag*p_imag)-2)/Den;
  a[i][2]=(1-2*p_real+p_real*p_real+p_imag*p_imag)/Den;
 }
 if((N/2)!=i)
 {
  i--;
  Den=OmegaC+1;
  bi[i]=OmegaC/Den;

  b[i][0]=1;
  b[i][1]=1;
  b[i][2]=0;
  a[i][0]=1;
  a[i][1]=(OmegaC-1)/Den;
  a[i][2]=0;
 }
 printf("\n The Coefficients of cascaded second order");
 printf(" \n\n sections of digital filter as follows...\n");
 for(i=0;i<N/2;i++)
 {
  printf("\n B[%d]= %f\tb[%d][0]= %f\ta[%d][0]= %f",
   i,bi[i],i,b[i][0],i,a[i][0]);
  printf("\n\t\tb[%d][1]= %f\ta[%d][1]= %f",i,b[i][1],i,a[i][1]);
  printf("\n\t\tb[%d][2]= %f\ta[%d][2]= %f",i,b[i][2],i,a[i][2]);
 }
 getch();
}

****o*p***
                Butterworth filter design using Billinear Transformation


 Enter the order of the filter N= 2

 Enter the cutoff frequency of digital filter Wc:90

 The Coefficients of cascaded second order

 sections of digital filter as follows...

 B[0]= 0.443609 b[0][0]= 1.000000       a[0][0]= 1.000000
                b[0][1]= 2.000000       a[0][1]= 0.549059
                b[0][2]= 1.000000       a[0][2]= 0.225377

No comments:

Post a Comment