0% found this document useful (0 votes)
45 views5 pages

'Enter The Length of Filter ' 'Enter The Cut Off Frequency of Filter '

The document describes designing a low pass filter using frequency sampling. It involves taking user input for the filter length and cutoff frequency. It then calculates the values of h(k) and h(n) using cosine terms and sums over k to generate the filter impulse response. Sample output is shown for a filter with length 7 and cutoff frequency of pi/2.

Uploaded by

Sourav Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views5 pages

'Enter The Length of Filter ' 'Enter The Cut Off Frequency of Filter '

The document describes designing a low pass filter using frequency sampling. It involves taking user input for the filter length and cutoff frequency. It then calculates the values of h(k) and h(n) using cosine terms and sums over k to generate the filter impulse response. Sample output is shown for a filter with length 7 and cutoff frequency of pi/2.

Uploaded by

Sourav Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

%%NAME- Shubham Jain

%%USN-1MS16EE054
%%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

enter the cut off frequency of filter=pi/2

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

DESIGN OF LOW PASS FILTER BY WINDOWING TECHNIQUE

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

%to det the window to be used based on attenuation


if a>=-21
win=fprintf('rectangular')
if ta==1
m1=((4*pi)/df)-1
m=round(m1)
elseif ta==2
m1=((4*pi)/df)-1
m=round(m1)
else
m=input('enter the value of m=')
end
n=0:1:m-1
wrn=1

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

% to find the value of tau


b= mod(m,2)
if b==0
t=(m/2)-1
else
t=(m-1)/2
end
%to obtain the time response of filter
if ta==1 %lpf
symswn
n=0:1:m-1
f=exp(((-j*t)+(j*n))*w)
hdn=int(f/(2*pi),w,-wc,wc)
ji=abs(hdn)
elseif ta==2 %hpf
symswn
n=0:1:m-1
f=exp(((-j*t)+(j*n))*w)
hdn1=int(f/(2*pi),w,-pi,-wc)
hdn2=int(f/(2*pi),w,wc,pi)
hdn=(hdn1+hdn2)
ji=abs(hdn)

elseif ta==3 %band pass


symswn
n=0:1:m-1
f=exp((-j*t*w)+(j*n*w))
hdn1=int(f/(2*pi),w,-ws,-wp)
hdn2=int(f/(2*pi),w,wp1,ws1)
hdn=(hdn1+hdn2)
ji=abs(hdn)

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

%to obtain h(n) by windowing


n=0:1:m-1
hn=(hdn.*wrn)
stem(n,hn)

You might also like