/*
-------------------------------------------------------------------------------------------------
Assignment No: 12
Title - Design an FIR filter from given specification using windowing method.
-------------------------------------------------------------------------------------------------
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int M,i,ch,Wc;
float Hd[10],h[10],W[10],T,n;
clrscr();
printf("\\nEnter the value of M:");
scanf("%d",&M);
T=(M-1)/2;
printf("\\nEnter the value of Cut-Off frequency Wc:");
scanf("%d",&Wc);
for(n=0;n<M;n++)
{
if(n==T)
Hd[n]=Wc/M_PI;
else
Hd[n]=(sin(n-T)*Wc)/(M_PI*(n-T));
}
do
{
printf("\\n\\nWindows:");
printf("\\n1.Rectangular Window\\n2.Hamming Window\\n3.Hanning Window\\n4.Triangular Window");
printf("\\n5.Blackman Window\\n6.Exit");
printf("\\nEnter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1 : //Rectangular
for(n=0;n<M;n++)
{
h[n]=Hd[n];
}
printf("\\nThe Output of Filter Is:");
for(n=0;n<M;n++)
{
printf("\\nh(%d):",n);
printf("%f",h[n]);
}
break;
case 2: for(n=0;n<M;n++)
{
W[n]=0.54+(0.46*cos(2*M_PI*n/(M-1)));
h[n]=Hd[n]*W[n];
}
printf("\\nThe Output ofFilter is :");
for(n=0;n<M;n++)
{
printf("\\nh(%d):",n);
printf("%f",h[n]);
}
break;
case 3: for(n=0;n<M;n++)
{
W[n]=(1-cos(2*M_PI*n/(M-1)))*0.5;
h[n]=Hd[n]*W[n];
}
printf("\\nThe Output ofFilter is :");
for(n=0;n<M;n++)
{
printf("\\nh(%d):",n);
printf("%f",h[n]);
}
break;
case 4: for(n=0;n<M;n++)
{
W[n]=1-(2*n)/M-1;
h[n]=Hd[n]*W[n];
}
printf("\\nThe Output ofFilter is :");
for(n=0;n<M;n++)
{
printf("\\nh(%d):",n);
printf("%f",h[n]);
}
break;
case 5: for(n=0;n<M;n++)
{
W[n]=0.42+(0.5*cos(2*M_PI*n/(M-1)))+(0.08*cos(4*M_PI*n/(M-1)));
h[n]=Hd[n]*W[n];
}
printf("\\nThe Output ofFilter is :");
for(n=0;n<M;n++)
{
printf("\\nh(%d):",n); printf("%f",h[n]);
}
break;
}
}while(ch!=6);
getch();
}