Professional Documents
Culture Documents
%%USN-1MS16EE055
%%DESIGN OF LOW PASS FILTER BY FREQUENCY SAMPLING
clc
clear
m=input('enter the length of filter=')
wc=input('enter the cut off frequency of filter=')
a=mod(m,2)
if a==0
t=(m/2)-1
else
t=(m-1)/2
end
%calculation of h(k)
k= round((wc*m)/(2*pi))
%calclation of h(n)
for n=0:1:m-1
p=1:1:k
S=cos(2*pi*p*((t/m)-(n/m)))
S1=sum(S)
hn=1/m*(1+(2*S1))
end
%% OUTPUT
enter the length of filter=7
m = 7
wc = 1.5708
a =1t =3 k =2
p = 1 2
S = -0.9010 0.6235
S1 = -0.2775
hn = 0.0636
p = 1 2
S = -0.2225 -0.9010
S1= -1.1235
hn = -0.1781
p = 1 2
S = 0.6235 -0.2225
S1 = 0.4010
hn = 0.2574
p= 1 2
S = 1 1
S1 = 2
hn = 0.7143
p = 1 2
S = 0.6235 -0.2225
S1 = 0.401
hn = 0.2575
p = 1 2
S = -0.2225 -0.9010
S1 = -1.1235
hn = -0.1781
p = 1 2
S = -0.9010 0.6235
S1 = -0.2771
hn = 0.0636
clc
clear
wp=input('enter the value of pass band(1) frequency=')
ws=input('enter the value of stop band band(1) frequency=')
wp1=input('enter the value of pass band(2) frequency=')
ws1=input('enter the value of stop band band(2) frequency=')
ba=[wp1 ws1]
%to det the type of filter
ifnnz(ba) ==0
ds=input('enter the value of pass band ripple=')
dp=input('enter the value of stop band rippple=')
wc=(wp+ws)/2 %cutoff freq
D=min(ds,dp) %min value of ripple
a=20*log10(D) %min stop band attenuation
ifwp<ws
fil_type=fprintf('lowpassfilter')
ta=1
df=ws-wp%transistion band
else
fil_type=fprintf('highpassfilter')
ta=2
df=wp-ws%transistion band
end
else
a=input('enter the value of stop band attenuation=')
if wp1<ws1
fil_type=fprintf('band pass')
ta=3
else
fil_type=fprintf('band reject')
ta=4
end
end
elseif a>=-44
win=fprintf('hanning')
if ta==1
m1=(8*pi)/df
m=round(m1)
elseif ta==2
m1=(8*pi)/df
m=round(m1)
else
m=input('enter the value of m=')
end
n=0:1:m-1
wrn=0.5*(1-cos((2*pi*n)/(m-1)))
else
win=fprintf('hamming')
if ta==1
m1=(8*pi)/df
m=round(m1)
elseif ta==2
m1=(8*pi)/df
m=round(m1)
else
m=input('enter the value of m=')
end
n=0:1:m-1
wrn=0.54-0.46*cos((2*pi*n)/(m-1))
end
else
ta==4 %band reject
symswn
n=0:1:m-1
f=exp(((-j*t)+(j*n))*w)
hdn=int(f/(2*pi),w,-wp,wp)
ji=abs(hdn)
end