document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. -------------------------------------------------------------------------------------------------
  3.  Assignment No: 12
  4.  Title - Design an FIR filter from given specification using windowing method.
  5. -------------------------------------------------------------------------------------------------
  6. */
  7.  
  8. #include<stdio.h>
  9. #include<conio.h>
  10. #include<math.h>
  11.  
  12. void main()
  13. {
  14.  int M,i,ch,Wc;
  15.  float Hd[10],h[10],W[10],T,n;
  16.  clrscr();
  17.  
  18.  printf("\\nEnter the value of M:");
  19.  scanf("%d",&M);
  20.  
  21.  T=(M-1)/2;
  22.  
  23.  printf("\\nEnter the value of Cut-Off frequency Wc:");
  24.  scanf("%d",&Wc);
  25.  
  26.  for(n=0;n<M;n++)
  27.  {
  28.     if(n==T)
  29.     Hd[n]=Wc/M_PI;
  30.     else
  31.     Hd[n]=(sin(n-T)*Wc)/(M_PI*(n-T));
  32.  }
  33.  
  34.  do
  35.  {
  36.     printf("\\n\\nWindows:");
  37.     printf("\\n1.Rectangular Window\\n2.Hamming Window\\n3.Hanning Window\\n4.Triangular Window");
  38.     printf("\\n5.Blackman Window\\n6.Exit");
  39.     printf("\\nEnter the choice:");
  40.     scanf("%d",&ch);
  41.     switch(ch)
  42.     {
  43.         case 1 : //Rectangular
  44.             for(n=0;n<M;n++)
  45.             {
  46.               h[n]=Hd[n];
  47.             }
  48.             printf("\\nThe Output of Filter Is:");
  49.             for(n=0;n<M;n++)
  50.             {
  51.              printf("\\nh(%d):",n);
  52.              printf("%f",h[n]);
  53.             }
  54.             break;
  55.         case 2: for(n=0;n<M;n++)
  56.             {
  57.               W[n]=0.54+(0.46*cos(2*M_PI*n/(M-1)));
  58.               h[n]=Hd[n]*W[n];
  59.             }
  60.             printf("\\nThe Output ofFilter is :");
  61.             for(n=0;n<M;n++)
  62.             {
  63.              printf("\\nh(%d):",n);
  64.              printf("%f",h[n]);
  65.             }
  66.             break;
  67.  
  68.         case 3: for(n=0;n<M;n++)
  69.             {
  70.              W[n]=(1-cos(2*M_PI*n/(M-1)))*0.5;
  71.              h[n]=Hd[n]*W[n];
  72.             }
  73.             printf("\\nThe Output ofFilter is :");
  74.             for(n=0;n<M;n++)
  75.             {
  76.              printf("\\nh(%d):",n);
  77.              printf("%f",h[n]);
  78.             }
  79.             break;
  80.        
  81.         case 4: for(n=0;n<M;n++)
  82.             {
  83.               W[n]=1-(2*n)/M-1;
  84.               h[n]=Hd[n]*W[n];
  85.             }
  86.             printf("\\nThe Output ofFilter is :");
  87.             for(n=0;n<M;n++)
  88.             {
  89.              printf("\\nh(%d):",n);
  90.              printf("%f",h[n]);
  91.             }
  92.             break;
  93.        
  94.         case 5: for(n=0;n<M;n++)
  95.             {
  96.               W[n]=0.42+(0.5*cos(2*M_PI*n/(M-1)))+(0.08*cos(4*M_PI*n/(M-1)));
  97.               h[n]=Hd[n]*W[n];
  98.             }
  99.             printf("\\nThe Output ofFilter is :");
  100.             for(n=0;n<M;n++)
  101.             {
  102.              printf("\\nh(%d):",n);       printf("%f",h[n]);
  103.             }
  104.             break;
  105.        }
  106.      }while(ch!=6);
  107.     getch();
  108. }
');