Go to Makefile Here
Go to Misc_fun.c function library Here
Go to win_lib.c function library Here
Go to coeff.dat Results Here

```
#include
#include "../optimal/globDefs.h"

main()
{
real window[1000],hh[1000],coeff[1000],u_freq,l_freq,u_freq_sub,l_freq_sub;
real new_window[1000];
int i,N,s_freq,fil_typ,win_typ,ans;
logical odd;
FILE *out;
printf("Enter the number of coefficients\n");
scanf("%d",&N);
printf("Enter the lower and upper frequencies\n");
scanf("%lf%lf",&l_freq,&u_freq);
printf("Enter the sampling frequency\n");
scanf("%d",&s_freq);
printf("Do you want to quantize your coefficients select 1 for yes or 0 for no ?\n");
scanf("%d",&ans);
u_freq_sub = u_freq;
l_freq_sub = l_freq;
u_freq *= 3.1415927;
u_freq /= s_freq;
l_freq *= 3.1415927;
l_freq /= s_freq;
if ((out=fopen("coeff.dat","w"))== NULL) {
printf("Cannot open coeff.dat file\n");
exit(1);
}
printf("Select the type of filter\n");
printf(" 0 - lowpass\n");
printf(" 1 - highpass\n");
printf(" 2 - bandpass\n");
printf(" 3 - bandstop\n");
scanf("%d",&fil_typ);
switch(fil_typ) {

case 0:
idealLowpass(N, u_freq, hh);
fprintf(out,"Coefficients for the Lowpass Filter\n");
printf("Coefficients for the Lowpass Filter\n");
break;
case 1:
idealHighpass(N, l_freq, hh);
fprintf(out,"Coefficients for the Highpass Filter\n");
printf("Coefficients for the Highpass Filter\n");
break;
case 2:
idealBandpass(N, l_freq, u_freq, hh);
fprintf(out,"Coefficients for the Bandpass Filter\n");
printf("Coefficients for the Bandpass Filter\n");
break;
case 3:
idealBandstop(N, l_freq, u_freq, hh);
fprintf(out,"Coefficients for the Bandstop Filter\n");
printf("Coefficients for the Bandstop Filter\n");
break;
default:
printf("Invalid number\n");
exit(1);
}
printf("\nSelect the type of window\n");
printf(" 0 - Hanning\n");
printf(" 1 - Hamming\n");
printf(" 2 - Blackman\n");
printf(" 3 - Triangular\n");
printf(" 4 - Rectangular\n");
scanf("%d",&win_typ);
switch (win_typ) {

case 0:
hanningWindow(N,window);
makeDataWindow(N,window,new_window);
fprintf(out,"using the Hanning Window\n\n");
printf("using the Hanning Window\n\n");
break;
case 1:
hammingWindow(N,window);
makeDataWindow(N,window,new_window);
fprintf(out,"using the Hamming Window\n\n");
printf("using the Hamming Window\n\n");
break;
case 2:
blackmanWindow(N,window);
makeDataWindow(N,window,new_window);
fprintf(out,"using the Blackman Window\n\n");
printf("using the Blackman Window\n\n");
break;
case 3:
triangularWindow(N,window);
makeDataWindow(N,window,new_window);
fprintf(out,"using the Triangular Window\n\n");
printf("using the Triangular Window\n\n");
break;
case 4:
rectWindow(N,window);
makeDataWindow(N,window,new_window);
fprintf(out,"using the Rectangular Window\n\n");
printf("using the Rectangular Window\n\n");
break;
default:
printf("Invalid Number\n");
exit(1);
}
odd = N%2;

for (i=0; i<=(N-1); i++)
{
coeff[i] = new_window[i] * hh[i];
}
for (i=0; i<=(N-1); i++)
{
printf("w[%d] = %lf\n",i,new_window[i]);
fprintf(out,"w[%d] = %lf\n",i,new_window[i]);
}
printf("\n\n");
fprintf(out,"\n\n");
for (i=0; i<=(N-1); i++)
{
printf("hh[%d] = %lf\n",i,hh[i]);
fprintf(out,"hh[%d] = %lf\n",i,hh[i]);
}
printf("\n\n");
fprintf(out,"\n\n");
for (i=0; i<=(N-1); i++)
{
printf("coeff[%d] = %lf\n",i,coeff[i]);
fprintf(out,"coeff[%d] = %lf\n",i,coeff[i]);
}
printf("\n\n");
fprintf(out,"\n\n");
printf("The number of coefficients is: %d\n",N);
fprintf(out,"The number of coefficients is: %d\n",N);
printf("The Upper and lower frequencies are: %lf %lf\n",l_freq_sub,u_freq_sub);
fprintf(out,"The Upper and lower frequencies  Normalized are: %lf %lf\n",l_freq_sub,u_freq_sub);
printf("The Sampling frequency is: %d\n",s_freq);
fprintf(out,"The Sampling frequency is: %d\n",s_freq);

if (ans)
{
quantize(N,odd,coeff);
printf("\n\n");
fprintf(out,"\n\n");
if (odd)
{
for (i=0; i<=(N-1); i++)
{
printf("coeff[%d] = %d\n",i,(int)coeff[i]);
fprintf(out,"coeff[%d] = %d\n",i,(int)coeff[i]);
}
}

}
}
```