Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 6

/*FIR HPF USING TMS320C6713 DSK KIT

#include <stdio.h>
#include <math.h>
float hd[20],h[20];
void main()
{
float wc,tou,M,hd[20],h[20],wn,pi;
int p,n;
printf("enter the no of coeff. of filter M=");
scanf("%f",&M);
p=(int)M;
printf("enter the discrete time cutoff freq. wc=");
scanf("%f",&wc);
tou=(M-1)/2;
pi=3.145;
for (n=0;n<=M-1;n++)
{
hd[n]=(sin(pi*(n-tou))-sin(wc*(n-tou)))/(pi*(n-tou));
if ((n==tou)&&((p/2)*2 != p))
hd[n]=1-wc/pi;
wn=1;
h[n]=hd[n]*wn;

}
for (n=0;n<=M-1;n++)
{
printf("\n h%1.0f=%f",n,h[n]);
}

}
/*result
enter the no of coeff. of filter M=15
enter the discrete time cutoff freq. wc=100
h-0=-0.025792
h-0=-0.001258
h-0=0.028664
h-0=0.068724
h-0=0.104879
h-0=0.139922
h-0=0.159923
h-0=-30.796503
h-0=0.159923
h-0=0.139922
h-0=0.104879
h-0=0.068724
h-0=0.028664
h-0=-0.001258
h-0=-0.025792
*/
Rectangular window
#include <stdio.h>
#include <math.h>
float hd[20],h[20];
void main()
{
float wc,tou,M,hd[20],h[20],wn,pi;
int p,n;
printf("enter the no of coeff. of filter M=");
scanf("%f",&M);
p=(int)M;
printf("enter the discrete time cutoff freq. wc=");
scanf("%f",&wc);
tou=(M-1)/2;
pi=3.145;
for (n=0;n<=M-1;n++)
{
hd[n]=(sin(pi*(n-tou))-sin(wc*(n-tou)))/(pi*(n-tou));
if ((n==tou)&&((p/2)*2 != p))
hd[n]=1-wc/pi;
wn=0.54-0.46*cos((2*pi*n)/(M-1));
h[n]=hd[n]*wn;

}
for (n=0;n<=M-1;n++)
{
printf("\n h%1.0f=%f",n,h[n]);
}

}
Hamming window
/*FIR LPF
#include <stdio.h>
#include <math.h>
float hd[20],h[20];
void main()
{
float wc,tou,M,hd[20],h[20],wn,pi;
int p,n;
printf("enter the no of coeff. of filter M=");
scanf("%f",&M);
p=(int)M;
printf("enter the discrete time cutoff freq. wc=");
scanf("%f",&wc);
tou=(M-1)/2;
pi=3.145;
for (n=M-1;n>=0;n--)
{
hd[n]=sin(wc*(n-tou))/(pi*(n-tou));
if((n==tou)&&((p/2)*2 != p))
{
hd[n]=wc/pi;
}
wn=1;
h[n]=hd[n]*wn;

}
for (n=M-1;n>=0;n--)
{
printf("\n h%1.0f=%f",n,h[n]);
}

/*Result
enter the no of coeff. of filter M=8
enter the discrete time cutoff freq. wc=1000

h0=-0.024108
h0=0.023750
h0=0.061744
h0=0.055416
h0=-0.024315
h0=-0.146777
h0=-0.264002
h0=-316.965027
*/

You might also like