Professional Documents
Culture Documents
Output :
>> imp(2,0,4)
n=
0 1 2
x=
0 0 1
ans =
0 1 2
4
impulsesignal
1
0.9
0.8
amplitude
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0
0.5
1.5
2
time
2.5
3.5
Output
>>stepf(2,-2,4)
n=
-2 -1
x=
0
0
ans =
-2 -1
4
step signal
1
0.9
0.8
0.7
amplitude
0.6
0.5
0.4
0.3
0.2
0.1
0
-4
-3
-2
-1
0
time
Output:
sinege(0:100,0.1*pi)
sine signal
1
amplitude
0.5
0
-0.5
-1
10
20
30
40
50
time
60
70
80
90
100
Output:
periodseq([1 2 3 4],4)
m=
1 1 1 1
x1 =
1
2
3
4
y1 =
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
y2 =
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
y=
Columns 1 through 14
1 2 3 4 1 2
Columns 15 through 16
3 4
ans =
Columns 1 through 14
1 2 3 4 1 2
Columns 15 through 16
3 4
periodic signal
4
y(n)
3
2
1
0
8
n..................
10
12
14
16
function[y3]=addseq(n1,n2,n3,n4,x1,x2)
no=n1:n2
nn=n3:n4
minn=min(min(no),min(nn))
maxn=max(max(no),max(nn))
n=minn:maxn
y1=zeros(1,length(n))
y2=y1
a=((n>=min(no))&(n<=max(no)))
b=((n>=min(nn))&(n<=max(nn)))
y1(find(a))=x1
y2(find(b))=x2
y3=y1+y2
subplot(3,1,1)
stem(n,y1)
title(Sequence y1)
xlabel(Range)
ylabel(y1)
subplot(3,1,2)
stem(n,y2)
title(Sequence y2)
xlabel(Range)
ylabel(y2)
subplot(3,1,3)
stem(n,y3)
title(Addition of two sequences)
xlabel(Range)
ylabel(y3)
Output:
addseq(0,2,2,6,[1 4 2],[0 3 4 5 5])
no =
0
nn =
2
minn =
0
maxn =
6
n=
0
y1 =
0
y2 =
0
a=
1
b=
0
y1 =
1
y2 =
0
y3 =
1
ans =
1
6
4
2
0
6
4
2
0
Output:
subseq(0,2,2,6,[1 4 2],[0 3 4 5 5])
no =
0
nn =
2
minn =
0
maxn =
6
n=
0
y1 =
-3
-4
-5
-5
-3
-4
-5
-5
y2 =
0
a=
1
b=
0
y1 =
1
y2 =
0
y3 =
1
ans =
1
10
6
4
2
0
5
-5
11
Output:
mulseq(0,2,2,6,[1 4 2],[0 3 4 5 5])
no =
0
nn =
2
minn =
0
maxn =
6
n=
0
y1 =
12
y2 =
0
a=
1
b=
0
y1 =
1
y2 =
0
y3 =
0
ans =
0
13
6
4
2
0
1
-1
14
Output:
seqfold(-3,4,[0 1
n0 =
-3 -2 -1
y=
8
5
4
n=
-4 -3 -2
2 5 3 4 5 8])
0
-1
original sequence
8
amplitude
6
4
2
0
-3
-2
-1
-3
-2
1
time
folded sequence
amplitude
6
4
2
0
-4
-1
0
time
15
Output:
shiftf1(-2,-3:2,[0 2 5 6 5 8])
m=
-5 -4 -3 -2 -1 0
y=
0 2 5 6 5 8
ans =
-5 -4 -3 -2 -1 0
original sequence
8
sequence
6
4
2
0
-3
-2.5
-2
-1.5
-1
-0.5
0
range
shifted sequence
-4.5
-4
-3.5
-3
0.5
1.5
-1.5
-1
-0.5
sequence
6
4
2
0
-5
-2.5
range
-2
16
Output:
evenodd(0:6,[0 1 2 3 4 5 5])
n1 =
-6
-5
-4
-3
-2
-1
x1 =
5
n2 =
17
-6
-5
-4
-3
-2
-1
y1 =
0
y2 =
0
a=
0
b=
1
y1 =
0
y2 =
5
xe =
Columns 1 through 8
2.5000
2.5000
2.0000
1.5000
1.0000
2.5000
2.5000
0.5000
0.5000
Columns 9 through 13
1.0000
1.5000
2.0000
x0 =
Columns 1 through 8
-2.5000 -2.5000 -2.0000 -1.5000 -1.0000 -0.5000
0.5000
Columns 9 through 13
1.0000
1.5000
2.0000
2.5000
2.5000
18
z=
0
original s ignal
even s ignal
2
amp
amp
0
-10
-5
0
n2
res ult
10
-5
0
n2
10
n
odd s ignal
4
4
amp
amp
2
-2
-4
-10
-5
0
n2
10
0
-10
19
Output:
convol([1 2 3 4 5],[2 3 4 ],0:4,0:2)
y=
2
7 16 25 34 31 20
n=
0
1
2
3
4
5
6
20
o rig in a l 1 s ig n a l
am p
0 .5
1 .5
2
2 .5
n
o rig in a l 2 s ig n a l
3 .5
am p
4
2
0
0 .2
0 .4
0 .6
0 .8
1
1 .2 1 .4
n
c o n vo lve d s ig n a l
1 .6
1 .8
am p
40
20
0
3
n
21
ylabel('amp')
Output:
correlation([1 2 3 4 1],[4 6 7 0 3 4 5 ],0:4,-6:0)
n2 =
0
c=
2
y=
Columns 1 through 8
5.0000 14.0000 26.0000 38.0000 37.0000 36.0000 40.0000 54.0000
Columns 9 through 13
43.0000 22.0000
4.0000
n=
0
10
11
12
10
11
12
ans =
0
22
o rig in a l 1 s ig n a l
am p
4
2
0
0 .5
1 .5
2
2 .5
3
n
o rig in a l 2 s ig n a l
3 .5
am p
10
5
0
3
4
n
c o rre la t e d s ig n a l
10
12
am p
100
50
0
6
n
23
subplot(2,2,2)
plot(w/pi,angle(X))
title('phase')
xlabel('frequency in pi units')
ylabel('angle')
subplot(2,2,3)
plot(w/pi,real(X))
title('real plot')
xlabel('frequency in pi units')
ylabel('real')
subplot(2,2,4)
plot(w/pi,imag(X))
title('imaginary plot')
xlabel('frequency in pi units')
ylabel('imaginary mag')
Output:
dtft([0 3 5 4 6 8],-2:3)
24
m agnitude plot
phas e
30
0
-1
real
angle
10
0
-2
-0.5
0
0.5
frequenc y in pi units
real plot
-4
-1
30
20
20
10
imaginary mag
amplitude
2
20
10
0
-10
-1
-0.5
0
0.5
frequenc y in pi units
-0.5
0
0.5
frequenc y in pi units
im aginary plot
-0.5
0
0.5
frequenc y in pi units
0
-10
-20
-1
function[]=dtfti()
w=[-500:1:500]*pi/500
X=exp(j*w)./(exp(j*w)-0.5*ones(1,1001))
subplot(2,2,1)
plot(w/pi,abs(X))
title('magnitude plot')
xlabel('frequency in pi units')
ylabel('magnitude')
subplot(2,2,2)
plot(w/pi,angle(X))
title('phase plot')
xlabel('angle in radians')
ylabel('phase')
subplot(2,2,3)
plot(w/pi,real(X))
title('real part')
xlabel('frequency in pi units')
ylabel('real part')
subplot(2,2,4)
plot(w/pi,imag(X))
title('imaginary part')
xlabel('frequency in pi units')
ylabel('imaginary part')
Output:
26
dtfti()
m agnitude plot
phas e plot
1
0.5
1.5
phase
magnitude
0.5
-1
-0.5
-0.5
0
0.5
frequenc y in pi units
real part
-1
-1
-0.5
0
0.5
angle in radians
im aginary part
-0.5
0
0.5
frequenc y in pi units
1
imaginary part
real part
1.5
0.5
-1
-0.5
0
0.5
frequenc y in pi units
0.5
0
-0.5
-1
-1
Output:
symmetry([1 2 3 4],0:3)
err =
3.0642e-014
err1 =
3.0642e-014
28
29
Output:
conjugate([1 2 3 4],0:3)
err = 6.1284e-014
30
m a g n it u d e p a rt
p h a s e p a rt
4
angle in radian
mag of X
10
0
-1
-2
-0 . 5
0
0.5
1
fre q u e n c y in p i u n it s
a n g le o f Y
4
angle in radians
magnitude of Y
-4
-1
-0 . 5
0
0.5
1
fre q u e n c y in p i u n it s
m a g n it u d e p a rt
10
0
-1
-0 . 5
0
0.5
1
fre q u e n c y in p i u n it s
2
0
-2
-4
-1
-0 . 5
0
0.5
1
fre q u e n c y in p i u n it s
31
32
Output:
linprop([1 3 5 7],[2 4 6 8],2,3,0:3)
d t ft o f a * x 1 + b * x 2
m agnitude part
100
50
0
-4
-3
-2
-1
0
1
2
fr e q u e n c y in p i u n i t s
d t ft o f a * [ X 1 ] + b * [ X 2 ]
-3
-2
-1
0
1
2
fr e q u e n c y in p i u n i t s
m agnitude part
100
50
0
-4
33
Output:
freqsh1([1 0 -1 0],0:3)
4.1851e-015
34
m a g n it u d e p a rt
p h a s e p a rt
2
angle in radians
magnitude of x
0
-1
-0 . 5
0
0.5
1
fre q u e n c y in p i u n it s
a n g le o f Y
angle in radians
magnitude of Y
-2
-4
-1
-0 . 5
0
0 .5
1
fre q u e n c y in p i u n it s
m a g n it u d e p a rt o f x
0
-1
-0 . 5
0
0 .5
1
fre q u e n c y in p i u n it s
1
0
-1
-2
-1
-0 . 5
0
0.5
1
fre q u e n c y in p i u n it s
35
Output:
Period
36
m a g n it u d e p a rt
p h a s e p a rt
10
0
-1
angle in radians
m agnitude
-0 .5
0
0 .5
1
fr e q u e n c y in p i u n it s
re a l p a rt
10
-4
-1
-0 .5
0
0 .5
1
fr e q u e n c y i n p i u n it s
im a g in a ry p a rt
5
im aginary
real
-5
-1
-2
10
-0 .5
0
0 .5
1
fr e q u e n c y in p i u n it s
0
-5
-1 0
-1
-0 .5
0
0 .5
1
fr e q u e n c y i n p i u n it s
37
38
Output:
dtftshift()
39
Output:
dfs([1 2 3 4],4)
n=
0
k=
0
wn =
40
0.0000 - 1.0000i
nk =
0
0
0
0
0
1
2
3
0
2
4
6
0
3
6
9
wnk =
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
0.0000 - 1.0000i -1.0000 - 0.0000i -0.0000 + 1.0000i
-1.0000 - 0.0000i 1.0000 + 0.0000i -1.0000 - 0.0000i
-0.0000 + 1.0000i -1.0000 - 0.0000i 0.0000 - 1.0000i
xk =
2.5000
magx =
2.5000
0.7071
0.5000
0.7071
phasex =
0
realx =
2.5000 -0.5000 -0.5000 -0.5000
imagx =
0
ans =
2.5000
41
magnitude plot
phase part
2.5
4
2
angle in rad
magnitude
2
1.5
1
-2
0.5
0
1
2
frequency in pi units
-4
real plot
1
2
frequency in pi units
imaginary plot
0.6
0.4
imaginary part
real part
1
0
0.2
0
-0.2
-0.4
-1
1
2
frequency in pi units
-0.6
1
2
frequency in pi units
42
Output
idfs([2.5000 -0.5000 + 0.5000i -0.5000 - 0.0000i -0.5000 - 0.5000i],4)
n=
0
k=
0
wn =
43
0.0000 + 1.0000i
nk =
0
0
0
0
0
1
2
3
0
2
4
6
0
3
6
9
wnk =
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
1.0000
0.0000 + 1.0000i -1.0000 + 0.0000i -0.0000 - 1.0000i
-1.0000 + 0.0000i 1.0000 - 0.0000i -1.0000 + 0.0000i
-0.0000 - 1.0000i -1.0000 + 0.0000i 0.0000 + 1.0000i
y=
1.0000
magx =
1
phasex =
1.0e-015 *
0
realx =
1
imagx =
1.0e-015 *
0
ans =
1.0000
44
-17
0
angle in rad
magnitude
magnitude plot
2
1
0
1
2
frequency in pi units
-10
imaginary part
real part
1
0
1
2
frequency in pi units
1
2
frequency in pi units
-16
real plot
phase part
-5
-15
x 10
x 10
imaginary plot
-2
-4
-6
1
2
frequency in pi units
23.Program to do upsampling
function[n1,y]=upsam(n,x,I)
45
mn=min(n)
mx=max(n)
n1=mn*I:(mx*I+I-1)
x1=x'
x1=[x1,zeros(length(x),I-1)]
x1=x1'
y=(x1(:))'
subplot(2,1,1)
stem(n,x)
xlabel('range')
ylabel('sequence')
title('original')
subplot(2,1,2)
stem(n1,y)
xlabel('range')
ylabel('sequence')
title('upsampling')
Output:
ups(0:4,[1 2 3 4 5],3)
mn =
0
mx =
4
n1 =
Columns 1 through 14
0
10
11
12
13
Column 15
14
x1 =
1
2
3
4
5
x1 =
1
2
0
0
0
0
46
3
4
5
0
0
0
0
0
0
2
0
0
3
0
0
x1 =
1
0
0
4
0
0
5
0
0
y=
Columns 1 through 14
1
10
Column 15
0
ans =
Columns 1 through 14
0
11
12
13
Column 15
14
47
original
5
sequence
4
3
2
1
0
0.5
1.5
2
range
2.5
3.5
upsampling
5
sequence
4
3
2
1
0
10
12
14
range
48
Output:
downsamp(0:4,[1 2 3 4 4 ],0.5)
n1 =
2
n2 =
2
49
original
amp--sequence
4
3
2
1
0
1.5
2.5
n-- range
result
3.5
amp--sequence
4
3
2
1
0
n--range
50
Output:
ztr1
Enter numerator co-efficient[0 0.25]
b=
0
0.2500
0.2500
n=
0
10
x=
1
y=
Columns 1 through 8
0
0.2500 -0.0625
0.0156 -0.0039
0.0010 -0.0002
0.0001
Columns 9 through 11
51
-0.0000
0.0000 -0.0000
ans =
Columns 1 through 8
0
0.2500 -0.0625
0.0156 -0.0039
0.0010 -0.0002
0.0001
Columns 9 through 11
-0.0000
0.0000 -0.0000
pole-zero plot
Imaginary part
1
0.5
0
-0.5
-1
-3
-2
-1
0
Real part
Impulse response
0.3
y----------->
0.2
0.1
0
-0.1
5
6
n----------->
10
52
Output:
ztr
Enter numerator co-efficient [0 1]
b=
0
p=
0 - 0.3536i
0 + 0.3536i
-1.0000 + 1.4142i
-1.0000 - 1.4142i
k=
[]
53
pole-zero plot
Imaginary part
-1
-4
-3
-2
-1
0
Real part
54
Output:
55
X=
Columns 1 through 4
15.0000
Columns 5 through 7
-0.9342 - 2.4527i 3.4635 + 1.4300i -6.5293 + 4.0546i
H=
Columns 1 through 4
6.0000
Columns 5 through 7
1.0685 - 1.4777i -2.1479 + 0.6482i 1.5794 + 4.4884i
Y=
Columns 1 through 4
90.0000
Columns 5 through 7
-4.6225 - 1.2403i -8.3663 - 0.8266i -28.5112 -22.9026i
56
yl =
1.0000
N1 =
5
k2 =
0
X1 =
Columns 1 through 4
15.0000
Column 5
-2.5000 - 3.4410i
H1 =
Columns 1 through 4
6.0000
Column 5
-0.8090 + 3.6655i
Y1 =
Columns 1 through 4
90.0000
Column 5
14.6353 - 6.3799i
yc =
23
19
10
16
22
57
1.5
h----------->
3
2
1
0
y----------->
sequence h(n)
2
1
2
n----------->
Linear convolution)
1
0.5
0
3
y----------->
x----------->
sequence x(n)
4
2
1
0
1
2
n----------->
1
2
m----------->
circular convolution)
1
2
n----------->
2
1
0
58
Output:
ovlsav([1:12],[1 2 3 4],6)
lx =
6
x1 =
10
12
11
y=
16
44
74
104
10
17
42
72
102
31
12
34
64
94
64
1
20
50
80
97
4 10
30 40
60 70
90 100
80 48
59
y1 =
12
34
64
94
64
1
20
50
80
97
4 10
30 40
60 70
90 100
80 48
z=
Columns 1 through 14
12
34
64
94
64
20
50
80
97
30
60
90
Columns 15 through 20
80
10
40
70 100
48
60
Output:
ovladd([1:12],[1 2 3 4],6)
Z=
Columns 1 through 14
1
10
20
30
40
50
60
70
80
90 100
97
80
Columns 15 through 20
48
61
Output:
circondft([1 2 3 4],[2 0 0 1],4)
n=
0
k=
0
X1 =
10.0000
62
Y1 =
3.0000
Z=
30.0000
xf =
4.0000 - 0.0000i 7.0000 - 0.0000i 10.0000 + 0.0000i 9.0000 - 0.0000i
sequence x(n)
amp---->
0.5
1.5
n----->
sequence y(n)
2.5
0.5
1.5
n----->
convolved sequence
2.5
0.5
1.5
n----->
2.5
amp---->
amp---->
10
63
Output:
Correlation([1 2 3 4],[2 4 6 8],0:3,0:3)
n2 =
-3
-2
-1
c=
0
y=
8.0000 22.0000 40.0000 60.0000 40.0000 22.0000
8.0000
n=
64
-3
-2
-1
-2
-1
ans =
-3
original 1 signal
amp
0.5
1.5
n
original 2 signal
2.5
0
-3
-2.5
-2
-1.5
n
correlated signal
-1
-0.5
-2
-1
0
n
amp
10
60
amp
40
20
0
-3
65
Output:
circorre([1 2 3 4],[2 0 0 1],4)
n=
0
k=
0
X1 =
10.0000
Y1 =
66
3.0000
Z=
30.0000
xf =
6.0000 - 0.0000i 5.0000 - 0.0000i 8.0000 - 0.0000i 11.0000 + 0.0000i
sequence x(n)
amp---->
0.5
0.5
0.5
1.5
n----->
sequence y(n)
2.5
1.5
2
n----->
correlated sequence
2.5
2.5
amp---->
amp---->
15
10
5
0
1.5
n----->
67
Output:
cifold([1 4 3 2],4)
m=
0
y=
[]
x1 =
1
n=
1
x1 =
68
4
original
sequence
3
2
1
0
1.5
2.5
range
original
3.5
1.5
2.5
range
3.5
4
3
sequence
2
1
0
69
70
Output:
dtftfreq
71
Output:
maverage([1 4 71 14 45 ])
72
120
Magnitude
100
80
60
40
20
3
4
Frequency in radians
73
stem(xe,xce)
title('even part')
xlabel('xe')
ylabel('mag')
subplot(4,1,4)
stem(xo,xco)
title('odd part')
xlabel('xo')
ylabel('mag')
Output:
ceco([1 3 4 7 5 8],6)
74
even part
real
50
0
-50
-20
-10
10
20
30
xe
odd part
40
50
60
70
imag
10
0
-10
-35
-30
-25
-20
-15
-10
-5
xo
even part
10
15
mag
20
10
0
-20
-10
10
20
30
xe
odd part
40
50
60
70
mag
0
-10
-20
-35
-30
-25
-20
-15
-10
xo
-5
10
15
75
%m-No.of shift
function[y]=cirshift(x,N,m)
n=0:N-1;
lx=length(x)
x1=[x,zeros(1,N-lx)]
n1=mod((n-m),N);
y=x1(n1+1);
subplot(2,1,1)
stem(x)
title('original')
xlabel('n')
ylabel('amp')
subplot(2,1 ,2)
stem(y)
title('shifted')
xlabel('n')
ylabel('amp')
Output:
cirshift([1 4 8 2],4,2)
lx =
76
4
x1 =
1
ans =
8
original
8
amp
6
4
2
0
1.5
2.5
n
shifted
3.5
1.5
2.5
n
3.5
amp
6
4
2
0
77
stopband)
%
%
%
%
%
%
%
%
%
%
N=8;
fr=[1 1 1 1 0 0 1 1]
xn=ifft(fr)
[h,w]=freqz(xn,1);
xn=cirshift(xn,N,N/2)
z=hanning(8)'.*xn
[z1,w]=freqz(z,1)
%subplot(2,2,1)
%plot(w,abs(h))
N=16
fr=[1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1]
xn=ifft(fr)
[h,w]=freqz(xn,1);
xn1=cirshift(xn,n,n/2)
z2=blackman(16)'.*xn
[z3,w]=freqz(z2,1)
% subplot(2,1,1)
% plot(w,abs(z1))
subplot(2,1,1)
plot(w,abs(z3))
n=16
fr1=[1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1]
xn1=ifft(fr1)
[h,w]=freqz(xn1,1);
xn1=cirshift(xn1,n,n/2)
z3=hanning(16)'.*xn1
[z4,w]=freqz(z3,1)
subplot(2,1,2)
plot(w,abs(z4))
% subplot(2,2,4)
% plot(w,abs(z3))
Output:
frasmmebl
78
original
0.1
amp
0.05
0
-0.05
-0.1
0.5
8
n
10
12
14
16
3.5
1.5
0.5
1.5
2.5
79
plot(w,abs(z3))
Output:
Frsam
1
0.8
0.6
0.4
0.2
0.5
1.5
2.5
3.5
0.5
1.5
2.5
3.5
1
0.8
0.6
0.4
0.2
0
80
n=0:(length(n1)+length(n2)-2)
y=conv(x1,x2)
[X3,w]=dtft(y,n)
[X1,w]=dtft(x1,n1)
[X2,w]=dtft(x2,n2)
X4=X1.*X2
Output:
Funconv(0:3,0:3,[1 4 7 2],[ 2 5 4 1])
Filters
81
% %nr=buttord(wp,ws,rp,rs)
% %ceil(N)
function[b1,a1]=abutunb(N,wc)
[z p k]=buttap(N)
p=p*wc
k=k*(wc)^N
b1=real(poly(z))
b1=k*b1
a1=real(poly(p))
[mag,phase]=freqs(b1,a1)
plot(abs(mag))
output
abutunbss(1,16,0.2*pi,0.3*pi)
82
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
20
40
60
80
100
120
140
160
180
200
N=ceil(log10((10^(rp/10)-1)/(10^(as/10)-1))/(2*log10(omp/oms)))
fprintf('order of filter=52.0f',N)
wc=omp/(10^(rp/10)-1)^(1/(2*N))
[b1,a1]=abutunb(N,wc)
[mag,dbh,phase,wa]=freqsm(b1,a1)
subplot(3,1,1)
plot(wa,abs(mag))
title('Magnitude plot')
xlabel('frequency in pi units')
ylabel('Magnitude')
grid
83
subplot(3,1,2)
plot(wa,abs(mag))
title('Magnitude(db) plot')
xlabel('frequency in pi units')
ylabel('Magnitude in db')
grid
subplot(3,1,3)
plot(wa,phase)
title('Phase plot')
xlabel('frequency in pi units')
ylabel('angle in radians')
grid
function[b1,a1]=abutunb(N,wc)
[z p k]=buttap(N)
p=p*wc
k=k*(wc)^N
b1=real(poly(z))
b1=k*b1
a1=real(poly(p))
% [mag,phase]=freqs(b,a)
% plot(abs(mag))
function[mag,dbh,phase,wa]=freqsm(b1,a1)
wa=[[0:1:500]*(0.5*pi/500)]
h=freqs(b1,a1,wa)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
phase=angle(h)
Output
anfbutt(0.2*pi,0.3*pi,1,16)
T=
1
omp =
0.6498
oms =
1.0191
84
N=
6
order of filter=52.0f
wc =
0.7273
z=
[]
85
Magnitude plot
Magnitude
1.5
1
0.5
0
0.2
0.4
0.6
0.8
1
frequency in pi units
Magnitude(db) plot
1.2
1.4
1.6
0.2
0.4
0.6
0.8
1
frequency in pi units
Phase plot
1.2
1.4
1.6
0.2
0.4
0.6
0.8
1
frequency in pi units
1.2
1.4
1.6
Magnitude in db
1.5
1
0.5
0
angle in radians
4
2
0
-2
-4
86
[mag,phase]=freqs(b,a)
plot(abs(mag))
grid
[mag,dbh,phi,w]=freqsm(b,a)
subplot(3,1,1)
plot(w,dbh)
title('Magnitude(db) plot')
xlabel('frequency in pi units')
ylabel('Magnitude in db')
subplot(3,1,2)
plot(w,mag)
title('Magnitude plot')
xlabel('frequency in pi units')
ylabel('Magnitude ')
subplot(3,1,3)
plot(w,phi)
grid
title('Phase plot')
xlabel('frequency in pi units')
ylabel('angle in radians')
% %nr=buttord(wp,ws,rp,rs)
% %ceil(N)
function[mag,dbh,phi,w]=freqsm(b,a)
wmax=0.5*pi
w=[0:500]*wmax/500
h=freqs(b,a,w)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
phi=angle(h)
output
butterh1(0.2*pi,0.3*pi,1,16
w=
0.4444
p=
-0.3522
M=
0.0067
87
q=
-2.1758
N=
7
wc =
0.6920
b=
1
a=
1.0000
3.1097
4.8353
4.8350
3.3457
1.6022
0.4934
0.0760
88
Magnitude(db) plot
Magnitude in db
200
0
-200
-400
0.2
0.4
0.6
0.8
1
frequency in pi units
Magnitude plot
1.2
1.4
1.6
0.2
0.4
0.6
0.8
1
frequency in pi units
Phase plot
1.2
1.4
1.6
0.2
0.4
0.6
0.8
1
frequency in pi units
1.2
1.4
1.6
Magnitude
0.5
angle in radians
-5
w=(wp/ws)^2
p=log10(w)
M=(10^(rp/10)-1)/(10^(rs/10)-1)
q=log10(M)
N=ceil(q/p)
wc=wp/(10^(rp/10)-1)^(1/(2*N))
wc=[wp/pi,ws/pi]
89
[b,a]=butter(N,wc,'bandpass','s')
[mag,phase]=freqs(b,a)
plot(abs(mag))
grid
[dbh,w,mag,phi]=freqsm(b,a)
subplot(3,1,1)
plot(w,dbh)
grid
title('Magnitude(db) plot')
xlabel('frequency in pi units')
ylabel('Magnitude in db')
subplot(3,1,2)
plot(w,mag)
grid
title('Magnitude plot')
xlabel('frequency in pi units')
ylabel('Magnitude')
subplot(3,1,3)
plot(w,phi)
grid
title('Phase plot')
xlabel('frequency in pi units')
ylabel('angle in radians')
% %nr=buttord(wp,ws,rp,rs)
% %ceil(N)
function[dbh,w,mag,phi]=freqsm(b,a)
wmax=0.5*pi
w=[0:500]*wmax/500
h=freqs(b,a,w)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
phi=angle(h)
Output
butterpa1(1,16,0.2*pi,0.3*pi)
w=
0.4444
p=
90
-0.3522
M=
0.0067
q=
-2.1758
N=
7
wc =
0.6920
wc =
0.2000
0.3000
91
Magnitude(db) plot
Magnitude in db
200
0
-200
-400
0.2
0.4
0.6
0.8
1
frequency in pi units
Magnitude plot
1.2
1.4
1.6
0.2
0.4
0.6
0.8
1
frequency in pi units
Phase plot
1.2
1.4
1.6
0.2
0.4
0.6
0.8
1
frequency in pi units
1.2
1.4
1.6
Magnitude
1.5
1
0.5
0
angle in radians
4
2
0
-2
-4
92
wc=[wp/pi,ws/pi]
[b,a]=butter(N,wc,'stop','s')
[mag,phase]=freqs(b,a)
plot(abs(mag))
grid
[dbh,w,mag,phi]=freqsm(b,a)
subplot(3,1,1)
plot(w,dbh)
subplot(3,1,2)
plot(w,mag)
subplot(3,1,3)
plot(w,phi)
grid
%n=buttord(wp,ws,rp,rs)
%ceil(N)
function[dbh,w,mag,phi]=freqsm(b,a)
wmax=0.5*pi
w=[0:500]*wmax/500
h=freqs(b,a,w)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
phi=angle(h)
Output
butterst1(1,16,0.2*pi,0.3*pi)
w=
0.4444
p=
-0.3522
M=
0.0067
q=
-2.1758
93
N=
7
wc =
0.6920
wc =
0.2000
0.3000
94
M a g n it u d e (d b ) p lo t
M agnitude in db
500
0
-5 0 0
0
0 .2
0 .4
0 .6
0 .8
1
1 .2
fr e q u e n c y i n p i u n i t s
M a g n it u d e p lo t
1 .4
1 .6
0 .2
0 .4
0 .6
0 .8
1
1 .2
fr e q u e n c y i n p i u n i t s
P h a s e p lo t
1 .4
1 .6
0 .2
0 .4
0 .6
0 .8
1
1 .2
fr e q u e n c y i n p i u n i t s
1 .4
1 .6
M agnitude
2
1
0
angle in radians
5
0
-5
95
[mag,phase]=freqz(b,a)
plot(abs(mag))
grid
[mag,dbh,phi,w]=freqsm(b,a)
subplot(3,1,1)
plot(w,dbh)
grid
title('Magnitude(db) plot')
xlabel('frequency in pi units')
ylabel('Magnitude in db')
subplot(3,1,2)
plot(w,mag)
grid
title('Magnitude(db) plot')
xlabel('frequency in pi units')
ylabel('Magnitude in db')
subplot(3,1,3)
plot(w,phi)
grid
title('Phase plot')
xlabel('frequency in pi units')
ylabel('angle in radians')
% %ceil(N)
function[mag,dbh,phi,w]=freqsm(b,a)
wmax=0.5*pi
w=[0:500]*wmax/500
h=freqz(b,a,w)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
phi=angle(h)
Output
butterdigl(1,16,0.2,0.3)
96
Magnitude(db) plot
Magnitude in db
50
0
-50
-100
0.2
0.4
0.6
0.8
1
frequency in pi units
Magnitude(db) plot
1.2
1.4
1.6
0.2
0.4
0.6
0.8
1
frequency in pi units
Phase plot
1.2
1.4
1.6
0.2
0.4
0.6
0.8
1
frequency in pi units
1.2
1.4
1.6
Magnitude in db
1.5
1
0.5
0
angle in radians
-5
97
[mag,phase]=freqz(b,a)
plot(abs(mag))
grid
[mag,dbh,phi,w]=freqsm(b,a)
subplot(3,1,1)
plot(w,dbh)
grid
title('Magnitude(db) plot')
xlabel('frequency in pi units')
ylabel('Magnitude in db')
subplot(3,1,2)
plot(w,mag)
grid
title('Magnitude(db) plot')
xlabel('frequency in pi units')
ylabel('Magnitude in db')
subplot(3,1,3)
plot(w,phi)
grid
title('Phase plot')
xlabel('frequency in pi units')
ylabel('angle in radians')
% %ceil(N)
function[mag,dbh,phi,w]=freqsm(b,a)
wmax=0.5*pi
w=[0:500]*wmax/500
h=freqz(b,a,w)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
phi=angle(h)
Output
butterdigh(0.2*pi,0.3*pi,1,16)
98
Magnitude(db) plot
Magnitude in db
200
0
-200
-400
0.2
0.4
0.6
0.8
1
frequency in pi units
Magnitude(db) plot
1.2
1.4
1.6
0.2
0.4
0.6
0.8
1
frequency in pi units
Phase plot
1.2
1.4
1.6
0.2
0.4
0.6
0.8
1
frequency in pi units
1.2
1.4
1.6
Magnitude in db
0.5
angle in radians
-5
99
[mag,dbh,phi,w]=freqsm(b,a)
subplot(3,1,1)
plot(w,dbh)
grid
title('Magnitude(db) plot')
xlabel('frequency in pi units')
ylabel('Magnitude in db')
subplot(3,1,2)
plot(w,mag)
grid
title('Magnitude plot')
xlabel('frequency in pi units')
ylabel('Magnitude')
subplot(3,1,3)
plot(w,phi)
grid
title('Phase plot')
xlabel('frequency in pi units')
ylabel('angle in radians')
% %ceil(N)
function[mag,dbh,phi,w]=freqsm(b,a)
wmax=0.5*pi
w=[0:500]*wmax/500
h=freqz(b,a,w)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
phi=angle(h)
Output
butterdigbp(0.2,0.3,1,16)
100
Magnitude(db) plot
Magnitude in db
200
0
-200
-400
0.2
0.4
0.6
0.8
1
frequency in pi units
Magnitude plot
1.2
1.4
1.6
0.2
0.4
0.6
0.8
1
frequency in pi units
Phase plot
1.2
1.4
1.6
0.2
0.4
0.6
0.8
1
frequency in pi units
1.2
1.4
1.6
Magnitude
1.5
1
0.5
0
angle in radians
-5
101
[dbh,w,mag,phi]=freqsm(b,a)
subplot(3,1,1)
plot(w,dbh)
subplot(3,1,2)
plot(w,mag)
subplot(3,1,3)
plot(w,phi)
grid
% %ceil(N)
function[dbh,w,mag,phi]=freqsm(b,a)
wmax=0.5*pi
w=[-500:500]*wmax/500
h=freqz(b,a,w)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
phi=angle(h)
Output
butterdigst1(0.2,0.3,1,16)
102
Magnitude(db) plot
Magnitude in db
50
0
-50
-100
-2
-1.5
-1
-0.5
0
0.5
frequency in pi units
Magnitude(db) plot
1.5
-1.5
-1
-0.5
0
0.5
frequency in pi units
Phase plot
1.5
-1.5
-1
-0.5
0
0.5
frequency in pi units
1.5
Magnitude in db
1.5
1
0.5
0
-2
angle in radians
-5
-2
103
fprintf('order of filter=%2.0f',n)
omc=omp/((10^(rp/10)-1)^(1/(2*n)))
wc=(2/T)*tan(omc*T/2)
wc=wc/pi
[b,a]=butter(n,wc)
[mag,dbh,pha,w]=freqzm(b,a)
subplot(3,2,1)
plot(w,dbh)
title('magnitude(db) plot')
xlabel('frequency in pi units')
ylabel(' magnitude in db')
grid
subplot(3,2,2)
plot(w,mag)
title('magnitude plot')
xlabel('frequency in pi units')
ylabel(' magnitude in db')
grid
subplot(3,2,3)
plot(w,pha)
title('phase plot')
xlabel('frequency in pi units')
ylabel(' angle in radians ')
grid
n1=0:499
n0=0
x1=[(n1-n0)==0]
y1=filter(b,a,x1)
subplot(3,2,4)
plot(w,y1)
axis([0,0.5,-1,1])
title('impulse response')
xlabel('frequency in pi units')
ylabel(' magnitude')
grid
x2=sin(0.1*pi*n1)
y2=filter(b,a,x2)
subplot(3,2,5)
plot(w,y2)
axis([0,1,-2,2])
title('pass region')
xlabel('frequency in pi units')
ylabel(' magnitude')
grid
x3=sin(0.3*pi*n1)
y3=filter(b,a,x3)
subplot(3,2,6)
plot(w,y3)
axis([0,1,-3,3])
title('stop region')
xlabel('frequency in pi units')
ylabel(' magnitude')
grid
104
function[mag,dbh,pha,w]=freqzm(b,a)
[h,w]=freqz(b,a,500)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
pha=angle(h)
Output
>> butterdigl(0.2*pi,0.3*pi,1,16)
1
2
3
frequency in pi units
phase plot
magnitude
5
0
-5
1
2
3
frequency in pi units
pass region
magnitude
angle in radians
-500
0
-2
magnitude in db
magnitude plot
magnitude
magnitude in db
magnitude(db) plot
500
0.5
frequency in pi units
2
1
0
1
2
3
frequency in pi units
impulse response
0.1
0.2 0.3
0.4
frequency in pi units
stop region
0.5
frequency in pi units
1
0
-1
2
0
-2
1
105
Chebshew filters
%analog chebyshew low pass filter analog
%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=chebalo1(wp,ws,rp,rs)
[N,wc]=cheb1ord(wp,ws,rp,rs,'s')
%wc=[wp/pi,ws/pi]
[b,a]=cheby1(N,0.5,wc,'low','s')
% [mag,phase]=freqz(b,a)
% plot(abs(mag))
% grid
[dbh,w,mag,phi]=freqsm(b,a)
subplot(3,1,1)
plot(w,dbh)
subplot(3,1,2)
plot(w,mag)
subplot(3,1,3)
plot(w,phi)
grid
% %ceil(N)
function[dbh,w,mag,phi]=freqsm(b,a)
wmax=0.5*pi
w=[-500:500]*wmax/500
h=freqs(b,a,w)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
phi=angle(h)
Output
>> chebalo1(0.2*pi,0.3*pi,1,16)
106
20
0
-20
-40
-2
-1.5
-1
-0.5
0.5
1.5
-1.5
-1
-0.5
0.5
1.5
-1.5
-1
-0.5
0.5
1.5
0.5
0
-2
5
-5
-2
107
% %ceil(N)
function[dbh,w,mag,phi]=freqsm(b,a)
wmax=0.5*pi
w=[-500:500]*wmax/500
h=freqs(b,a,w)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
phi=angle(h)
-1.5
-1
-0.5
0.5
1.5
-1.5
-1
-0.5
0.5
1.5
-1.5
-1
-0.5
0.5
1.5
0.5
0
-2
5
-5
-2
108
Cheb bandpass
%analog chebyshew low pass filter analog
%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=chebalo1(wp,ws,rp,rs)
[N,wc]=cheb1ord(wp,ws,rp,rs,'s')
wc=[wp/pi,ws/pi]
[b,a]=cheby1(N,0.5,wc,'bandpass','s')
% [mag,phase]=freqz(b,a)
% plot(abs(mag))
% grid
[dbh,w,mag,phi]=freqsm(b,a)
subplot(3,1,1)
plot(w,dbh)
subplot(3,1,2)
plot(w,mag)
subplot(3,1,3)
plot(w,phi)
grid
% %ceil(N)
function[dbh,w,mag,phi]=freqsm(b,a)
wmax=0.5*pi
w=[-500:500]*wmax/500
h=freqs(b,a,w)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
phi=angle(h)
Output
>> chebbps(0.2*pi,0.3*pi,1,16)
109
200
0
-200
-400
-2
-1.5
-1
-0.5
0.5
1.5
-1.5
-1
-0.5
0.5
1.5
-1.5
-1
-0.5
0.5
1.5
0.5
0
-2
5
-5
-2
110
function[dbh,w,mag,phi]=freqsm(b,a)
wmax=0.5*pi
w=[-500:500]*wmax/500
h=freqs(b,a,w)
mag=abs(h)
dbh=20*log10((mag+eps)/max(mag))
phi=angle(h)
-1.5
-1
-0.5
0.5
1.5
-1.5
-1
-0.5
0.5
1.5
-1.5
-1
-0.5
0.5
1.5
0.5
0
-2
5
-5
-2
111
N=ceil((rs+6-(20*log10(esp)))/(6+(20*log10(ws))))
wc=wp
wc=[wp/pi,ws/pi]
n=cheb1ord(0.2*pi,0.3*pi,1,16,'s')
[b,a]=cheby1(n,.5,wc,'bandpass','s')
[h,w]=freqs(b,a)
plot(w,abs(h))
Output >> chepshewbps(0.2*pi,0.3*pi,1,16)
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
10
112
Output
>> chepshewbp(0.2*pi,0.3*pi,1,16)
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
113
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
10
114
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
10
115
-3
5.5
x 10
4.5
3.5
2.5
10
116
2.2
2
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
10
117
-6
2.6
x 10
2.55
2.5
2.45
2.4
2.35
2.3
2.25
2.2
2.15
2.1
0
10
118
1.15
1.1
1.05
0.95
0.9
0.85
0.8
10
119