You are on page 1of 119

1.

Program to generate impulse function


function[n,x]=imp(n0,n1,n2)
n=[n1:n2]
x=[(n-n0)==0]
stem(n,x)
xlabel ( Time )
ylabel ( Amplitude )
title ( Impulse signal )
% n0=value at which impulse present
% n1=lower limit
% n2=upper limit
% x=sequence
% n=range

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

2. Program to generate step sequence


function[n,x]=stepf(n0,n1,n2)
n=[n1:n2]
x=[(n-n0)>=0]
stem(n,x)
xlabel ('time ')
ylabel ('amplitude ')
title ('step signal ')
%
%
%
%
%

n0=value at which impulse present


n1=lower limit
n2=upper limit
x=sequence
n=range

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

3.Program to generate sine sequence


function[]=sinege(n,w)
y=sin(w*n);
subplot(2,1,1)
plot(n,y)
xlabel ('time ')
ylabel ('amplitude ')
title ('sine signal ')
% n= range
%w=period in pi units

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

4.Program to generate periodic sequence


function[y]=periodseq(x,N)
m=ones(1,N)
x1=x'
y1=x1*m
y2=y1(:)
y=y2'
stem(y)
xlabel ('n.................. ')
ylabel ('y(n) ')
title ('periodic signal ')

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

5.Program to add two discrete signals


5

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

6.Program to subtract two discrete signals


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)
subplot(3,1,2)
stem(n,y2)
subplot(3,1,3)
stem(n,y3)

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

7. Program to multiply the signal


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)
subplot(3,1,2)
stem(n,y2)
subplot(3,1,3)
stem(n,y3)

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

8.Program to fold a sequence


function[]=seqfold(n1,n2,x)
n0=n1:n2
subplot(2,1,1)
stem(n0,x)
title('original sequence')
xlabel('time')
ylabel('amplitude')
y=fliplr(x)
n=-fliplr(n0)
subplot(2,1,2)
stem(n,y)
title('folded sequence')
xlabel('time')
ylabel('amplitude')

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

9.Program to shift the sequence


function[m,y]=shift(n0,n,x)
m=n+n0
y=x
subplot(2,1,1)
stem(n,x)
title('original sequence')
xlabel('range')
ylabel('sequence')
subplot(2,1,2)
stem(m,y)
xlabel('range')
ylabel('sequence')
title('shifted sequence')
%n=range
%x=seq
%n0=value of shift

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

10 . Program to find even and odd part of the


signal
function[]=evenodd(n,x)
n1=-fliplr(n)
x1=fliplr(x)
subplot(2,2,1)
stem(n,x)
title('original signal')
xlabel('n')
ylabel('amp')
n2=min(min(n),min(n1)):max(max(n),max(n1))
y1=zeros(1,length(n2))
y2=y1
a=(n2>=min(n) & n2<=max(n))
b=(n2>=min(n1) & n2<=max(n1))
y1(find(a))=x
y2(find(b))=x1
xe=(y1+y2)./2
x0=(y1-y2)./2
subplot(2,2,2)
stem(n2,xe)
title('even signal')
xlabel('n2')
ylabel('amp')
subplot(2,2,3)
stem(n2,x0)
title('odd signal')
xlabel('n2')
ylabel('amp')
z=xe+x0
subplot(2,2,4)
stem(n2,z)
title('result')
xlabel('n2')
ylabel('amp')

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

11.Program to find convolution of two


sequences
function[]=convol(x1,x2,n1,n2)
y=conv(x1,x2)
n=(min(n1)+min(n2)):(max(n1)+max(n2))
subplot(3,1,1)
stem(n1,x1)
subplot(3,1,2)
stem(n2,x2)
subplot(3,1,3)
stem(n,y)

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

12.Program to cross correlation of two


