digital signal processing-chapter 16: matlab programs
TRANSCRIPT
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
1/96
MATLAB Programs
Chapter 1616.1 INTRODUCTION
MATLAB stands or MATrix LABoratory. It is a technical computing environment
or high perormance numeric computation and visualisation. It integrates numerical
analysis, matrix computation, signal processing and graphics in an easy-to-use
environment, where problems and solutions are expressed just as they are written
mathematically, without traditional programming. MATLAB allows us to express
the entire algorithm in a ew dozen lines, to compute the solution with great accuracy
in a ew minutes on a computer, and to readily manipulate a three-dimensional
display o the result in colour.
MATLAB is an interactive system whose basic data element is a matrix that
does not require dimensioning. It enables us to solve many numerical problems in a
raction o the time that it would take to write a program and execute in a language
such as FORTRAN, BASIC, or C. It also eatures a amily o application specifc
solutions, called toolboxes. Areas in which toolboxes are available include signal
processing, image processing, control systems design, dynamic systems simulation,
systems identifcation, neural networks, wavelength communication and others.
It can handle linear, non-linear, continuous-time, discrete-time, multivariable andmultirate systems. This chapter gives simple programs to solve specifc problems
that are included in the previous chapters. All these MATLAB programs have been
tested under version 7.1 o MATLAB and version 6.12 o the signal processing
toolbox.
16.2 REPRESENTATION OF BASIC SIGNALS
MATLAB programs or the generation o unit impulse, unit step, ramp, exponential,
sinusoidal and cosine sequences are as ollows.
% Program or the generation o unit impulse signal
clc;clear all;close all;
t522:1:2;
y5[zeros(1,2),ones(1,1),zeros(1,2)];subplot(2,2,1);stem(t,y);
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
2/96
816 Digital Signal Processing
ylabel(Amplitude --.);
xlabel((a) n --.);
% Program or the generation o unit step sequence [u(n)2 u(n 2 N]
n5input(enter the N value);
t50:1:n21;
y15ones(1,n);subplot(2,2,2);
stem(t,y1);ylabel(Amplitude --.);
xlabel((b) n --.);
% Program or the generation o ramp sequence
n15input(enter the length o ramp sequence);
t50:n1;
subplot(2,2,3);stem(t,t);ylabel(Amplitude --.);
xlabel((c) n --.);
% Program or the generation o exponential sequence
n25input(enter the length o exponential sequence);
t50:n2;
a5input(Enter the a value);
y25exp(a*t);subplot(2,2,4);
stem(t,y2);ylabel(Amplitude --.);xlabel((d) n --.);
% Program or the generation o sine sequence
t50:.01:pi;
y5sin(2*pi*t);gure(2);
subplot(2,1,1);plot(t,y);ylabel(Amplitude --.);
xlabel((a) n --.);
% Program or the generation o cosine sequence
t50:.01:pi;
y5cos(2*pi*t);
subplot(2,1,2);plot(t,y);ylabel(Amplitude --.);
xlabel((b) n --.);
As an example,
enter the N value 7
enter the length o ramp sequence 7
enter the length o exponential sequence 7
enter the a value 1
Using the above MATLAB programs, we can obtain the waveorms o the unit
impulse signal, unit step signal, ramp signal, exponential signal, sine wave signal and
cosine wave signal as shown in Fig. 16.1.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
3/96
MATLAB Programs 817
Fig. 16.1 Representation of Basic Signals (a) Unit Impulse Signal (b)Unit-stepSignal (c) Ramp Signal (d) Exponential Signal (e) Sinewave Signal (f)Cosine Wave Signal
2 1 0 1 2 0
0
2
2
4
4
6
6 8
nn
nn
0.2
0.21
0.2
0.4
0.4
2
0.4
0.6
0.6
3
4
5
6
7
0.6
0.8
0.8
0.8
1
1
1
0
000 2 4 6 8
0
(a)
Amplitude
Amplitude
Amplitude
Amplitude
(b)
(d)(c)
1
1
0.5
0.5
0.5
0.5
0
0
1
1
1.5
(e)
(f)
1.5
2.5
2.5
3
3
3.5
3.5
2
2
0
0
0.5
0.5
1
1
n
n
Amplitude
Amplitude
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
4/96
818 Digital Signal Processing
16.3 DISCRETE CONVOLUTION
16.3.1 Linear Convolution
Algorithm
1. Get two signalsx(m)and h(p)in matrix orm
2. The convolved signal is denoted asy(n)
3. y(n)is given by the ormula
y(n) 5 [ ( ) ( )]x k h n kk
=
where n50 to m1p2 1
4. Stop
% Program or linear convolution o the sequence x5[1, 2] and h5[1, 2, 4]
clc;
clear all;
close all;
x5input(enter the 1st sequence);
h5input(enter the 2nd sequence);
y5conv(x,h);
gure;subplot(3,1,1);
stem(x);ylabel(Amplitude --.);
xlabel((a) n --.);subplot(3,1,2);
stem(h);ylabel(Amplitude --.);
xlabel((b) n --.);
subplot(3,1,3);
stem(y);ylabel(Amplitude --.);
xlabel((c) n --.);
disp(The resultant signal is);y
As an example,
enter the 1st sequence [1 2]
enter the 2nd sequence [1 2 4]The resultant signal is
y51 4 8 8
Figure 16.2 shows the discrete input signalsx(n)and h(n)and the convolved output
signaly(n).
Fig. 16.2 (Contd.)
Am
plitude
n
0
0.5
1 1.1 1.2 1.3 1.4 1.5
(a)
1.6 1.7 1.8 1.9 2
1
1.5
2
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
5/96
MATLAB Programs 819
16.3.2 Circular Convolution
% Program or Computing Circular Convolution
clc;
clear;
a = input(enter the sequence x(n) = );
b = input(enter the sequence h(n) = );
n1=length(a);
n2=length(b);
N=max(n1,n2);
x = [a zeros(1,(N-n1))];
or i = 1:N
k = i;
or j = 1:n2
H(i,j)=x(k)* b(j);k = k-1;
i (k == 0)
k = N;
end
end
end
y=zeros(1,N);
M=H;
or j = 1:N
or i = 1:n2y(j)=M(i,j)+y(j);
end
end
disp(The output sequence is y(n)= );
disp(y);
Fig. 16.2 Discrete Linear Convolution
Amplitude
n
0
1
1 1.2 1.4 1.6 1.8 2
(b)
2.2 2.4 2.6 2.8 3
2
3
4
Amp
litude
n
0
2
1 1.5 2
(c)
2.5 3 3.5 4
4
6
8
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
6/96
820 Digital Signal Processing
stem(y);
title(Circular Convolution);
xlabel(n);ylabel(y(n));
As an Example,
enter the sequence x(n) = [1 2 4]
enter the sequence h(n) = [1 2]
The output sequence is y(n)= 9 4 8
% Program or Computing Circular Convolution with zero padding
clc;
close all;
clear all;g5input(enter the rst sequence);
h5input(enter the 2nd sequence);
N15length(g);
N25length(h);
N5max(N1,N2);
N35N12N2;
%Loop or getting equal length sequence
i(N350)
h5[h,zeros(1,N3)];
else
g5[g,zeros(1,2N3)];
end
%computation o circular convolved sequence
or n51:N,
y(n)50;
or i51:N,
j5n2i11;
i(j550)
j5N1j;
end
y(n)5y(n)1g(i)*h(j);
end
end
disp(The resultant signal is);y
As an example,
enter the rst sequence [1 2 4]
enter the 2nd sequence [1 2]
The resultant signal is y51 4 8 8
16.3.3 Overlap Save Method and Overlap Add method
% Program or computing Block Convolution using Overlap SaveMethod
Overlap Save Method
x=input(Enter the sequence x(n) = );
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
7/96
MATLAB Programs 821
h=input(Enter the sequence h(n) = );
n1=length(x);
n2=length(h);N=n1+n2-1;
h1=[h zeros(1,N-n1)];
n3=length(h1);
y=zeros(1,N);
x1=[zeros(1,n3-n2) x zeros(1,n3)];
H=t(h1);
or i=1:n2:N
y1=x1(i:i+(2*(n3-n2)));
y2=t(y1);
y3=y2.*H;y4=round(it(y3));
y(i:(i+n3-n2))=y4(n2:n3);
end
disp(The output sequence y(n)=);
disp(y(1:N));
stem(y(1:N));
title(Overlap Save Method);
xlabel(n);
ylabel(y(n));
Enter the sequence x(n) = [1 2 -1 2 3 -2 -3 -1 1 1 2 -1]
Enter the sequence h(n) = [1 2 3 -1]
The output sequence y(n) = 1 4 6 5 2 11 0 -16 -8 3 8 5 3 -5 1
%Program or computing Block Convolution using Overlap AddMethod
x=input(Enter the sequence x(n) = );
h=input(Enter the sequence h(n) = );
n1=length(x);
n2=length(h);
N=n1+n2-1;
y=zeros(1,N);
h1=[h zeros(1,n2-1)];
n3=length(h1);
y=zeros(1,N+n3-n2);
H=t(h1);
or i=1:n2:n1
i i
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
8/96
822 Digital Signal Processing
y(1:n3)=x4(1:n3);
else
y(i:i+n3-1)=y(i:i+n3-1)+x4(1:n3);end
end
disp(The output sequence y(n)=);
disp(y(1:N));
stem((y(1:N));
title(Overlap Add Method);
xlabel(n);
ylabel(y(n));
As an Example,
Enter the sequence x(n) = [1 2 -1 2 3 -2 -3 -1 1 1 2 -1]Enter the sequence h(n) = [1 2 3 -1]
The output sequence
y(n) = 1 4 6 5 2 11 0 -16 -8 3 8 5 3 -5 1
16.4 DISCRETE CORRELATION
16.4.1 Crosscorrelation
Algorithm
1. Get two signalsx(m)and h(p)in matrix orm
2. The correlated signal is denoted asy(n)
3. y(n)is given by the ormula
y(n) 5 [ ( ) ( )]x k h k nk
=
where n52 [max (m,p)2 1] to [max (m,p)2 1]
4. Stop
% Program or computing cross-correlation o the sequences
x5[1, 2, 3, 4] and h5[4, 3, 2, 1]clc;
clear all;
close all;
x5input(enter the 1st sequence);
h5input(enter the 2nd sequence);
y5xcorr(x,h);
gure;subplot(3,1,1);
stem(x);ylabel(Amplitude --.);
xlabel((a) n --.);
subplot(3,1,2);
stem(h);ylabel(Amplitude --.);
xlabel((b) n --.);
subplot(3,1,3);
stem(fiplr(y));ylabel(Amplitude --.);
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
9/96
MATLAB Programs 823
xlabel((c) n --.);
disp(The resultant signal is);fiplr(y)
As an example,enter the 1st sequence [1 2 3 4]
enter the 2nd sequence [4 3 2 1]
The resultant signal is
y51.0000 4.0000 10.0000 20.0000 25.0000 24.0000 16.0000
Figure 16.3 shows the discrete input signalsx(n)and h(n)and the cross-correlated
output signaly(n).
Amplitude
Amplitu
de
Amplitude
n
n
n
0
0
1
1
1
1
1
1.5
1.5
2
2
2
3
3
3
5
2.5
2.5
4
(a)
(b)
(c)
3.5
3.5
6
4
4
7
2
2
3
3
4
4
30
20
10
0
Fig. 16.3 Discrete Cross-correlation
16.4.2 Autocorrelation
Algorithm
1. Get the signalx(n)o lengthNin matrix orm
2. The correlated signal is denoted asy(n)
3. y(n)is given by the ormula
y(n) 5 [ ( ) ( )]x k x k nk
=
where n52(N2 1) to (N2 1)
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
10/96
824 Digital Signal Processing
% Program or computing autocorrelation unction
x5input(enter the sequence);
y5xcorr(x,x);
gure;subplot(2,1,1);
stem(x);ylabel(Amplitude --.);
xlabel((a) n --.);
subplot(2,1,2);
stem(fiplr(y));ylabel(Amplitude --.);
xlabel((a) n --.);
disp(The resultant signal is);fiplr(y)
As an example,
enter the sequence [1 2 3 4]
The resultant signal is
y54 11 2030 20 11 4
Figure 16.4 shows the discrete input signal x(n)and its auto-correlated output
signaly(n).
( )
Amplitude
Amplitude
n
n
0
1
1
1
1.5
2
2
3
3
(a)
5
2.5
4
(b) y (n)
3.5
6
4
7
2
3
4
0
5
10
15
20
2530
Fig. 16.4 Discrete Auto-correlation
16.5 STABILITY TEST
% Program or stability test
clc;clear all;close all;
b5input(enter the denominator coecients o the
lter);
k5poly2rc(b);knew5fiplr(k);
s5all(abs(knew)1);
i(s55 1)
disp(Stable system);
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
11/96
MATLAB Programs 825
else
disp(Non-stable system);
endAs an example,
enter the denominator coecients o the lter [1 21 .5]
Stable system
16.6 SAMPLING THEOREM
The sampling theorem can be understood well with the ollowing example.
Example 16.1 Frequency analysis of the amplitude modulated discrete-time
signal
x(n)5cos 2 pf1n1 cos 2pf
2n
where f1
1
128= andf
2
5
128= modulates the amplitude-modulated signal is
xc(n)5cos 2pf
cn
wherefc550/128. The resulting amplitude-modulated signal is
xam
(n)5x(n) cos 2pfcn
Using MATLAB program,
(a) sketch the signals x(n),xc(n) andx
am(n), 0 #n# 255
(b) compute and sketch the 128-point DFT of the signalxam
(n), 0 #n# 127
(c) compute and sketch the 128-point DFT of the signal xam
(n),0 #n# 99
Solution
% Program
Solution or Section (a)
clc;close all;clear all;
151/128;255/128;n50:255;c550/128;
x5cos(2*pi*1*n)1cos(2*pi*2*n);
xa5cos(2*pi*c*n);
xamp5x.*xa;
subplot(2,2,1);plot(n,x);title(x(n));
xlabel(n --.);ylabel(amplitude);
subplot(2,2,2);plot(n,xc);title(xa(n));
xlabel(n --.);ylabel(amplitude);
subplot(2,2,3);plot(n,xamp);
xlabel(n --.);ylabel(amplitude);
%128 point DFT computation2solution or Section (b)
n50:127;gure;n15128;151/128;255/128;c550/128;
x5cos(2*pi*1*n)1cos(2*pi*2*n);
xc5cos(2*pi*c*n);
xa5cos(2*pi*c*n);(Contd.)
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
12/96
826 Digital Signal Processing
2
1
0
1
2
Amplitude
0 100 200 300
(iii) n
Fig. 16.5(a) (iii) Amplitude Modulated Signal
Fig. 16.5(a) (ii) Carrier Signal and
1
0.5
0
0.5
1
Am
plitude
0 100 200 300
(ii) n
02
1
0
1
2
100
Amplitude
200
(i)
300n
Fig. 16.5(a) (i) Modulating Signal x (n)
(Contd.)
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
13/96
MATLAB Programs 827
20
Amplitude
40 60 80 100 120
n
1400
10
5
0
5
10
15
20
25
Fig. 16.5(b) 128-point DFT of the Signal xam
(n), 0# n #127
20 40 60 80 100 120 140
n
0
5
0
5
10
15
20
25
30
35
Amplitude
Fig. 16.5(c) 128-point DFT of the Signal xam
(n), 0# n #99
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
14/96
828 Digital Signal Processing
xamp5x.*xa;xam5t(xamp,n1);
stem(n,xam);title(xamp(n));xlabel(n --.);
ylabel(amplitude);%128 point DFT computation2solution or Section (c)
n50:99;gure;n250:n121;
151/128;255/128;c550/128;
x5cos(2*pi*1*n)1cos(2*pi*2*n);
xc5cos(2*pi*c*n);
xa5cos(2*pi*c*n);
xamp5x.*xa;
or i51:100,
xamp1(i)5xamp(i);
endxam5t(xamp1,n1);
s t e m ( n 2 , x a m ) ; t i t l e ( x a m p ( n ) ) ; x l a b e l ( n
--.);ylabel(amplitude);
(a)Modulated signal x(n), carrier signal xa(n) and amplitude modulated signal
xam
(n) are shown in Fig. 16.5(a). Fig. 16.5 (b) shows the 128-point DFT o the
signal xam
(n) or 0 #n# 127 and Fig. 16.5 (c) shows the 128-point DFT o the
signalxam
(n), 0 #n# 99.
16.7 FAST FOURIER TRANSFORM
Algorithm
1. Get the signalx(n)o lengthNin matrix orm
2. Get theNvalue
3. The transormed signal is denoted as
x k x n e k Nj
Nnk
n
N
( ) ( ) for =
=
2
0
1
0 1p
\\\% Program or computing discrete Fourier transorm
clc;close all;clear all;x5input(enter the sequence);
n5input(enter the length o t);
X(k)5t(x,n);
stem(y);ylabel(Imaginary axis --.);
xlabel(Real axis --.);
X(k)
As an example,
enter the sequence [0 1 2 3 4 5 6 7]
enter the length o t 8
X(k)5
Columns 1 through 4
28.0000 24.000019.6569i 24.0000 14.0000i 24.0000
1 1.6569i
Columns 5 through 8
24.0000 24.0000 21.6569i 24.0000 24.0000i 24.0000
29.6569i
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
15/96
MATLAB Programs 829
The eight-point decimation-in-time ast Fourier transorm o the sequencex(n)is
computed usingMATLAB program and the resultant output is plotted in Fig. 16.6.
05
10
8
6
4
2
0
2
4
6
8
10
5 10 15 20 25 30
Real axis
Imaginaryaxis
Fig. 16.6 Fast Fourier Transform
16.8 BUTTERWORTH ANALOG FILTERS
16.8.1 Low-pass Filter
Algorithm
1. Get the passband and stopband ripples2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.46
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Butterworth analog low pass flter
clc;
close all;clear all;
ormat longrp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
wp5input(enter the passband req);
ws5input(enter the stopband req);
s5input(enter the sampling req);
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
16/96
830 Digital Signal Processing
w152*wp/s;w252*ws/s;
[n,wn]5buttord(w1,w2,rp,rs,s);
[z,p,k]5butter(n,wn);[b,a]5zp2t(z,p,k);
[b,a]5butter(n,wn,s);
w50:.01:pi;
[h,om]5reqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple 0.15
enter the stopband ripple 60
enter the passband req 1500
enter the stopband req 3000
enter the stopband req 7000
The amplitude and phase responses o the Butterworth low-pass analog flter are
shown in Fig. 16.7.
Fig. 16.7 Butterworth Low-pass Analog Filter(a) Amplitude Response and (b) Phase Response
0.1
250
200
150
100
50
50
GainindB
0
0.2 0.3 0.4
(a)
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
0.14
2
2
4
0
0.2 0.3 0.4
(b)
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
Ph
aseinradians
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
17/96
MATLAB Programs 831
16.8.2 High-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.46
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Butterworth analog highpass flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
wp5input(enter the passband req);
ws5input(enter the stopband req);
s5input(enter the sampling req);
w152*wp/s;w252*ws/s;[n,wn]5buttord(w1,w2,rp,rs,s);
[b,a]5butter(n,wn,high,s);
w50:.01:pi;
[h,om]5reqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple 0.2
enter the stopband ripple 40
enter the passband req 2000
enter the stopband req 3500
enter the sampling req 8000
The amplitude and phase responses o Butterworth high-pass analog flter are
shown in Fig. 16.8.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
18/96
832 Digital Signal Processing
16.8.3 Bandpass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.465. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Butterworth analog Bandpass flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
Fig. 16.8 Butterworth High-pass Analog Filter(a) Amplitude Response and(b) Phase Response
Phaseinradians
(b)
0.14
4
2
2
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
GainindB
(a)
0.1400
300
200
100
0
100
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
19/96
MATLAB Programs 833
[n]5buttord(w1,w2,rp,rs);
wn5[w1 w2];
[b,a]5butter(n,wn,bandpass,s);w50:.01:pi;
[h,om]5reqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.36
enter the stopband ripple... 36
enter the passband req... 1500
enter the stopband req... 2000
enter the sampling req... 6000
The amplitude and phase responses o Butterworth bandpass analog flter are
shown in Fig. 16.9.
Fig. 16.9 Butterworth Bandpass Analog Filter(a) Amplitude Response and(b) Phase Response
GainindB
Phaseinradians
(a)
(b)
0.1
0.1
1000
4
4
2
2
0
800
600
200
400
0
200
0.2
0.2
0.3
0.3
0.4
0.4
Normalised frequency
Normalised frequency
0.5
0.5
0.6
0.6
0.7
0.7
0.8
0.8
0.9
0.9
1
1
0
0
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
20/96
834 Digital Signal Processing
16.8.4 Bandstop Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.46
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Butterworth analog Bandstop flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n]5buttord(w1,w2,rp,rs,s);
wn5[w1 w2];
[b,a]5butter(n,wn,stop,s);
w50:.01:pi;
[h,om]5reqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.28
enter the stopband ripple... 28
enter the passband req... 1000
enter the stopband req... 1400
enter the sampling req... 5000
The amplitude and phase responses o Butterworth bandstop analog flter are
shown in Fig. 16.10.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
21/96
MATLAB Programs 835
16.9 CHEBYSHEV TYPE-1 ANALOG FILTERS
16.9.1 Low-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.57
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-1 low-pass flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
GainindB
(a)
0.1
150
50
100
200
0
50
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
Fig. 16.10 Butterworth Bandstop Analog Filter(a) Amplitude Response and(b) Phase Response
Phaseinradians
(b)
0.14
4
2
2
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
22/96
836 Digital Signal Processing
w152*wp/s;w252*ws/s;
[n,wn]5cheb1ord(w1,w2,rp,rs,s);
[b,a]5cheby1(n,rp,wn,s);w50:.01:pi;
[h,om]5reqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.23
enter the stopband ripple... 47
enter the passband req... 1300
enter the stopband req... 1550
enter the sampling req... 7800
The amplitude and phase responses o Chebyshev type - 1 low-pass analog flter
are shown in Fig. 16.11.
GainindB
Phaseinradians
(a)
(b)
0.1
0.14
4
2
2
0
80
40
20
60
100
0
0.2
0.2
0.3
0.3
0.4
0.4
Normalised frequency
Normalised frequency
0.5
0.5
0.6
0.6
0.7
0.7
0.8
0.8
0.9
0.9
1
1
0
0
Fig. 16.11 Chebyshev Type-I Low-pass Analog Filter(a)Amplitude Responseand (b) Phase Response
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
23/96
MATLAB Programs 837
16.9.2 High-pass Filter
Algorithm
1. Get the passband and stopband ripples2. Get the passband and stopband edge requencies3. Get the sampling requency4. Calculate the order o the flter using Eq. 8.575. Find the flter coefcients6. Draw the magnitude and phase responses.
%Program or the design o Chebyshev Type-1 high-pass flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n,wn]5cheb1ord(w1,w2,rp,rs,s);
[b,a]5cheby1(n,rp,wn,high,s);
w50:.01:pi;
[h,om]5reqs(b,a,w);
m520*log10(abs(h));
an5angle(h);subplot(2,1,1);plot(om/pi,m);
Fig. 16.12 Chebyshev Type - 1 High-pass Analog Filter(a) Amplitude Responseand (b) Phase Response
GainindB
(a)
0.1
100
50
150
200
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
Ph
aseinradians
(b)
0.14
4
2
2
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
24/96
838 Digital Signal Processing
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,enter the passband ripple... 0.29
enter the stopband ripple... 29
enter the passband req... 900
enter the stopband req... 1300
enter the sampling req... 7500
The amplitude and phase responses o Chebyshev type - 1 high-pass analog flter
are shown in Fig. 16.12.
16.9.3 Bandpass Filter
Algorithm
1. Get the passband and stopband ripples2. Get the passband and stopband edge requencies3. Get the sampling requency4. Calculate the order o the flter using Eq. 8.575. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-1 Bandpass flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n]5cheb1ord(w1,w2,rp,rs,s);
wn5[w1 w2];[b,a]5cheby1(n,rp,wn,bandpass,s);
w50:.01:pi;
[h,om]5reqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.3
enter the stopband ripple... 40
enter the passband req... 1400
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
25/96
MATLAB Programs 839
enter the stopband req... 2000
enter the sampling req... 5000
The amplitude and phase responses o Chebyshev type - 1 bandpass analog flter
are shown in Fig. 16.13.
16.9.4 Bandstop Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requency
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.57
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-1 Bandstop flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
Fig. 16.13 Chebyshev Type-1 Bandpass Analog Filter(a) Amplitude Response and (b) Phase Response
Ga
in
in
dB
a
0.1
200
100
300
400
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
Phase
in
radians
(b)
0.13
3
2
1
1
2
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
26/96
840 Digital Signal Processing
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n]5cheb1ord(w1,w2,rp,rs,s);wn5[w1 w2];
[b,a]5cheby1(n,rp,wn,stop,s);
w50:.01:pi;
[h,om]5reqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.15
enter the stopband ripple... 30
enter the passband req... 2000
enter the stopband req... 2400
enter the sampling req... 7000
The amplitude and phase responses o Chebyshev type - 1 bandstop analog flter
are shown in Fig. 16.14.
Fig. 16.14 Chebyshev Type - 1 Bandstop Analog Filter(a) Amplitude Response and (b) Phase Response
GainindB
(a)
0.1
150
50
100
200
250
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
Pha
seinradians
(b)
0.14
4
2
2
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
27/96
MATLAB Programs 841
16.10 CHEBYSHEV TYPE-2 ANALOG FILTERS
16.10.1 Low-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.67
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-2 low pass analog flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n,wn]5cheb2ord(w1,w2,rp,rs,s);
[b,a]5cheby2(n,rs,wn,s);
w50:.01:pi;
[h,om]5reqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.4
enter the stopband ripple... 50
enter the passband req... 2000
enter the stopband req... 2400
enter the sampling req... 10000
The amplitude and phase responses o Chebyshev type - 2 low-pass analog flter
are shown in Fig. 16.15.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
28/96
842 Digital Signal Processing
Fig. 16.15 Chebyshev Type - 2 Low-pass Analog Filter(a) Amplitude Responseand (b) Phase Response
GainindB
Phaseinradians
(a)
(b)
0.1
0.14
4
2
2
0
60
20
40
80
100
0
0.2
0.2
0.3
0.3
0.4
0.4
Normalised frequency
Normalised frequency
0.5
0.5
0.6
0.6
0.7
0.7
0.8
0.8
0.9
0.9
1
1
0
0
16.10.2 High-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.67
5. Find the flter coefcients6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-2 High pass analog flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n,wn]5cheb2ord(w1,w2,rp,rs,s);
[b,a]5cheby2(n,rs,wn,high,s);
w50:.01:pi;
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
29/96
MATLAB Programs 843
[h,om]5reqs(b,a,w);
m520*log10(abs(h));
an5angle(h);subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.34
enter the stopband ripple... 34
enter the passband req... 1400
enter the stopband req... 1600enter the sampling req... 10000
The amplitude and phase responses o Chebyshev type - 2 high-pass analog flter
are shown in Fig. 16.16.
Gain
indB
Phaseinradians
(a)
(b)
0.1
0.14
4
2
2
0
60
20
40
80
0
0.2
0.2
0.3
0.3
0.4
0.4
Normalised frequency
Normalised frequency
0.5
0.5
0.6
0.6
0.7
0.7
0.8
0.8
0.9
0.9
1
1
0
0
Fig. 16.16 Chebyshev Type - 2 High-pass Analog Filter(a) Amplitude Response and (b) Phase Response
16.10.3 Bandpass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
30/96
844 Digital Signal Processing
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.67
5. Find the flter coefcients6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-2 Bandpass analog flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n]5cheb2ord(w1,w2,rp,rs,s);
wn5[w1 w2];
[b,a]5cheby2(n,rs,wn,bandpass,s);
w50:.01:pi;
[h,om]5reqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.37
enter the stopband ripple... 37
enter the passband req... 3000
enter the stopband req... 4000
enter the sampling req... 9000
The amplitude and phase responses o Chebyshev type - 2 bandpass analog flter
are shown in Fig. 16.17.
Fig. 16.17 (Contd.)
GainindB
(a)
0.1
80
60
20
0
40
100
20
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
31/96
MATLAB Programs 845
16.10.4 Bandstop Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.67
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-2 Bandstop analog flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n]5cheb2ord(w1,w2,rp,rs,s);
wn5[w1 w2];
[b,a]5cheby2(n,rs,wn,stop,s);
w50:.01:pi;
[h,om]5reqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
Fig. 16.17 Chebyshev Type - 2 Bandstop Analog Filter(a) Amplitude Responseand (b) Phase Response
Phaseinradians
(b)
0.14
4
2
2
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
32/96
846 Digital Signal Processing
As an example,
enter the passband ripple... 0.25
enter the stopband ripple... 30enter the passband req... 1300
enter the stopband req... 2000
enter the sampling req... 8000
The amplitude and phase responses o Chebyshev type - 2 bandstop analog flter
are shown in Fig. 16.18.
Fig. 16.18 Chebyshev Type - 2 Bandstop Analog Filter(a) Amplitude Response and (b) Phase Response
GainindB
Phaseinradians
(a)
(b)
0.1
0.14
4
2
2
0
60
40
0
20
20
80
40
0.2
0.2
0.3
0.3
0.4
0.4
Normalised frequency
Normalised frequency
0.5
0.5
0.6
0.6
0.7
0.7
0.8
0.8
0.9
0.9
1
1
0
0
16.11 BUTTERWORTH DIGITAL IIR FILTERS
16.11.1 Low-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.46
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
33/96
MATLAB Programs 847
% Program or the design o Butterworth low pass digital flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
wp5input(enter the passband req);
ws5input(enter the stopband req);
s5input(enter the sampling req);
w152*wp/s;w252*ws/s;
[n,wn]5buttord(w1,w2,rp,rs);
[b,a]5butter(n,wn);w50:.01:pi;
[h,om]5reqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple 0.5
enter the stopband ripple 50
enter the passband req 1200
enter the stopband req 2400
enter the sampling req 10000
The amplitude and phase responses o Butterworth low-pass digital flter are
shown in Fig. 16.19.
GainindB
(a)
0.1
300
200
0
100
400
100
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
Fig. 16.19 (Contd.)
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
34/96
848 Digital Signal Processing
16.11.2 High-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.46
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Butterworth highpass digital flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
wp5input(enter the passband req);
ws5input(enter the stopband req);
s5input(enter the sampling req);
w152*wp/s;w252*ws/s;
[n,wn]5buttord(w1,w2,rp,rs);
[b,a]5butter(n,wn,high);
w50:.01:pi;
[h,om]5reqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);ylabel(Phase in radians --.);
As an example,
enter the passband ripple 0.5
enter the stopband ripple 50
enter the passband req 1200
Fig. 16.19 Butterworth Low-pass Digital Filter(a) Amplitude Response and(b) Phase Response
Phaseinradians
(b)
0.14
4
2
2
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
35/96
MATLAB Programs 849
enter the stopband req 2400
enter the sampling req 10000
The amplitude and phase responses o Butterworth high-pass digital flter are
shown in Fig. 16.20.
16.11.3 Band-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.46
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Butterworth Bandpass digital flter
clc;close all;clear all;
ormat long
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
wp5input(enter the passband req);
Fig. 16.20 Butterworth High-pass Digital Filter(a) Amplitude Response and (b) Phase Response
GainindB
(a)
0.1
250
200
150
0
100
50
300
50
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
Phaseinra
dians
(b)
0.14
4
2
2
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
36/96
850 Digital Signal Processing
ws5input(enter the stopband req);
s5input(enter the sampling req);
w152*wp/s;w252*ws/s;[n]5buttord(w1,w2,rp,rs);
wn5[w1 w2];
[b,a]5butter(n,wn,bandpass);
w50:.01:pi;
[h,om]5reqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple 0.3
enter the stopband ripple 40
enter the passband req 1500
enter the stopband req 2000
enter the sampling req 9000
The amplitude and phase responses o Butterworth band-pass digital flter areshown in Fig. 16.21.
Fig. 16.21 Butterworth Bandstop Digital Filter(a) Amplitude Response and(b) Phase Response
GainindB
(a)
(b)
Pha
seinradians
0.1
0.1
0
200
100
400
500
600
700
4
2
0
2
4
300
0.2
0.2
0.3
0.3
0.4
0.4
Normalised frequency
Normalised frequency
0.5
0.5
0.6
0.6
0.7
0.7
0.8
0.8
0.9
0.9
1
1
0
0
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
37/96
MATLAB Programs 851
16.11.4 Bandstop Filter
Algorithm1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.46
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Butterworth Band stop digital flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
wp5input(enter the passband req);
ws5input(enter the stopband req);
s5input(enter the sampling req);
w152*wp/s;w252*ws/s;
[n]5buttord(w1,w2,rp,rs);wn5[w1 w2];
[b,a]5butter(n,wn,stop);
w50:.01:pi;
[h,om]5reqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple 0.4
enter the stopband ripple 46
enter the passband req 1100
enter the stopband req 2200
enter the sampling req 6000
The amplitude and phase responses o the Butterworth bandstop digital flter are
shown in Fig. 16.22.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
38/96
852 Digital Signal Processing
Fig. 16.22 Butterworth Bandstop Digital Filter(a) Amplitude Response and (b) Phase Response
Phaseinradians
(b)
0.14
4
2
2
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
GainindB
(a)
0.1
100
0
200
100
400
300
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
16.12 CHEBYSHEV TYPE-1 DIGITAL FILTERS
16.12.1 Low-pass Filter
Algorithm
1. Get the passband and stopband ripples2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.57
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-1 lowpass digital flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
39/96
MATLAB Programs 853
w152*wp/s;w252*ws/s;
[n,wn]5cheb1ord(w1,w2,rp,rs);
[b,a]5cheby1(n,rp,wn);w50:.01:pi;
[h,om]5reqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);As an example,
enter the passband ripple... 0.2
enter the stopband ripple... 45
enter the passband req... 1300
enter the stopband req... 1500
enter the sampling req... 10000
The amplitude and phase responses o Chebyshev type - 1 low-pass digital flter
are shown in Fig. 16.23.
Fig. 16.23 Chebyshev Type - 1 Low-pass Digital Filter(a) Amplitude Responseand (b) Phase Response
GainindB
Phaseinradians
(a)
(b)
0.1
0.14
4
2
2
0
0
200
100
500
400
300
0.2
0.2
0.3
0.3
0.4
0.4
Normalised frequency
Normalised frequency
0.5
0.5
0.6
0.6
0.7
0.7
0.8
0.8
0.9
0.9
1
1
0
0
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
40/96
854 Digital Signal Processing
16.12.2 High-pass Filter
Algorithm1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.57
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-1 highpass digital
ilterclc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n,wn]5cheb1ord(w1,w2,rp,rs);
[b,a]5cheby1(n,rp,wn,high);
w50:.01/pi:pi;
[h,om]5reqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised requency
--.);subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.3
enter the stopband ripple... 60
enter the passband req... 1500
enter the stopband req... 2000
enter the sampling req... 9000
The amplitude and phase responses o Chebyshev type - 1 high-pass digital flter
are shown in Fig. 16.24.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
41/96
MATLAB Programs 855
16.12.3 Bandpass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.575. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-1 Bandpass digital flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
Fig. 16.24 Chebyshev Type - 1 High-pass Digital Filter(a) Amplitude Response and (b) Phase Response
Phaseinradians
(b)
0.14
4
2
2
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
GainindB
(a)
0.1
0
250
200
150
100
50
350
300
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
42/96
856 Digital Signal Processing
[n]5cheb1ord(w1,w2,rp,rs);
wn5[w1 w2];
[b,a]5cheby1(n,rp,wn,bandpass);w50:.01:pi;
[h,om]5reqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.4
enter the stopband ripple... 35
enter the passband req... 2000
enter the stopband req... 2500
enter the sampling req... 10000
The amplitude and phase responses o Chebyshev type - 1 bandpass digital flter
are shown in Fig. 16.25.
GainindB
Phaseinradians
(a)
(b)
0.1
0.14
4
2
2
0
0
300
200
100
500
400
0.2
0.2
0.3
0.3
0.4
0.4
Normalised frequency
Normalised frequency
0.5
0.5
0.6
0.6
0.7
0.7
0.8
0.8
0.9
0.9
1
1
0
0
Fig. 16.25 Chebyshev Type - 1 Bandpass Digital Filter(a) AmplitudeResponse and (b) Phase Response
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
43/96
MATLAB Programs 857
16.12.4 Bandstop Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.57
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-1 Bandstop digital flter
clc;close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n]5cheb1ord(w1,w2,rp,rs);wn5[w1 w2];
[b,a]5cheby1(n,rp,wn,stop);
w50:.1/pi:pi;
[h,om]5reqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.25
enter the stopband ripple... 40
enter the passband req... 2500
enter the stopband req... 2750
enter the sampling req... 7000
The amplitude and phase responses o Chebyshev type - 1 bandstop digital flter
are shown in Fig. 16.26.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
44/96
858 Digital Signal Processing
Fig. 16.26 Chebyshev Type - 1 Bandstop Digital Filter(a) Amplitude Response and (b) Phase Response
GainindB
(a)
0.1
0
200
150
100
50
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
Phaseinradians
(b)
0.13
2
1
1
2
3
4
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
16.13 CHEBYSHEV TYPE-2 DIGITAL FILTERS
16.13.1 Low-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency4. Calculate the order o the flter using Eq. 8.67
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-2 lowpass digital flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n,wn]5cheb2ord(w1,w2,rp,rs);
[b,a]5cheby2(n,rs,wn);
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
45/96
MATLAB Programs 859
w50:.01:pi;
[h,om]5reqz(b,a,w);
m520*log10(abs(h));an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.35
enter the stopband ripple... 35enter the passband req... 1500
enter the stopband req... 2000
enter the sampling req... 8000
The amplitude and phase responses o Chebyshev type - 2 low-pass digital flter
are shown in Fig. 16.27.
Fig. 16.27 Chebyshev Type - 2 Low-pass Digital Filter(a) Amplitude Response
and (b) Phase Response
Gainind
B
(a)
0.1100
80
60
40
20
0
20
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
Phaseinradians
(b)
0.14
2
2
4
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
16.13.2 High-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
46/96
860 Digital Signal Processing
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.67
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-2 high pass digital flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n,wn]5cheb2ord(w1,w2,rp,rs);
[b,a]5cheby2(n,rs,wn,high);
w50:.01/pi:pi;
[h,om]5reqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.25
enter the stopband ripple... 40
enter the passband req... 1400
enter the stopband req... 1800
enter the sampling req... 7000
The amplitude and phase responses o Chebyshev type - 2 high-pass digital flter
are shown in Fig. 16.28.
GainindB
(a)
0.1120
100
80
60
40
20
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
Fig. 16.28 (Contd.)
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
47/96
MATLAB Programs 861
16.13.3 Bandpass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requency
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.67
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o Chebyshev Type-2 Bandpass digital flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);w152*wp/s;w252*ws/s;
[n]5cheb2ord(w1,w2,rp,rs);
wn5[w1 w2];
[b,a]5cheby2(n,rs,wn,bandpass);
w50:.01/pi:pi;
[h,om]5reqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalisedrequency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);
Phaseinradians
(b)
0.14
2
2
4
0
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
Fig. 16.28 Chebyshev Type - 2 High-pass Digital Filter(a) Amplitude Response
and (b) Phase Response
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
48/96
862 Digital Signal Processing
As an example,
enter the passband ripple... 0.4
enter the stopband ripple... 40
enter the passband req... 1400
enter the stopband req... 2000
enter the sampling req... 9000
The amplitude and phase responses o Chebyshev type - 2 bandpass digital flter
are shown in Fig. 16.29.
Fig. 16.29 Chebyshev Type - 2 Bandpass Digital Filter(a) Amplitude Responseand (b) Phase Response
GainindB
Phaseinradians
(a)
(b)
0.1
0.14
2
4
0
2
400
300
200
100
0
100
0.2
0.2
0.3
0.3
0.4
0.4
Normalised frequency
Normalised frequency
0.5
0.5
0.6
0.6
0.7
0.7
0.8
0.8
0.9
0.9
1
1
0
0
16.13.4 Bandstop Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter using Eq. 8.675. Find the flter coefcients
6. Draw the magnitude and phase responses.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
49/96
MATLAB Programs 863
% Program or the design o Chebyshev Type-2 Bandstop digital flter
clc;
close all;clear all;
ormat long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband req...);
ws5input(enter the stopband req...);
s5input(enter the sampling req...);
w152*wp/s;w252*ws/s;
[n]5cheb2ord(w1,w2,rp,rs);
wn5[w1 w2];
[b,a]5cheby2(n,rs,wn,stop);w50:.1/pi:pi;
[h,om]5reqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
requency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised requency --.);
ylabel(Phase in radians --.);As an example,
enter the passband ripple... 0.3
enter the stopband ripple... 46
enter the passband req... 1400
enter the stopband req... 2000
enter the sampling req... 8000
The amplitude and phase responses o Chebyshev type - 2 bandstop digital flter
are shown in Fig. 16.30.
GainindB
(a)
0.1
80
60
40
20
0
20
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
Fig. 16.30 (Contd.)
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
50/96
864 Digital Signal Processing
16.14FIR FILTER DESIGN USING WINDOWTECHNIQUES
In the design o FIR flters using any window technique, the order can be calculated
using the ormula given by
Np s
f f Fs p s
=
20 13
14 6
log( )
. ( ) /
d d
where dp is the passband ripple, ds is the stopband ripple,fp
is the passband requency,
fs
is the stopband requency andFs
is the sampling requency.
16.14.1 Rectangular Window
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter
5. Find the window coefcients using Eq. 7.37
6. Draw the magnitude and phase responses.
% Program or the design o FIR Low pass, High pass, Band passand Bandstop flters using rectangular window
clc;clear all;close all;
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
p5input(enter the passband req);s5input(enter the stopband req);
5input(enter the sampling req);
wp52*p/;ws52*s/;
num5220*log10(sqrt(rp*rs))213;
Fig. 16.30 Chebyshev Type - 2 Bandstop Digital Filter(a) Amplitude Response
and (b) Phase Response
Phaseinradians
(b)
0.1-4
-2
-1
-3
3
0
1
2
0.2 0.3 0.4
Normalised frequency
0.5 0.6 0.7 0.8 0.9 10
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
51/96
MATLAB Programs 865
dem514.6*(s2p)/;
n5ceil(num/dem);
n15n11;i (rem(n,2)50)
n15n;
n5n21;
end
y5boxcar(n1);
% low-passfilter
b5r1(n,wp,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((a) Normalised requency --.);
% high-passfilter
b5r1(n,wp,high,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((b) Normalised requency --.);
% bandpassfilter
wn5[wp ws];
b5r1(n,wn,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);ylabel(Gain in dB -->);
xlabel((c) Normalised requency -->);
% bandstopfilter
b5r1(n,wn,stop,y);[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);ylabel(Gain in dB -->);
xlabel((d) Normalised requency -->);
As an example,
enter the passband ripple 0.05
enter the stopband ripple 0.04
enter the passband req 1500
enter the stopband req 2000
enter the sampling req 9000
The gain responses o low-pass, high-pass, bandpass and bandstop flters using
rectangular window are shown in Fig. 16.31.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
52/96
866 Digital Signal Processing
16.14.2 Bartlett Window
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o FIR Low pass, High pass, Band passand Bandstop flters using Bartlett window
clc;clear all;close all;
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
p5input(enter the passband req);
s5input(enter the stopband req);
5input(enter the sampling req);
Fig. 16.31 Filters Using Rectangular Window (a) Low-pass (b) High-pass(c) Bandpass and (d) Bandstop
0.2
0.2
0.2
0.2
80
8020
80
60
6015
60
40
4010
40
20
205
20
0
0 0
0
20
20 5
20
0.4
0.4
0.4
0.4
(a)
(c)
(b)
(d)
Normalised frequency
Normalised frequency
Normalised frequency
Normalised frequency
0.6
0.6
0.6
0.6
0.8
0.8
0.8
0.8
1
1
1
1
0
0
0
0
Ga
in
in
dB
Ga
in
in
dB
Ga
in
in
dB
Ga
in
in
dB
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
53/96
MATLAB Programs 867
wp52*p/;ws52*s/;
num5220*log10(sqrt(rp*rs))213;
dem514.6*(s2p)/;n5ceil(num/dem);
n15n11;
i (rem(n,2)50)
n15n;
n5n21;
end
y5bartlett(n1);
% low-passfilter
b5r1(n,wp,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((a) Normalised requency --.);
% high-passfilter
b5r1(n,wp,high,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((b) Normalised requency --.);
% bandpassfilter
wn5[wp ws];
b5r1(n,wn,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((c) Normalised requency --.);
% bandstopfilter
b5r1(n,wn,stop,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((d) Normalised requency --.);
As an example,
enter the passband ripple 0.04
enter the stopband ripple 0.02
enter the passband req 1500
enter the stopband req 2000enter the sampling req 8000
The gain responses o low-pass, high-pass, bandpass and bandstop flters using
Bartlett window are shown in Fig. 16.32.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
54/96
868 Digital Signal Processing
16.14.3 Blackman window
Algorithm
1. Get the passband and stopband ripples2. Get the passband and stopband edge requencies
3. Get the sampling requency
4. Calculate the order o the flter
5. Find the window coefcients using Eq. 7.45
6. Draw the magnitude and phase responses.
% Program or the design o FIR Low pass, High pass, Band passand Band stop digital flters using Blackman window
clc;clear all;close all;
rp5input(enter the passband ripple);rs5input(enter the stopband ripple);
p5input(enter the passband req);
s5input(enter the stopband req);
5input(enter the sampling req);
Fig. 16.32 Filters using Bartlett Window (a) Low-pass (b) High-pass(c) Bandpass and (d) Bandstop
35
40 8
30
306
30
25
25
20
204
20
15
15
10
10
2
0
10
5
5
0
20
5
0
0.2
0.2
0.2
0.2
0.4
0.4
0.4
0.4
(a)
(c)
(b)
(d)
Normalised frequency
Normalised frequency
Normalised frequency
Normalised frequency
0.6
0.6
0.6
0.6
0.8
0.8
0.8
0.8
1
1
1
1
0
0
0
0
GainindB
GainindB
GainindB
GainindB
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
55/96
MATLAB Programs 869
wp52*p/;ws52*s/;
num5220*log10(sqrt(rp*rs))213;
dem514.6*(s2p)/;n5ceil(num/dem);
n15n11;
i (rem(n,2)50)
n15n;
n5n21;
end
y5blackman(n1);
% low-passfilter
b5r1(n,wp,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((a) Normalised requency --.);
% high-passfilter
b5r1(n,wp,high,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((b) Normalised requency --.);
% bandpassfilter
wn5[wp ws];
b5r1(n,wn,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((c) Normalised requency --.);
% bandstopfilter
b5r1(n,wn,stop,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);;ylabel(Gain in dB --.);
xlabel((d) Normalised requency --.);
As an example,
enter the passband ripple 0.03
enter the stopband ripple 0.01
enter the passband req 2000
enter the stopband req 2500enter the sampling req 7000
The gain responses o low-pass, high-pass, bandpass and bandstop flters using
Blackman window are shown in Fig. 16.33.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
56/96
870 Digital Signal Processing
16.14.4 Chebyshev Window
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies3. Get the sampling requency
4. Calculate the order o the flter
5. Find the flter coefcients
6. Draw the magnitude and phase responses.
% Program or the design o FIR Lowpass, High pass, Band passand Bandstop flters using Chebyshev window
clc;clear all;close all;
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
p5input(enter the passband req);
s5input(enter the stopband req);
5input(enter the sampling req);
Fig. 16.33 Filters using Blackman Window (a) Low-pass (b) High-pass(c) Bandpass and (d) Bandstop
120
120 8
150
100100
100 6
80
60
804
40
20
60
40
20
2
0
50
0
0
20
20
50
0.2
0.2
0.2
0.2
0.4
0.4
0.4
0.4
(a)
(c)
(b)
(d)
Normalised frequency
Normalised frequency
Normalised frequency
Normalised frequency
0.6
0.6
0.6
0.6
0.8
0.8
0.8
0.8
1
1
1
1
0
0
0
0
GainindB
GainindB
GainindB
GainindB
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
57/96
MATLAB Programs 871
r5input(enter the ripple value(in dBs));
wp52*p/;ws52*s/;
num5220*log10(sqrt(rp*rs))213;dem514.6*(s2p)/;
n5ceil(num/dem);
i(rem(n,2)50)
n5n11;
end
y5chebwin(n,r);
% low-passfilter
b5r1(n-1,wp,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((a) Normalised requency --.);
% high-passfilter
b5r1(n21,wp,high,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((b) Normalised requency --.);
% band-passfilter
wn5[wp ws];
b5r1(n21,wn,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((c) Normalised requency --.);
% band-stopfilter
b5r1(n21,wn,stop,y);[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((d) Normalised requency --.);
As an example,
enter the passband ripple 0.03
enter the stopband ripple 0.02
enter the passband req 1800
enter the stopband req 2400
enter the sampling req 10000enter the ripple value(in dBs)40
The gain responses o low-pass, high-pass, bandpass and bandstop flters using
Chebyshev window are shown in Fig. 16.34.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
58/96
872 Digital Signal Processing
16.14.5 Hamming Window
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies3. Get the sampling requency
4. Calculate the order o the flter
5. Find the window coefcients using Eq. 7.40
6. Draw the magnitude and phase responses.
% Program or the design o FIR Low pass, High pass, Band passand Bandstop flters using Hamming window
clc;clear all;close all;
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);p5input(enter the passband req);
s5input(enter the stopband req);
5input(enter the sampling req);
Fig. 16.34 Filters using Chebyshev Window (a) Low-pass (b) High-pass(c) Bandpass and (d) Bandstop
100
120 12
100
40
20
60
8080
10010
60
40
808
20
60
40
20
6
4
2
0
0
20
0
20
20
0.2
0.2
0.2
0.2
0.4
0.4
0.4
0.4
(a)
(c)
(b)
(d)
Normalised frequency
Normalised frequency
Normalised frequency
Normalised frequency
0.6
0.6
0.6
0.6
0.8
0.8
0.8
0.8
1
1
1
1
0
0
0
0
GainindB
GainindB
GainindB
GainindB
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
59/96
MATLAB Programs 873
wp52*p/;ws52*s/;
num5220*log10(sqrt(rp*rs))213;
dem514.6*(s2p)/;n5ceil(num/dem);
n15n11;
i (rem(n,2)50)
n15n;
n5n21;
end
y5hamming(n1);
% low-passfilter
b5r1(n,wp,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((a) Normalised requency --.);
% high-passfilter
b5r1(n,wp,high,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((b) Normalised requency --.);
% bandpassfilter
wn5[wp ws];
b5r1(n,wn,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((c) Normalised requency --.);
% bandstopfilter
b5r1(n,wn,stop,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((d) Normalised requency --.);
As an example,
enter the passband ripple 0.02
enter the stopband ripple 0.01
enter the passband req 1200
enter the stopband req 1700enter the sampling req 9000
The gain responses o low-pass, high-pass, bandpass and bandstop flters using
Hamming window are shown in Fig. 16.35.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
60/96
874 Digital Signal Processing
16.14.6 Hanning Window
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies3. Get the sampling requency
4. Calculate the order o the flter
5. Find the window coefcients using Eq. 7.44
6. Draw the magnitude and phase responses.
% Program or the design o FIR Low pass, High pass, Band passand Band stop flters using Hanning window
clc;clear all;close all;
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
p5input(enter the passband req);
s5input(enter the stopband req);
5input(enter the sampling req);
Fig. 16.35 Filters using Hamming Window (a) Low-pass (b) High-pass(c) Bandpass and (d) Bandstop
120
120 15
100
40
20
60
80100
10010
5
80
60
80
40
20
60
40
200
0
20
0
20
20
0.2
0.2
0.2
0.2
0.4
0.4
0.4
0.4
(a)
(c)
(b)
(d)
Normalised frequency
Normalised frequency
Normalised frequency
Normalised frequency
0.6
0.6
0.6
0.6
0.8
0.8
0.8
0.8
1
1
1
1
0
0
0
0
GainindB
GainindB
GainindB
GainindB
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
61/96
MATLAB Programs 875
wp52*p/;ws52*s/;
num5220*log10(sqrt(rp*rs))213;
dem514.6*(s2p)/;n5ceil(num/dem);
n15n11;
i (rem(n,2)50)
n15n;
n5n21;
end
y5hamming(n1);
% low-passfilter
b5r1(n,wp,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((a) Normalised requency --.);
% high-passfilter
b5r1(n,wp,high,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((b) Normalised requency --.);
% bandpassfilter
wn5[wp ws];
b5r1(n,wn,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((c) Normalised requency --.);
% bandstopfilter
b5r1(n,wn,stop,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((d) Normalised requency --.);
As an example,
enter the passband ripple 0.03
enter the stopband ripple 0.01
enter the passband req 1400
enter the stopband req 2000enter the sampling req 8000
The gain responses o low-pass, high-pass, bandpass and bandstop flters using
Hanning window are shown in Fig. 16.36.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
62/96
876 Digital Signal Processing
16.14.7 Kaiser Window
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge requencies3. Get the sampling requency
4. Calculate the order o the flter
5. Find the window coefcients using Eqs 7.46 and 7.47
6. Draw the magnitude and phase responses.
% Program or the design o FIR Low pass, High pass, Band passand Bandstop flters using Kaiser window
clc;clear all;close all;
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
p5input(enter the passband req);
s5input(enter the stopband req);
5input(enter the sampling req);
beta5input(enter the beta value);
Fig. 16.36 Filters using Hanning Window (a) Low-pass (b) High-pass(c) Bandpass and (d) Bandstop
120
120 12
100
40
20
60
80 100
10010
8
6
4
2
0
80
60
80
40
20
60
40
20
0
20
0
0 2
20
0.2
0.2
0.2
0.2
0.4
0.4
0.4
0.4
(a)
(c)
(b)
(d)
Normalised frequency
Normalised frequency
Normalised frequency
Normalised frequency
0.6
0.6
0.6
0.6
0.8
0.8
0.8
0.8
1
1
1
1
0
0
0
0
GainindB
GainindB
GainindB
GainindB
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
63/96
MATLAB Programs 877
wp52*p/;ws52*s/;
num5220*log10(sqrt(rp*rs))213;
dem514.6*(s2p)/;n5ceil(num/dem);
n15n11;
i (rem(n,2)50)
n15n;
n5n21;
end
y5kaiser(n1,beta);
% low-passfilter
b5r1(n,wp,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB -->);
xlabel((a) Normalised requency -->);
% high-passfilter
b5r1(n,wp,high,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB -->);
xlabel((b) Normalised requency -->);
% bandpassfilter
wn5[wp ws];
b5r1(n,wn,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);ylabel(Gain in dB -->);
xlabel((c) Normalised requency -->);
% bandstopfilter
b5r1(n,wn,stop,y);
[h,o]5reqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);ylabel(Gain in dB -->);
xlabel((d) Normalised requency -->);
As an example,
enter the passband ripple 0.02
enter the stopband ripple 0.01
enter the passband req 1000
enter the stopband req 1500enter the sampling req 10000
enter the beta value 5.8
The gain responses o low-pass, high-pass, bandpass and bandstop flters using
Kaiser window are shown in Fig. 16.37.
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
64/96
878 Digital Signal Processing
16.15 UPSAMPLING A SINUSOIDAL SIGNAL
% Program or upsampling a sinusoidal signal by actor L
N5input(Input length o the sinusoidal sequence5);
L5input(Up Samping actor5);
5input(Input signal requency5);
% Generate the sinusoidal sequence or the specifed length N
n50:N21;
x5sin(2*pi**n);
% Generate the upsampled signal
y5zeros (1,L*length(x));
y([1:L:length(y)])5x;
%Plot the input sequence
subplot (2,1,1);stem (n,x);
title(Input Sequence);
xlabel(Time n);
ylabel(Amplitude);
Fig. 16.37 Filters using Kaiser Window (a) Low-pass (b) High-pass(c) Bandpass and (d) Bandstop
120
120 15
40
20
60
80
100
10010
5
0
80
60
80
40
20
60
40
20
0
20
0
0 5
20
0.2
0.2
0.2
0.2
0.4
0.4
0.4
0.4
(a)
(c)
(b)
(d)
Normalised frequency
Normalised frequency
Normalised frequency
Normalised frequency
0.6
0.6
0.6
0.6
0.8
0.8
0.8
0.8
1
1
1
1
0
0
0
0
GainindB
GainindB
GainindB
GainindB
-
7/30/2019 Digital Signal Processing-chapter 16: MATLAB Programs
65/96
MATLAB Programs 879
%Plot the output sequence
subplot (2,1,2);
stem (n,y(1:length(x)));title([output sequence,upsampling actor5,num2str(L)]);
xlabel(Time n);
ylabel(Amplitude);
16.16UPSAMPLING AN EXPONENTIALSEQUENCE