sequences
function[n,y]=correl(x1,x2,n1,n2)
n2=fliplr(-n2)
c= abs(length(n1)-length(n2))
y=xcorr(x1,x2)
n=(min(n1)+min(n2)):(max(n1)+max(n2))+c
subplot(3,1,1)
stem(n1,x1)
title('original 1 signal')
xlabel('n')
ylabel('amp')
subplot(3,1,2)
stem(n2,x2)
title('original 2 signal')
xlabel('n')
ylabel('amp')
subplot(3,1,3)
stem(n,y)
title('correlated signal')
xlabel('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

13.Program to find DTFT of finite sequence


function[X,w]=dtft(x,n)
k=[-100:100]
w=k*pi/100
X=x*exp(-j*pi/100).^(n'*k)
subplot(2,2,1)
plot(w/pi,abs(X))
title('magnitude plot')
xlabel('frequency in pi units')
ylabel('amplitude')

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

14. Program to compute DTFT of infinite


sequence of
(0.5 ^n)*u(n)
25

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

15. Program to prove symmetric property of


DTFT using
27

even or odd sequences


%x(n)=sin(n*pi/2) -5<=n<=10
%dtft(xe)=real(X)
%dtft(xo)=j*imag(X)
function[]=dtftsymm(x,n)
k=-100:100
w=pi*k/100
X=x*(exp(-j*pi./100)).^(n'*k)
[xe,xo,n2]=evenodd(x,n)
XE=xe*(exp(-j*pi/100)).^(n2'*k)
XO=xo*(exp(-j*pi/100)).^(n2'*k)
err=max(abs(XE-real(X)))
err1=max(abs(XO-j*imag(X)))
subplot(2,2,1)
plot(w/pi,real(XE))
title('Transform of even part ')
xlabel('Frequency in pi units')
ylabel('XE')
subplot(2,2,2)
plot(w/pi,real(X))
title(' Real part of X ')
xlabel('Frequency in pi units')
ylabel('XE')
subplot(2,2,3)
plot(w/pi,imag(XO))
title('transform of odd part ')
xlabel('frequency in pi units')
ylabel('XO')
subplot(2,2,4)
plot(w/pi,imag(X))
title('imaginary part of X ')
xlabel('frequency in pi units')
ylabel('XO')

Output:
symmetry([1 2 3 4],0:3)
err =
3.0642e-014
err1 =
3.0642e-014

28

29

16. Program to prove conjugate property of


DTFT using
even or odd sequences
%conj(x)=conj(X(-w))
function[]=dtftconj(x,n)
k=-100:100
w=pi*k/100
X=x*(exp(-j*pi./100)).^(n'*k)
y=conj(x)
Y1=y*(exp(-j*pi./100)).^(n'*k)
Y2=conj(fliplr(X))
err=max(abs(Y1-Y2))
subplot(2,2,1)
plot(w/pi,abs(X))
title('magnitude part ')
xlabel('frequency in pi units')
ylabel('mag of X')
subplot(2,2,2)
plot(w/pi,angle(X))
title(' phase part ')
xlabel('frequency in pi units')
ylabel('angle in radian')
subplot(2,2,3)
plot(w/pi,abs(Y2))
title('magnitude part ')
xlabel('frequency in pi units')
ylabel('magnitude of Y')
subplot(2,2,4)
plot(w/pi,angle(Y2))
title('angle of Y ')
xlabel('frequency in pi units')
ylabel('angle in radians')

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

17. Program to verify the linearity property of


DTFT
function[]=linprop(x1,x2,a,b,n)
[X1,w]=dtft(x1,n)
[X2,w]=dtft(x2,n)
x3=a*x1+b*x2
[X3,w]=dtft(x3,n)
subplot(2,1,1)
plot(w,abs(X3))
title('dtft of a*x1+b*x2')
xlabel(' frequency in pi units')
ylabel(' magnitude part')
X4=a*[X1]+b*[X2]
subplot(2,1,2)
plot(w,abs(X4))
title('dtft of a*[X1]+b*[X2]')
xlabel(' frequency in pi units')
ylabel(' magnitude part')

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

18. Program to verify frequency shift property of DTFT


%X(n)=cos(n*pi/2) 0<=n<=100
function[err]=freqsh(x,n)
k=-100:100
w=pi*k/100
X=x*(exp(-j*pi/100)).^(n'*k)
y=x.*(exp(j*pi*n./2))
Y1=y*(exp(-j*pi/100)).^(n'*k)
Y2=x*(exp(-j*pi/100)).^(n'*(k-50))
err=max(abs(Y1-Y2))
subplot(2,1,1)
plot(w/pi,abs(X))
subplot(2,1,2)
plot(w/pi,abs(Y1))
subplot(2,2,1)
plot(w/pi,abs(X))
title('magnitude part ')
xlabel('frequency in pi units')
ylabel('magnitude of x')
subplot(2,2,2)
plot(w/pi,angle(X))
title('phase part ')
xlabel('frequency in pi units')
ylabel('angle in radians')
subplot(2,2,3)
plot(w/pi,abs(Y2))
title('magnitude part of x')
xlabel('frequency in pi units')
ylabel('magnitude of Y')
subplot(2,2,4)
plot(w/pi,angle(Y2))
title('angle of Y ')
xlabel('frequency in pi units')
ylabel('angle in radians')

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

19. Program to verify periodicity property of


DTFT
function[]=period()
k=-100:100
w=pi*k/100
n=0:10
x=0.9*(exp(j*pi/3)).^n
X=x*(exp(-j*pi/100)).^(n'*k)
magx=abs(X)
phasex=angle(X)
realx=real(X)
imagx=imag(X)
subplot(2,2,1)
plot(w/pi,magx)
title('magnitude part ')
xlabel('frequency in pi units')
ylabel('magnitude')
subplot(2,2,2)
plot(w/pi,phasex)
title('phase part ')
xlabel('frequency in pi units')
ylabel('angle in radians')
subplot(2,2,3)
plot(w/pi,realx)
title('real part ')
xlabel('frequency in pi units')
ylabel('real')
subplot(2,2,4)
plot(w/pi,imagx)
title('imaginary part ')
xlabel('frequency in pi units')
ylabel('imaginary')

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

20.Program to verify time shifting property of


DTFT
function[] = dtftshift()
n = -10:10;
x = (-0.9) .^ n
k = 0:500;
w = (pi/500)*k
n1=-2
m = shift(n,x,n1)
X = x*(exp(-j*pi/500) .^ (n'*k))
x1 = exp(-j*2) .^ w
X1 = X .* x1
X2 = x*(exp(-j*pi/500) .^ (m'*k))
subplot(2,2,1)
plot(w/pi,abs(X1))
grid
title('Magnitude Part')
subplot(2,2,2)
plot(w/pi,angle(X1))
grid
title('Phase Part')
subplot(2,2,3)
plot(w/pi,abs(X2))
grid
title('Magnitude Part')
subplot(2,2,4)
plot(w/pi,angle(X2))
grid
title('Phase Part')

38

Output:
dtftshift()

39

21. Program to find DFS of finite sequence


function[xk]=dfs(xn,N)
n=0:N-1
k=0:N-1
wn=exp(-j*2*pi/N)
nk=n'*k
wnk=wn.^nk
xk=(xn*wnk)*(1./N)
magx=abs(xk)
phasex=angle(xk)
realx=real(xk)
imagx=imag(xk)
subplot(2,2,1)
stem(n,magx)
title('magnitude plot')
xlabel('frequency in pi units')
ylabel('magnitude')
subplot(2,2,2)
stem(n,phasex)
title('phase part')
xlabel('frequency in pi units')
ylabel('angle in rad')
subplot(2,2,3)
stem(n,realx)
title('real plot')
xlabel('frequency in pi units')
ylabel('real part')
subplot(2,2,4)
stem(n,imagx)
title('imaginary plot')
xlabel('frequency in pi units')
ylabel('imaginary part')

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

-0.5000 + 0.5000i -0.5000 - 0.0000i -0.5000 - 0.5000i

magx =
2.5000

0.7071

0.5000

0.7071

phasex =
0

2.3562 -3.1416 -2.3562

realx =
2.5000 -0.5000 -0.5000 -0.5000
imagx =
0

0.5000 -0.0000 -0.5000

ans =
2.5000

-0.5000 + 0.5000i -0.5000 - 0.0000i -0.5000 - 0.5000i

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

22. Program to find IDFS of finite sequence


function[y]=idfs(xn,N)
n=0:N-1
k=0:N-1
wn=exp(j*2*pi/N)
nk=(n'*k)
wnk=wn.^nk
y=(xn*wnk)
magx=abs(y)
phasex=angle(y)
realx=real(y)
imagx=imag(y)
subplot(2,2,1)
stem(n,magx)
title('magnitude plot')
xlabel('frequency in pi units')
ylabel('magnitude')
subplot(2,2,2)
stem(n,phasex)
title('phase part')
xlabel('frequency in pi units')
ylabel('angle in rad')
subplot(2,2,3)
stem(n,realx)
title('real plot')
xlabel('frequency in pi units')
ylabel('real part')
subplot(2,2,4)
stem(n,imagx)
title('imaginary plot')
xlabel('frequency in pi units')
ylabel('imaginary part')

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

2.0000 + 0.0000i 3.0000 - 0.0000i 4.0000 - 0.0000i

magx =
1

phasex =
1.0e-015 *
0

0.0306 -0.0408 -0.1378

realx =
1

imagx =
1.0e-015 *
0

0.0612 -0.1225 -0.5511

ans =
1.0000

2.0000 + 0.0000i 3.0000 - 0.0000i 4.0000 - 0.0000i

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

24. Program to do down sampling


function[]=downsamp(x,n,D)
subplot(2,1,1)
stem(n,x)
title('original')
xlabel('n-- range')
ylabel('amp--sequence')
n1=n/D
n2=round(n1)
for k=(1:1:length(n1))
if(n1(k)==n2(k))
subplot(2,1,2)
stem(n1(k),x(k))
hold on
end
end
title('result')
xlabel('n--range')
ylabel('amp--sequence')

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

25.Program to find Z transformation


function[y]=ztr()
b=input(' Enter numerator co-efficient')
a=input('Enter denomenator co-efficient')
subplot(2,1,1)
zplane(b,a)
title('pole-zero plot')
xlabel('Real part')
ylabel('Imaginary part')
n=0:10
x=[(n-0)==0]
y=filter(b,a,x)
subplot(2,1,2)
stem(n,y)
title('Impulse response')
xlabel('n----------->')
ylabel('y----------->')

Output:
ztr1
Enter numerator co-efficient[0 0.25]
b=
0

0.2500

Enter denomenator co-efficient[1 0.25]


a=
1.0000

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

26.Program to find Inverse Z transformation


function[]=iztr()
b=input(' Enter numerator co-efficient')
a=input('Enter denomenator co-efficient')
[r,p,k]=residuez(b,a)
zplane(b,a)
title('pole-zero plot')
xlabel('Real part')
ylabel('Imaginary part')

Output:
ztr
Enter numerator co-efficient [0 1]
b=
0

Enter denomenator co-efficient[1 2 3]


a=
r=

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

27.Program to find linear and circular


convolution using
FFT
function[]=lincir(x,h)
n=length(x)
m=length(h)
%linear convolution
N=n+m-1
k1=0:N-1
X=fft(x,N)
H=fft(h,N)
Y=X.*H
yl=abs(ifft(Y))
%circular convolution
N1=max(n,m)
k2=0:N1-1
X1=fft(x,N1)
H1=fft(h,N1)
Y1=X1.*H1
yc=abs(ifft(Y1))
subplot(2,2,1)
stem(0:n-1,x)
title('sequence x(n)')
xlabel('n----------->')
ylabel('x----------->')
subplot(2,2,2)
stem(0:m-1,h)
title('sequence h(n)')
xlabel('m----------->')
ylabel('h----------->')
subplot(2,2,3)
stem(k1,yl)
stem(0:n-1,x)
title('Linear convolution)')
xlabel('n----------->')
ylabel('y----------->')
subplot(2,2,4)
stem(k2,yc)
stem(0:n-1,x)
title('circular convolution)')
xlabel('n----------->')
ylabel('y----------->')

Output:
55

lincir([1 2 3 4 5],[1 2 3])


n=
5
m=
3
N=
7
k1 =
0

X=
Columns 1 through 4
15.0000

-6.5293 - 4.0546i 3.4635 - 1.4300i -0.9342 + 2.4527i

Columns 5 through 7
-0.9342 - 2.4527i 3.4635 + 1.4300i -6.5293 + 4.0546i
H=
Columns 1 through 4
6.0000

1.5794 - 4.4884i -2.1479 - 0.6482i 1.0685 + 1.4777i

Columns 5 through 7
1.0685 - 1.4777i -2.1479 + 0.6482i 1.5794 + 4.4884i
Y=
Columns 1 through 4
90.0000

-28.5112 +22.9026i -8.3663 + 0.8266i -4.6225 + 1.2403i

Columns 5 through 7
-4.6225 - 1.2403i -8.3663 - 0.8266i -28.5112 -22.9026i

56

yl =
1.0000

4.0000 10.0000 16.0000 22.0000 22.0000 15.0000

N1 =
5
k2 =
0

X1 =
Columns 1 through 4
15.0000

-2.5000 + 3.4410i -2.5000 + 0.8123i -2.5000 - 0.8123i

Column 5
-2.5000 - 3.4410i
H1 =
Columns 1 through 4
6.0000

-0.8090 - 3.6655i 0.3090 + 1.6776i 0.3090 - 1.6776i

Column 5
-0.8090 + 3.6655i
Y1 =
Columns 1 through 4
90.0000

14.6353 + 6.3799i -2.1353 - 3.9430i -2.1353 + 3.9430i

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

28.Program to find correlation of two


sequences using
overlap save
function[]=ovlsav(x,h,N)
lx=length(x)
lh=length(h)
m=lh-1
L=N-m
h1=[h,zeros(1,N-lh)]
x1=[zeros(1,m),x,zeros(1,N-1)]
k=floor((lx+m-1)/L)
y=zeros(k+1,N)
for p=0:k
xk=x1(p*L+1:p*L+N)
y(p+1,:)=circon(xk,h1,N)
end
y1=y(:,m:N)
z=y1(:)'

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

29.Program to find correlation of two sequence


using
overlap add
function[]=ovladd(x,h,N)
lx=length(x)
lh=length(h)
m=lh-1
L=N-m
h1=[h,zeros(1,N-lh)]
x1=[x,zeros(1,N-1)]
x2=length(x1)
nb=floor(lx/L)
Z=zeros(1,x2+m)
for k=0:nb
xk=[x1(k*L+1:k*L+L),zeros(1,m)]
temp=circon(xk,h,N)
Z(1,k*L+1:k*L+N)=Z(1,k*L+1:k*L+N)+temp
end

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

30.Circular convolution of N points using DFT


function[y2]=circon(x,y,N)
n=0:N-1
k=0:N-1
x1=[x,zeros(1,N-length(x))];
y1=[y,zeros(1,N-length(y))];
X1=x1*(exp(-j*2*pi/N)).^(n'*k)
Y1=y1*(exp(-j*2*pi/N)).^(n'*k)
Z=X1.*Y1
xf=Z*(exp(j*2*pi/N)).^(n'*k)./N
subplot(3,1,1)
stem(n,x1)
title('sequence x(n)')
xlabel('n----->')
ylabel('amp---->')
subplot(3,1,2)
stem(n,y1)
title('sequence y(n)')
xlabel('n----->')
ylabel('amp---->')
subplot(3,1,3)
stem(n,xf)
title('convolved sequence ')
xlabel('n----->')
ylabel('amp---->')

Output:
circondft([1 2 3 4],[2 0 0 1],4)
n=
0

k=
0
X1 =
10.0000

-2.0000 + 2.0000i -2.0000 - 0.0000i -2.0000 - 2.0000i

62

Y1 =
3.0000

2.0000 + 1.0000i 1.0000 - 0.0000i 2.0000 - 1.0000i

Z=
30.0000

-6.0000 + 2.0000i -2.0000 - 0.0000i -6.0000 - 2.0000i

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

31.Program to correlate the 2 signals


function[n,y]=correl(x1,x2,n1,n2)
n2=fliplr(-n2)
c= abs(length(n1)-length(n2))
y=xcorr(x1,x2)
n=(min(n1)+min(n2)):(max(n1)+max(n2))+c
subplot(3,1,1)
stem(n1,x1)
title('original 1 signal')
xlabel('n')
ylabel('amp')
subplot(3,1,2)
stem(n2,x2)
title('original 2 signal')
xlabel('n')
ylabel('amp')
subplot(3,1,3)
stem(n,y)
title('correlated signal')
xlabel('n')
ylabel('amp')

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

32. Circular correlation of N points using DFT


function[y2]=circorre(x,y,N)
n=0:N-1
k=0:N-1
x1=[x,zeros(1,N-length(x))];
y1=[y,zeros(1,N-length(y))];
X1=x1*(exp(-j*2*pi/N)).^(n'*k)
Y1=y1*(exp(-j*2*pi/N)).^(n'*k)
Z=X1.*conj(Y1)
xf=Z*(exp(j*2*pi/N)).^(n'*k)./N
subplot(3,1,1)
stem(n,x1)
title('sequence x(n)')
xlabel('n----->')
ylabel('amp---->')
subplot(3,1,2)
stem(n,y1)
title('sequence y(n)')
xlabel('n----->')
ylabel('amp---->')
subplot(3,1,3)
stem(n,xf)
title('correlated sequence ')
xlabel('n----->')
ylabel('amp---->')

Output:
circorre([1 2 3 4],[2 0 0 1],4)
n=
0

k=
0
X1 =
10.0000

-2.0000 + 2.0000i -2.0000 - 0.0000i -2.0000 - 2.0000i

Y1 =

66

3.0000

2.0000 + 1.0000i 1.0000 - 0.0000i 2.0000 - 1.0000i

Z=
30.0000

-2.0000 + 6.0000i -2.0000 - 0.0000i -2.0000 - 6.0000i

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

33.Circular fold property of given sequence


function[]=cif(x,N)
m=0:N-1
y=zeros(N-length(x))
x1=[x,y]
n=mod(-m,N)+1
x1=x(n)
subplot(2,1,1)
stem(x)
title('original')
xlabel('range')
ylabel('sequence')
subplot(2,1,2)
stem(x1)
title('original')
xlabel('range')
ylabel('sequence')

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

34.Program to verify frequency shifting


property of
DTFT
function[] = dtftfreq()
k = -100:100
n = 0:100
x = cos(n*pi/2)
w = (pi*k/100)
X = x*exp(-j*pi/100).^(n'*k)
y = x.*exp(j*pi*n/4)
Y = y*exp(-j*pi/100).^(n'*k)
subplot(2,2,1)
plot(w/pi,abs(X))
title('Magnitude Part')
subplot(2,2,2)
plot(w/pi,angle(X)/pi)
title('Phase Part')
subplot(2,2,3)
plot(w/pi,abs(Y))
title('Magnitude Part')
subplot(2,2,4)
plot(w/pi,angle(Y)/pi)
title('Phase Part')

70

Output:
dtftfreq

71

35. Designing of Moving average digital Filter


function[]=maverage(b)
[h,w]=freqz(b,1,'whole')
magh=abs(h)
plot(w,magh)
title('Moving average digital filter')
xlabel('Frequency in radians')
ylabel('Magnitude')

Output:
maverage([1 4 71 14 45 ])

72

Moving average digital filter


140

120

Magnitude

100

80

60

40

20

3
4
Frequency in radians

36.Circular even and circular odd using DFT of


a
sequence
function[]=ceco(x,N)
n=0:N-1
xce=0.5*[x+x.*(mod(-n,N)+1)]
xco=0.5*[x-x.*(mod(-n,N)+1)]
Xk=dfta(x,N)
xe=dfta(xce,N)
xo=dfta(xco,N)
rx=real(Xk)
imgx=imag(Xk)
subplot(4,1,1)
stem(xe,rx)
title('even part')
xlabel('xe')
ylabel('real')
subplot(4,1,2)
stem(xo,imgx)
title('odd part')
xlabel('xo')
ylabel('imag')
subplot(4,1,3)

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

36.Circular shift of a sequence


%x-sequence
%N-No of samples to be shifted

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

37.FIR filter design freq sampling method(for


increased

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

38.FIR filter design freq sampling method


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
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)
z2=hamming(16)'.*xn1
[z3,w]=freqz(z2,1)
subplot(2,1,1)
plot(w,abs(z1))
subplot(2,1,2)

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

39.Convolution property of dtft


function[]=funconv(n1,n2,x1,x2)

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

%Analog low pass butterworth filter


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=abutlpf(rp,rs,wp,ws)
w=(wp/ws)^2
p=log10(w)
M=(10^(rp/10)-1)/(10^(rs/10)-1)
q=log10(M)
N=q/p
wc=wp/(10^(rp/10)-1)^(1/(2*N))
[b1,a1]=abutunb(N,wc)
[mag,phase]=freqs(b1,a1)
plot(abs(mag))

% %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

%Analog low pass butterworth filter


(in record)
%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%as=stop band attenuation
function[]=abu(wp,ws,rp,as)
T=1
omp=(2/T)*tan(wp*T/2)
oms=(2/T)*tan(ws*T/2)

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

Analog butterworth high pass filter


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=abuthpf1(wp,ws,rp,rs)
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))
[b,a]=butter(N,wc,'high','s')

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

%analog butterworth band pass filter


function[]=abutlpf1(rp,rs,wp,ws)
%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation

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

%analog butterworth stopband filter


function[]=abutlpf1(rp,rs,wp,ws)
%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
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))

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

%Digital butterworth low pass filter digital


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=abutlpf1(rp,rs,wp,ws)
% 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]
[N,w]=buttord(wp,ws,rp,rs)
[b,a]=butter(N,w)

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

%Digital butterworth high pass filter digital


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=abutlpf1(wp,ws,rp,rs)
% 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]
[N,w]=buttord(wp,ws,rp,rs)
[b,a]=butter(N,w,'high')

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

% Butterworth band pass filter digital


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=abutlpf1(wp,ws,rp,rs)
[N,wc]=buttord(wp,ws,rp,rs)
wc=[wp/pi,ws/pi]
[b,a]=butter(N,wc,'bandpass')
[mag,phase]=freqz(b,a)
plot(abs(mag))
grid

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

%analog butterworth stop band filter digital


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=abutlpf1(wp,ws,rp,rs)
[N,wc]=buttord(wp,ws,rp,rs)
wc=[wp/pi,ws/pi]
[b,a]=butter(N,wc,'stop')
% [mag,phase]=freqz(b,a)
% plot(abs(mag))
% grid

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

%analog butterworth low pass filter digital(in record)


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=abutlpf1(wp,ws,rp,rs)
T=1
omp=(2/T)*tan(wp*T/2)
oms=(2/T)*tan(ws*T/2)
n=ceil(log10((10^(rp/10)-1)/(10^(rs/10)-1))/(2*log10(omp/oms)))

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

Cheb high pass


%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,'high','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

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)

Output >> chebh(0.2*pi,0.3*pi,1,16)


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

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

Cheb stop band


%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,'stop','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)

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)

Output >> chebst(0.2*pi,0.3*pi,1,16)


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

Cheb analog easy


%analog chebshew band pass filter
%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=chelpf(wp,ws,rp,rs)
esp=sqrt((10^(rp/10))-1)

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

%analog chebshew stop band filter


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=chelpf(wp,ws,rp,rs)
esp=sqrt((10^(rp/10))-1)
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,'stop','s')
[h,w]=freqs(b,a)
plot(w,abs(h))

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

%analog chebshew low pass filter


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=chelpf(wp,ws,rp,rs)
esp=sqrt((10^(rp/10))-1)
N=ceil((rs+6-(20*log10(esp)))/(6+(20*log10(ws))))
wc=wp
n=cheb1ord(0.2*pi,0.3*pi,1,16,'s')
[b,a]=cheby1(N,.5,wc,'s')
[h,w]=freqs(b,a)
plot(w,abs(h))
Output >> chepshew(0.2*pi,0.3*pi,1,16)

113

1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0

10

%analog chebshew high pass filter


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=chelpf(wp,ws,rp,rs)
esp=sqrt((10^(rp/10))-1)
N=ceil((rs+6-(20*log10(esp)))/(6+(20*log10(ws))))
wc=wp
n=cheb1ord(0.2*pi,0.3*pi,1,16,'s')
[b,a]=cheby1(N,.5,wc,'high','s')
[h,w]=freqs(b,a)
plot(w,abs(h))
Output
>> chepshewh(0.2*pi,0.3*pi,1,16)

114

1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0

10

% chebshew low pass filter digital


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=chelpf(wp,ws,rp,rs)
esp=sqrt((10^(rp/10))-1)
N=ceil((rs+6-(20*log10(esp)))/(6+(20*log10(ws))))
wc=wp
%wc=[wp/pi,ws/pi]
n=cheb1ord(wp,ws,rp,rs)
[b,a]=cheby1(n,.5,wc)
[h,w]=freqs(b,a)
plot(w,abs(h))
Output
>> digchelow(0.2,0.3,1,16)

115

-3

5.5

x 10

4.5

3.5

2.5

10

% chebshew high pass filter digital


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=chelpf(wp,ws,rp,rs)
esp=sqrt((10^(rp/10))-1)
N=ceil((rs+6-(20*log10(esp)))/(6+(20*log10(ws))))
wc=wp
%wc=[wp/pi,ws/pi]
n=cheb1ord(wp,ws,rp,rs)
[b,a]=cheby1(n,.5,wc,'high')
[h,w]=freqs(b,a)
plot(w,abs(h))
Output
>> digcheh(0.2,0.3,1,16)

116

2.2
2
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2

10

% chebshew band pass filter digital


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=chelpf(wp,ws,rp,rs)
esp=sqrt((10^(rp/10))-1)
N=ceil((rs+6-(20*log10(esp)))/(6+(20*log10(ws))))
wc=wp
wc=[wp/pi,ws/pi]
n=cheb1ord(wp,ws,rp,rs)
[b,a]=cheby1(n,.5,wc,'bandpass')
[h,w]=freqs(b,a)
plot(w,abs(h))
Output
>> digcheband(0.2,0.3,1,16)

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

% chebshew stopband filter digital


%wp=pass band frequency
%ws=stop band frequency
%rp=pass band ripple
%rs=stop band attenuation
function[]=chelpf(wp,ws,rp,rs)
esp=sqrt((10^(rp/10))-1)
N=ceil((rs+6-(20*log10(esp)))/(6+(20*log10(ws))))
wc=wp
wc=[wp/pi,ws/pi]
n=cheb1ord(wp,ws,rp,rs)
[b,a]=cheby1(n,.5,wc,'stop')
[h,w]=freqs(b,a)
plot(w,abs(h))
Output
>> digchest(0.2,0.3,1,16)

118

1.15

1.1

1.05

0.95

0.9

0.85

0.8

10

119

You might also like