MATLAB Programs: % Program For The Generation of Unit Impulse Signal
MATLAB Programs: % Program For The Generation of Unit Impulse Signal
MATLAB Programs: % Program For The Generation of Unit Impulse Signal
Chapter 16
16.1 INTRODUCTION
MATLAB stands for MATrix LABoratory. It is a technical computing environment
for high performance 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 few dozen lines, to compute the solution with great accuracy
in a few minutes on a computer, and to readily manipulate a three-dimensional
display of 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
fraction of the time that it would take to write a program and execute in a language
such as FORTRAN, BASIC, or C. It also features a family of application specific
solutions, called toolboxes. Areas in which toolboxes are available include signal
processing, image processing, control systems design, dynamic systems simulation,
systems identification, neural networks, wavelength communication and others.
It can handle linear, non-linear, continuous-time, discrete-time, multivariable and
multirate systems. This chapter gives simple programs to solve specific problems
that are included in the previous chapters. All these MATLAB programs have been
tested under version 7.1 of MATLAB and version 6.12 of the signal processing
toolbox.
ylabel(Amplitude --.);
xlabel((a) n --.);
1 1
0.8 0.8
0.6 0.6
Amplitude
Amplitude
0.4 0.4
0.2 0.2
0 0
2 1 0 1 2 0 2 4 6
n n
(a) (b)
7 1
6
0.8
5
4 0.6
Amplitude
Amplitude
3 0.4
2
0.2
1
0 0
0 2 4 6 8 0 2 4 6 8
n n
(c) (d)
1
0.5
0
Amplitude
0.5
1
0 0.5 1 1.5 2 2.5 3 3.5
n
(e)
0.5
0
Amplitude
0.5
1
0 0.5 1 1.5 2 2.5 3 3.5
n
(f)
Fig. 16.1 Representation of Basic Signals (a) Unit Impulse Signal (b) Unit-step
Signal (c) Ramp Signal (d) Exponential Signal (e) Sinewave Signal ( f )Cosine Wave Signal
818 Digital Signal Processing
2
1.5
Amplitude
1
0.5
0
1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2
(a) n
2
1
0
1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3
(b) n
2
2
1.5
1.5
Amplitude
Amplitude
1
1
0.5
0.5
0
01
1 1.1
1.1 1.2
1.2 1.3
1.3 1.4
1.4 1.5
1.5 1.6
1.6 1.7
1.7 1.8
1.8 1.9
1.9 2
2
MATLAB Programs 819
(a) n
n
(a)
4
4
Amplitude
Amplitude 3
3
2
2
1
1
0
01
1 1.2
1.2 1.4
1.4 1.6
1.6 1.8
1.8 2
2 2.2
2.2 2.4
2.4 2.6
2.6 2.8
2.8 3
3
(b) n
n
(b)
8
8
6
6
Amplitude
Amplitude
4
4
2
2
0
0
1
1 1.5
1.5 2
2 2.5
2.5 3
3 3.5
3.5 4
4
(c) n
n
(c)
Fig. 16.2 Discrete Linear Convolution
16.3.2 Circular Convolution
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 for Computing Circular Convolution with zero padding
clc;
close all;
clear all;
g5input(enter the first sequence);
h5input(enter the 2nd sequence);
N15length(g);
N25length(h);
N5max(N1,N2);
N35N12N2;
%Loop for getting equal length sequence
if(N350)
h5[h,zeros(1,N3)];
else
g5[g,zeros(1,2N3)];
end
%computation of circular convolved sequence
for n51:N,
y(n)50;
for i51:N,
j5n2i11;
if(j550)
j5N1j;
end
y(n)5y(n)1g(i)*h(j);
end
end
disp(The resultant signal is);y
As an example,
enter the first sequence [1 2 4]
enter the 2nd sequence [1 2]
The resultant signal is y51 4 8 8
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.1 Crosscorrelation
Algorithm
xlabel((c) n --.);
disp(The resultant signal is);fliplr(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 signals x(n)and h(n)and the cross-correlated
output signal y(n).
4
3
Amplitude
2
1
0
1 1.5 2 2.5 3 3.5 4
(a) n
4
3
Amplitude
2
1
0
1 1.5 2 2.5 3 3.5 4
(b) n
30
20
Amplitude
10
0
1 2 3 4 5 6 7
(c) n
Fig. 16.3 Discrete Cross-correlation
16.4.2 Autocorrelation
Algorithm
4
3
Amplitude
2
1
0
1 1.5 2 2.5 3 3.5 4
(a) ( ) n
30
25
20
Amplitude
15
10
5
0
1 2 3 4 5 6 7
(b) y (n) n
Fig. 16.4 Discrete Auto-correlation
k5poly2rc(b);
knew5fliplr(k);
s5all(abs(knew)1);
if(s551)
disp(Stable system);
MATLAB Programs 825
else
disp(Non-stable system);
end
As an example,
enter the denominator coefficients of the filter [1 21 .5]
Stable system
Solution
% Program
Solution for Section (a)
clc;close all;clear all;
f151/128;f255/128;n50:255;fc550/128;
x5cos(2*pi*f1*n)1cos(2*pi*f2*n);
xa5cos(2*pi*fc*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 for Section (b)
n50:127;figure;n15128;
f151/128;f255/128;fc550/128;
x5cos(2*pi*f1*n)1cos(2*pi*f2*n);
xc5cos(2*pi*fc*n);
xa5cos(2*pi*fc*n);
(Contd.)
826 Digital Signal Processing
Amplitude
0
2
0 100 200 300
(i) n
Fig. 16.5(a) (i) Modulating Signal x (n)
0.5
Amplitude
0.5
1
Amplitude
2
0 100 200 300
(iii) n
Fig. 16.5(a) (iii) Amplitude Modulated Signal
(Contd.)
MATLAB Programs 827
25
20
15
10
Amplitude
10
0 20 40 60 80 100 120 140
n
Fig. 16.5(b) 128-point DFT of the Signal xam (n), 0#n#127
35
30
25
20
15
Amplitude
10
5
0 20 40 60 80 100 120 140
n
Fig. 16.5(c) 128-point DFT of the Signal xam (n), 0#n#99
828 Digital Signal Processing
xamp5x.*xa;xam5fft(xamp,n1);
stem(n,xam);title(xamp(n));xlabel(n --.);
ylabel(amplitude);
%128 point DFT computation2solution for Section (c)
n50:99;figure;n250:n121;
f151/128;f255/128;fc550/128;
x5cos(2*pi*f1*n)1cos(2*pi*f2*n);
xc5cos(2*pi*fc*n);
xa5cos(2*pi*fc*n);
xamp5x.*xa;
for i51:100,
xamp1(i)5xamp(i);
end
xam5fft(xamp1,n1);
stem(n2,xam);title(xamp(n));xlabel(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 of the
signal xam(n) for 0#n#127 and Fig. 16.5 (c) shows the 128-point DFT of the
signal xam(n), 0#n#99.
Algorithm
1. Get the signal x(n)of length N in matrix form
2. Get the N value
3. The transformed signal is denoted as
N 1 j
2p
nk
x( k ) = x( n )e N
for 0 k N 1
n=0
\ \% Program for computing discrete Fourier transform
clc;close all;clear all;
x5input(enter the sequence);
n5input(enter the length of fft);
X(k)5fft(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 of fft 8
X(k)5
Columns 1 through 4
28.0000 24.000019.6569i 24.0000 14.0000i 24.0000
11.6569i
Columns 5 through 8
24.0000 24.0000 21.6569i 24.0000 24.0000i 24.0000
29.6569i
MATLAB Programs 829
10
2
Imaginary axis
10
5 0 5 10 15 20 25 30
Real axis
w152*wp/fs;w252*ws/fs;
[n,wn]5buttord(w1,w2,rp,rs,s);
[z,p,k]5butter(n,wn);
[b,a]5zp2tf(z,p,k);
[b,a]5butter(n,wn,s);
w50:.01:pi;
[h,om]5freqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
frequency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised frequency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple 0.15
enter the stopband ripple 60
enter the passband freq 1500
enter the stopband freq 3000
enter the stopband freq 7000
The amplitude and phase responses of the Butterworth low-pass analog filter are
shown in Fig. 16.7.
50
50
0
0
50
50
dBdB
100
100
in in
150
Gain
150
Gain
200
200
250
250 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a) Normalised frequency
(a)
4
4
2
2
radians
radians
0
0
in in
2
Phase
2
Phase
4
4 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b) Normalised frequency
(b)
Fig. 16.7 Butterworth Low-pass Analog Filter
(a) Amplitude Response and (b) Phase Response
MATLAB Programs 831
Algorithm
100
in dB
200
GainGain
200
300
300
400
400 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6Normalised
0.7 frequency
0.8 0.9 1
(a)
Normalised frequency
(a)
4
4
2
2
in radians
0
in radians
0
2
Phase
2
Phase
4
4 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 frequency
Normalised 0.8 0.9 1
(b)
Normalised frequency
Fig. 16.8 Butterworth High-pass Analog
(b) Filter (a) Amplitude Response and
(b) Phase Response
[n]5buttord(w1,w2,rp,rs);
wn5[w1 w2];
[b,a]5butter(n,wn,bandpass,s);
w50:.01:pi;
[h,om]5freqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
frequency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised frequency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.36
enter the stopband ripple... 36
enter the passband freq... 1500
enter the stopband freq... 2000
enter the sampling freq... 6000
The amplitude and phase responses of Butterworth bandpass analog filter are
shown in Fig. 16.9.
200
0
200
Gain in dB
400
600
800
1000
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
2
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.9 Butterworth Bandpass Analog Filter (a) Amplitude Response and
(b) Phase Response
834 Digital Signal Processing
50
50
0
0
50
GaininindBdB
50
100
100
Gain
150
150
200
200 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a) Normalised frequency
(a)
4
4
2
2
radians
Phaseininradians
0
0
2
2
Phase
4
4 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b) Normalised frequency
(b)
Fig. 16.10 Butterworth Bandstop Analog Filter (a) Amplitude Response and
(b) Phase Response
w152*wp/fs;w252*ws/fs;
[n,wn]5cheb1ord(w1,w2,rp,rs,s);
[b,a]5cheby1(n,rp,wn,s);
w50:.01:pi;
[h,om]5freqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
frequency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised frequency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.23
enter the stopband ripple... 47
enter the passband freq... 1300
enter the stopband freq... 1550
enter the sampling freq... 7800
The amplitude and phase responses of Chebyshev type - 1 low-pass analog filter
are shown in Fig. 16.11.
20
40
Gain in dB
60
80
100
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
2
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.11 Chebyshev Type-I Low-pass Analog Filter (a) Amplitude Response
and (b) Phase Response
MATLAB Programs 837
100
GainGain
100
150
150
200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 frequency
Normalised 0.8 0.9 1
(a)
Normalised frequency
(a)
4
4
2
2
in radians
0
in radians
0
2
Phase
2
Phase
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 frequency
Normalised 0.8 0.9 1
(b)
Fig. 16.12 Chebyshev Type - 1 High-pass Normalised frequency
(b) Analog Filter (a) Amplitude Response
and (b) Phase Response
838 Digital Signal Processing
200
in dB
200
GainGain
300
300
400
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
400
0 0.1 0.2 0.3 0.4 0.5 0.6 Normalised
0.7 0.8
frequency0.9 1
(a)
Normalised frequency
(a)
3
3
2
2
1
1
in radians
0
in radians
0
1
1
2
Phase
2
3
Phase
100
in dB
150
Gain
150
Gain
200
200
250
250 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6Normalised
0.7 0.8
frequency 0.9 1
(a)
Normalised frequency
(a)
4
4
2
2
in radians
0
in radians
0
2
Phase
2
Phase
4
4 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
Normalised 0.8
frequency 0.9 1
(b)
Normalised frequency
(b) - 1 Bandstop Analog Filter
Fig. 16.14 Chebyshev Type
(a) Amplitude Response and (b) Phase Response
MATLAB Programs 841
% Program for the design of Chebyshev Type-2 low pass analog filter
clc;
close all;clear all;
format long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband freq...);
ws5input(enter the stopband freq...);
fs5input(enter the sampling freq...);
w152*wp/fs;w252*ws/fs;
[n,wn]5cheb2ord(w1,w2,rp,rs,s);
[b,a]5cheby2(n,rs,wn,s);
w50:.01:pi;
[h,om]5freqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
frequency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised frequency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.4
enter the stopband ripple... 50
enter the passband freq... 2000
enter the stopband freq... 2400
enter the sampling freq... 10000
The amplitude and phase responses of Chebyshev type - 2 low-pass analog filter
are shown in Fig. 16.15.
842 Digital Signal Processing
20
40
Gain in dB
60
80
100
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
2
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.15 Chebyshev Type - 2 Low-pass Analog Filter (a) Amplitude Response
and (b) Phase Response
[h,om]5freqs(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised frequency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised frequency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.34
enter the stopband ripple... 34
enter the passband freq... 1400
enter the stopband freq... 1600
enter the sampling freq... 10000
The amplitude and phase responses of Chebyshev type - 2 high-pass analog filter
are shown in Fig. 16.16.
20
40
Gain in dB
60
80
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
0
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.16 Chebyshev Type - 2 High-pass Analog Filter
(a) Amplitude Response and (b) Phase Response
60
80
100
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
Fig. 16.17 (Contd.)
4
2
ase in radians
2
40
Gain in d
60
80
100
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
MATLAB Programs
Normalised frequency 845
(a)
2
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.17 Chebyshev Type - 2 Bandstop Analog Filter (a) Amplitude Response
and (b) Phase Response
As an example,
enter the passband ripple... 0.25
enter the stopband ripple... 30
enter the passband freq... 1300
enter the stopband freq... 2000
enter the sampling freq... 8000
The amplitude and phase responses of Chebyshev type - 2 bandstop analog filter
are shown in Fig. 16.18.
40
20
0
Gain in dB
20
40
60
80
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
2
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.18 Chebyshev Type - 2 Bandstop Analog Filter
(a) Amplitude Response and (b) Phase Response
100
Gain in dB
200
300
400
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
2
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
200
Gain
300
400
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
848 Digital Signal Processing (a)
2
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.19 Butterworth Low-pass Digital Filter (a) Amplitude Response and
(b) Phase Response
16.11.2 High-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter using Eq. 8.46
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
% Program for the design of Butterworth highpass digital filter
clc;
close all;clear all;
format long
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
wp5input(enter the passband freq);
ws5input(enter the stopband freq);
fs5input(enter the sampling freq);
w152*wp/fs;w252*ws/fs;
[n,wn]5buttord(w1,w2,rp,rs);
[b,a]5butter(n,wn,high);
w50:.01:pi;
[h,om]5freqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
frequency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised frequency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple 0.5
enter the stopband ripple 50
enter the passband freq 1200
MATLAB Programs 849
50
50
0
0
50
50
100
GaininindBdB
100
150
150
200
Gain
200
250
250
300
300 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a) Normalised frequency
(a)
4
4
2
2
radians
Phaseininradians
0
0
2
2
Phase
4
4 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b) Normalised frequency
(b)
Fig. 16.20 Butterworth High-pass Digital Filter
(a) Amplitude Response and (b) Phase Response
400
500
600
700
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a) Normalised frequency
4
2
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised frequency
Fig. 16.21 Butterworth Bandstop Digital Filter (a) Amplitude Response and
(b) Phase Response
MATLAB Programs 851
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter using Eq. 8.46
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
100
100
dB
in dB
200
Gain in
Gain
300
400
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
2
radians
in radians
0
Phase in
2
Phase
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.22 Butterworth Bandstop Digital Filter
(a) Amplitude Response and (b) Phase Response
w152*wp/fs;w252*ws/fs;
[n,wn]5cheb1ord(w1,w2,rp,rs);
[b,a]5cheby1(n,rp,wn);
w50:.01:pi;
[h,om]5freqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
frequency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised frequency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.2
enter the stopband ripple... 45
enter the passband freq... 1300
enter the stopband freq... 1500
enter the sampling freq... 10000
The amplitude and phase responses of Chebyshev type - 1 low-pass digital filter
are shown in Fig. 16.23.
100
200
Gain in dB
300
400
500
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
2
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.23 Chebyshev Type - 1 Low-pass Digital Filter (a) Amplitude Response
and (b) Phase Response
854 Digital Signal Processing
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
3. Get the sampling frequency
4. Calculate the order of the filter using Eq. 8.57
5. Find the filter coefficients
6. Draw the magnitude and phase responses.
0
0
50
50
100
100
150
150
dB
GaininindB
200
200
250
250
Gain
300
300
350
350
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a) Normalised frequency
(a)
4
4
2
2
radians
Phaseininradians
0
0
2
2
Phase
4
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b) Normalised frequency
(b)
Fig. 16.24 Chebyshev Type - 1 High-pass Digital Filter
(a) Amplitude Response and (b) Phase Response
[n]5cheb1ord(w1,w2,rp,rs);
wn5[w1 w2];
[b,a]5cheby1(n,rp,wn,bandpass);
w50:.01:pi;
[h,om]5freqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
frequency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised frequency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.4
enter the stopband ripple... 35
enter the passband freq... 2000
enter the stopband freq... 2500
enter the sampling freq... 10000
The amplitude and phase responses of Chebyshev type - 1 bandpass digital filter
are shown in Fig. 16.25.
100
200
Gain in dB
300
400
500
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
2
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.25 Chebyshev Type - 1 Bandpass Digital Filter (a) Amplitude
Response and (b) Phase Response
MATLAB Programs 857
clc;
close all;clear all;
format long
rp5input(enter the passband ripple...);
rs5input(enter the stopband ripple...);
wp5input(enter the passband freq...);
ws5input(enter the stopband freq...);
fs5input(enter the sampling freq...);
w152*wp/fs;w252*ws/fs;
[n]5cheb1ord(w1,w2,rp,rs);
wn5[w1 w2];
[b,a]5cheby1(n,rp,wn,stop);
w50:.1/pi:pi;
[h,om]5freqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
frequency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised frequency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.25
enter the stopband ripple... 40
enter the passband freq... 2500
enter the stopband freq... 2750
enter the sampling freq... 7000
The amplitude and phase responses of Chebyshev type - 1 bandstop digital filter
are shown in Fig. 16.26.
858 Digital Signal Processing
0
0
50
50
100
in dB
100
in dB
GainGain
150
150
200
200 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7frequency
Normalised 0.8 0.9 1
(a)
Normalised frequency
(a)
4
4
3
3
2
in radians
1
2
in radians
1
0
1
0
Phase
2
1
Phase
2
3
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
3
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7frequency
Normalised 0.8 0.9 1
(b)
Normalised frequency
(b) - 1 Bandstop Digital Filter
Fig. 16.26 Chebyshev Type
(a) Amplitude Response and (b) Phase Response
w50:.01:pi;
[h,om]5freqz(b,a,w);
m520*log10(abs(h));
an5angle(h);
subplot(2,1,1);plot(om/pi,m);
ylabel(Gain in dB --.);xlabel((a) Normalised
frequency --.);
subplot(2,1,2);plot(om/pi,an);
xlabel((b) Normalised frequency --.);
ylabel(Phase in radians --.);
As an example,
enter the passband ripple... 0.35
enter the stopband ripple... 35
enter the passband freq... 1500
enter the stopband freq... 2000
enter the sampling freq... 8000
The amplitude and phase responses of Chebyshev type - 2 low-pass digital filter
are shown in Fig. 16.27.
20
20
0
0
20
20
dBdB
40
in in
40
Gain
60
Gain
60
80
80
100
100 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a) Normalised frequency
(a)
4
4
2
2
radians
radians
0
0
in in
2
Phase
2
Phase
4
4 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b) Normalised frequency
(b)
Fig. 16.27 Chebyshev Type - 2 Low-pass Digital Filter (a) Amplitude Response
and (b) Phase Response
16.13.2 High-pass Filter
Algorithm
1. Get the passband and stopband ripples
2. Get the passband and stopband edge frequencies
860 Digital Signal Processing
20
40
60
Gain in dB
80
100
120
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
Fig. 16.28 (Contd.)
4
2
ase in radians
2
Gain in
80
100
120
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
MATLAB Programs 861
(a)
2
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.28 Chebyshev Type - 2 High-pass Digital Filter (a) Amplitude Response
and (b) Phase Response
16.13.3 Bandpass Filter
Algorithm
As an example,
enter the passband ripple... 0.4
enter the stopband ripple... 40
enter the passband freq... 1400
enter the stopband freq... 2000
enter the sampling freq... 9000
The amplitude and phase responses of Chebyshev type - 2 bandpass digital filter
are shown in Fig. 16.29.
100
100
Gain in dB
200
300
400
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
2
Phase in radians
4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.29 Chebyshev Type - 2 Bandpass Digital Filter (a) Amplitude Response
and (b) Phase Response
20
20
Gain in dB
40
60
80
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(a)
Fig. 16.30 (Contd.)
3
2
1
Phase in radians
0
-1
-2
-3
-4
40
Gain i
60
80
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
864 Digital Signal Processing (a)
3
2
1
Phase in radians
0
-1
-2
-3
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency
(b)
Fig. 16.30 Chebyshev Type - 2 Bandstop Digital Filter (a) Amplitude Response
and (b) Phase Response
20 log( d pd s ) 13
N=
14.6( f s f p ) / Fs
where dp is the passband ripple, ds is the stopband ripple, fp is the passband frequency,
fs is the stopband frequency and Fs is the sampling frequency.
Algorithm
% Program for the design of FIR Low pass, High pass, Band pass
and Bandstop filters using rectangular window
dem514.6*(fs2fp)/f;
n5ceil(num/dem);
n15n11;
if (rem(n,2)50)
n15n;
n5n21;
end
y5boxcar(n1);
% low-pass filter
b5fir1(n,wp,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((a) Normalised frequency --.);
% high-pass filter
b5fir1(n,wp,high,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((b) Normalised frequency --.);
20 20
0 0
20 20
Gain in dB
Gain in dB
40 40
60 60
80 80
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(a) (b)
20 5
0 0
20 5
Gain in dB
Gain in dB
40 10
60 15
80 20
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(c) (d)
Fig. 16.31 Filters Using Rectangular Window (a) Low-pass (b) High-pass
(c) Bandpass and (d) Bandstop
Algorithm
wp52*fp/f;ws52*fs/f;
num5220*log10(sqrt(rp*rs))213;
dem514.6*(fs2fp)/f;
n5ceil(num/dem);
n15n11;
if (rem(n,2)50)
n15n;
n5n21;
end
y5bartlett(n1);
% low-pass filter
b5fir1(n,wp,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((a) Normalised frequency --.);
% high-pass filter
b5fir1(n,wp,high,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((b) Normalised frequency --.);
% band pass filter
wn5[wp ws];
b5fir1(n,wn,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((c) Normalised frequency --.);
% band stop filter
b5fir1(n,wn,stop,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((d) Normalised frequency --.);
As an example,
enter the passband ripple 0.04
enter the stopband ripple 0.02
enter the passband freq 1500
enter the stopband freq 2000
enter the sampling freq 8000
The gain responses of low-pass, high-pass, bandpass and bandstop filters using
Bartlett window are shown in Fig. 16.32.
868 Digital Signal Processing
0 5
5 0
10 5
Gain in dB
Gain in dB
15 10
20 15
25 20
30 25
35 30
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(a) (b)
0 2
10 0
2
Gain in dB
Gain in dB
20
4
30
6
40 8
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(c) (d)
Fig. 16.32 Filters using Bartlett Window (a) Low-pass (b) High-pass
(c) Bandpass and (d) Bandstop
Algorithm
% Program for the design of FIR Low pass, High pass, Band pass
and Band stop digital filters using Blackman window
clc;clear all;close all;
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
fp5input(enter the passband freq);
fs5input(enter the stopband freq);
f5input(enter the sampling freq);
MATLAB Programs 869
wp52*fp/f;ws52*fs/f;
num5220*log10(sqrt(rp*rs))213;
dem514.6*(fs2fp)/f;
n5ceil(num/dem);
n15n11;
if (rem(n,2)50)
n15n;
n5n21;
end
y5blackman(n1);
% low-pass filter
b5fir1(n,wp,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((a) Normalised frequency --.);
% high-pass filter
b5fir1(n,wp,high,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((b) Normalised frequency --.);
% band pass filter
wn5[wp ws];
b5fir1(n,wn,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((c) Normalised frequency --.);
% band stop filter
b5fir1(n,wn,stop,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);;ylabel(Gain in dB --.);
xlabel((d) Normalised frequency --.);
As an example,
enter the passband ripple 0.03
enter the stopband ripple 0.01
enter the passband freq 2000
enter the stopband freq 2500
enter the sampling freq 7000
The gain responses of low-pass, high-pass, bandpass and bandstop filters using
Blackman window are shown in Fig. 16.33.
870 Digital Signal Processing
20 50
0
20 0
Gain in dB
Gain in dB
40
50
60
80
100
100
120 150
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(a) (b)
0 2
20
0
40
2
Gain in dB
Gain in dB
60
4
80
100 6
120 8
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(c) (d)
Fig. 16.33 Filters using Blackman Window (a) Low-pass (b) High-pass
(c) Bandpass and (d) Bandstop
Algorithm
% Program for the design of FIR Lowpass, High pass, Band pass
and Bandstop filters using Chebyshev window
clc;clear all;close all;
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
fp5input(enter the passband freq);
fs5input(enter the stopband freq);
f5input(enter the sampling freq);
MATLAB Programs 871
20 20
0 0
20 20
Gain in dB
Gain in dB
40 40
60 60
80 80
100 100
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(a) (b)
0 2
20 0
2
40
Gain in dB
Gain in dB
4
60
6
80
8
100 10
120 12
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(c) (d)
Fig. 16.34 Filters using Chebyshev Window (a) Low-pass (b) High-pass
(c) Bandpass and (d) Bandstop
Algorithm
% Program for the design of FIR Low pass, High pass, Band pass
and Bandstop filters using Hamming window
clc;clear all;close all;
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
fp5input(enter the passband freq);
fs5input(enter the stopband freq);
f5input(enter the sampling freq);
MATLAB Programs 873
wp52*fp/f;ws52*fs/f;
num5220*log10(sqrt(rp*rs))213;
dem514.6*(fs2fp)/f;
n5ceil(num/dem);
n15n11;
if (rem(n,2)50)
n15n;
n5n21;
end
y5hamming(n1);
% low-pass filter
b5fir1(n,wp,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((a) Normalised frequency --.);
% high-pass filter
b5fir1(n,wp,high,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((b) Normalised frequency --.);
% band pass filter
wn5[wp ws];
b5fir1(n,wn,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((c) Normalised frequency --.);
% band stop filter
b5fir1(n,wn,stop,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((d) Normalised frequency --.);
As an example,
enter the passband ripple 0.02
enter the stopband ripple 0.01
enter the passband freq 1200
enter the stopband freq 1700
enter the sampling freq 9000
The gain responses of low-pass, high-pass, bandpass and bandstop filters using
Hamming window are shown in Fig. 16.35.
874 Digital Signal Processing
20 20
0 0
20
20
Gain in dB
Gain in dB
40
40
60
60
80
100 80
120 100
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(a) (b)
0 2
20
0
40
Gain in dB
Gain in dB
60 5
80
10
100
120 15
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(c) (d)
Fig. 16.35 Filters using Hamming Window (a) Low-pass (b) High-pass
(c) Bandpass and (d) Bandstop
Algorithm
% Program for the design of FIR Low pass, High pass, Band pass
and Band stop filters using Hanning window
clc;clear all;close all;
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
fp5input(enter the passband freq);
fs5input(enter the stopband freq);
f5input(enter the sampling freq);
MATLAB Programs 875
wp52*fp/f;ws52*fs/f;
num5220*log10(sqrt(rp*rs))213;
dem514.6*(fs2fp)/f;
n5ceil(num/dem);
n15n11;
if (rem(n,2)50)
n15n;
n5n21;
end
y5hamming(n1);
% low-pass filter
b5fir1(n,wp,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((a) Normalised frequency --.);
% high-pass filter
b5fir1(n,wp,high,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((b) Normalised frequency --.);
% band pass filter
wn5[wp ws];
b5fir1(n,wn,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((c) Normalised frequency --.);
% band stop filter
b5fir1(n,wn,stop,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);ylabel(Gain in dB --.);
xlabel((d) Normalised frequency --.);
As an example,
enter the passband ripple 0.03
enter the stopband ripple 0.01
enter the passband freq 1400
enter the stopband freq 2000
enter the sampling freq 8000
The gain responses of low-pass, high-pass, bandpass and bandstop filters using
Hanning window are shown in Fig. 16.36.
876 Digital Signal Processing
20 20
0 0
20
20
Gain in dB
Gain in dB
40
40
60
60
80
100 80
120 100
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(a) (b)
0 2
20 0
2
40
Gain in dB
Gain in dB
4
60
6
80
8
100 10
120 12
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(c) (d)
Fig. 16.36 Filters using Hanning Window (a) Low-pass (b) High-pass
(c) Bandpass and (d) Bandstop
Algorithm
% Program for the design of FIR Low pass, High pass, Band pass
and Bandstop filters using Kaiser window
clc;clear all;close all;
rp5input(enter the passband ripple);
rs5input(enter the stopband ripple);
fp5input(enter the passband freq);
fs5input(enter the stopband freq);
f5input(enter the sampling freq);
beta5input(enter the beta value);
MATLAB Programs 877
wp52*fp/f;ws52*fs/f;
num5220*log10(sqrt(rp*rs))213;
dem514.6*(fs2fp)/f;
n5ceil(num/dem);
n15n11;
if (rem(n,2)50)
n15n;
n5n21;
end
y5kaiser(n1,beta);
% low-pass filter
b5fir1(n,wp,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);ylabel(Gain in dB -->);
xlabel((a) Normalised frequency -->);
% high-pass filter
b5fir1(n,wp,high,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);ylabel(Gain in dB -->);
xlabel((b) Normalised frequency -->);
% band pass filter
wn5[wp ws];
b5fir1(n,wn,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);ylabel(Gain in dB -->);
xlabel((c) Normalised frequency -->);
% band stop filter
b5fir1(n,wn,stop,y);
[h,o]5freqz(b,1,256);
m520*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);ylabel(Gain in dB -->);
xlabel((d) Normalised frequency -->);
As an example,
enter the passband ripple 0.02
enter the stopband ripple 0.01
enter the passband freq 1000
enter the stopband freq 1500
enter the sampling freq 10000
enter the beta value 5.8
The gain responses of low-pass, high-pass, bandpass and bandstop filters using
Kaiser window are shown in Fig. 16.37.
878 Digital Signal Processing
20 20
0
0
20
40 20
Gain in dB
Gain in dB
60 40
80
60
100
120 80
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(a) (b)
0 5
20
0
40
Gain in dB
Gain in dB
60 5
80
10
100
120 15
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Normalised frequency Normalised frequency
(c) (d)
Fig. 16.37 Filters using Kaiser Window (a) Low-pass (b) High-pass
(c) Bandpass and (d) Bandstop
UPSAMPLING AN EXPONENTIAL
16.16
SEQUENCE
% Program for upsampling an exponential sequence by a factor M
n5input(enter length of input sequence );
l5input(enter up sampling factor );
% Generate the exponential sequence
m50:n21;
a5input(enter the value of a );
x5a.^m;
% Generate the upsampled signal
y5zeros(1,l*length(x));
y([1:l:length(y)])5x;
figure(1)
stem(m,x);
xlabel({Time n;(a)});
ylabel(Amplitude);
figure(2)
stem(m,y(1:length(x)));
xlabel({Time n;(b)});
ylabel(Amplitude);
As an example,
enter length of input sentence 25
enter upsampling factor 3
enter the value of a 0.95
The input and output sequences of upsampling an exponential sequence an are shown
in Fig. 16.38.
16.19 DECIMATOR
5
Amplitude
5
0 500 1000 1500 2000 2500
Time in Seconds
(a)
5
Amplitude
5
0 20 40 60 80 100 120
Time in Seconds
(b)
5
Amplitude
5
0 50 100 150 200 250
Time in Seconds
(c)
Fig. 16.40 (a) Input Sequence, (b) Decimated Sequence and
(c) Interpolated sequence
% 4:
Get the two FFT lengths for comparing the corre-
sponding power spectral densities
clc; close all; clear all;
f15input(Enter the frequency of first sinusoid);
f25input(Enter the frequency of second sinusoid);
fs5input(Enter the sampling frequency);
N5input(Enter the length of the input sequence);
N15input(Enter the input FFT length 1);
N25input(Enter the input FFT length 2);
%Generation of input sequence
t50:1/fs:1;
x52*sin(2*pi*f1*1)13*sin(2*pi*f2*t)2randn(size(t));
%Generation of psd for two different FFT lengths
Pxx15abs(fft(x,N1)).^2/(N11);
Pxx25abs(fft(x,N2)).^2/(N11);
%Plot the psd;
subplot(2,1,1);
plot ((0:(N121))/N1*fs,10*log10(Pxx1));
xlabel(Frequency in Hz);
ylabel(Power spectrum in dB);
title([PSD with FFT length,num2str(N1)]);
subplot (2,1,2);
plot ((0:(N221))/N2*fs,10*log10(Pxx2));
xlabel(Frequency in Hz);
ylabel(Power spectrum in dB);
title([PSD with FFT length,num2str(N2)]);
10
15
20
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised Frequency (x pi rad/sample)
Fig. 16.41 Welch PSD Estimate
20
40
60
80
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
N=512 Overlap = 50% Hanning
Power Spectral Density (dB/Hz)
50
100
150
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
Fig. 16.42 (a) Welch Estimate with N5512, 50% Overlap Hanning
Overlay plot of 50 Welch estimates
Power Spectral Density (dB/Hz)
20
40
60
80
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
N=512 Overlap = 50% Hamming
Power Spectral Density (dB/Hz)
20
40
60
80
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
Fig. 16.42 (b) Welch Estimate with N5512, 50% Overlap Hamming
888 Digital Signal Processing
20
40
60
80
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
N=512 Overlap = 50% Bartlett
Power Spectral Density (dB/Hz)
20
40
60
80
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
Fig. 16.42 (c) Welch Estimate with N5512, 50% Overlap Bartlett
20
40
60
80
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
N=512 Overlap = 50% Blackman
Power Spectral Density (dB/Hz)
50
100
150
200
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
Fig. 16.42 (d) Welch Estimate with N5512, 50% Overlap Blackman
MATLAB Programs 889
20
40
60
80
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
N = 512 Overlap = 50% Rectangular
Power Spectral Density (dB/Hz)
0
10
20
30
40
50
60
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
Fig. 16.42 (e) Welch Estimate with N5512, 50% Overlap Rectangular
figure(3)
subplot(211);
pwelch(y,[],[],[],fs);
title(Overlay plot of 50 Welch estimates);
subplot(212);
pwelch(y,bartlett(512),0,512,fs);
title(N5512 Overlap550% Bartlett);
figure(4)
subplot(211);
pwelch(y,[],[],[],fs);
title(Overlay plot of 50 Welch estimates);
subplot(212);
pwelch(y,blackman(512),0,512,fs);
title(N5512 Overlap550% Blackman);
figure(5)
subplot(211);
pwelch(y,[],[],[],fs);
title(Overlay plot of 50 Welch estimates);
subplot(212);
pwelch(y,boxcar(512),0,512,fs);
title(N5512 Overlap550% Rectangular);
10
10
20
30
40
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
N=512 Overlap = 50% Hanning
Power Spectral Density (dB/Hz)
10
10
20
30
40
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
Fig. 16.43 (a) Welch Estimate with N5512, 50% Overlap Hanning
MATLAB Programs 891
10
10
20
30
40
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
N=512 Overlap = 50% Hanning
Power Spectral Density (dB/Hz)
10
10
20
30
40
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
Fig. 16.43 (b) Welch Estimate with N5512, 50% Overlap Hamming
10
10
20
30
40
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
N=512 Overlap = 50% Bartlett
Power Spectral Density (dB/Hz)
10
10
20
30
40
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
Fig. 16.43 (c) Welch Estimate with N5512, 50% Overlap Bartlett
892 Digital Signal Processing
20
30
40
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
N=512 Overlap = 50% Blackman
10
0
10
20
30
40
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
Fig. 16.43 (d) Welch Estimate with N5512, 50% Overlap Blackman
10
10
20
30
40
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
N=512 Overlap = 50% Hanning
Power Spectral Density (dB/Hz)
10
10
20
30
40
0 50 100 150 200 250 300 350 400 450 500
Frequency (Hz)
Fig. 16.43 (e) Welch Estimate with N5512, 50% Overlap Rectangular
MATLAB Programs 893
DECIMATION BY POLYPHASE
16.36
DECOMPOSITION
v5fft(v);
y5[ ];
for m51:M,y5[conv(v(m,:),q(m,:));y]; end
y5y(:).;
% Program
function b5wiener(kappax,kappayx);
kappax5input(enter the covariance sequence5);
kappyx5input(enter the joint covariance sequence5);
q5length(kappax)21;
kappax5reshape(kappax,q11,1);
kappayx5reshape(kappayx,q11,1);
b5(toeplitz(kappax)/(kappayx);
% Program
function X5stsa(x,N,K,L,w,opt,M,theta0,dtheta);
x5input(enter the input signal5); L5input(enter the
number consecutive DFTs to average5);
N5input(enter the segment length5); K5input(enter
the number of overlapping points5); w5input(enter
900 Digital Signal Processing
Base band
Desired
sequence transmit
filter
Echo Echo
Canceler path
Estimated
sequence
Fig. 16.44 Baseband Channel Echo Canceler
Echo Echo
Canceler path
Estimated Passband
sequence receive
filter
l15length(ar); j51;
for i5round(ll/2): l1,
ar1(j)5ar(i)
j5j11;
end
% Toeplitz matrix is taken for the auto correlated
signal
r5toeplitz(ar1);
l25length(crd); j51;
for i5round(l2/2):l2,
crd1(j)5crd(i);
j5j11;
end
p5crd1;
% Maximum and minimum eigen values are calculated from
the toeplitz matrix
lam5max(eig(r)); la5min(eig(r)); l5lam/la;
% initial filter taps are found using the below relation
w5inv(r)*p;
% The step size factor is calculated
m5length(ns)22.5;
a5(m2.95367)/.274274;
mu5a/lam;
% The initial error is calculated
s51;
e5rs2filter(w,1,ns); ni51; figure(2); subplot(2,2,1);
% Filter taps are iterated until the mean squared error
becomes E225
while (s25 ! s0)
w15w22*mu*(e.*ns);
if (ni5100)
break;
end
rs
y45filter(w1,1,ns)
e5y42rs; s50; el5e.*e;
for i51: length(e1),
s5s1e1(i);
end
s5s/length(e1);
ni5ni11;
w5w1; plot (ni,e); hold on; title( MSE vs no. of
iterations);
end
end
subplot(2,2,2); plot(y4); title(estimated noise signal);
xlabel(Time ); ylabel(Amplitude );
subplot(2,2,3); plot(q-y4); title(noise cancelled signal);
xlabel(Time ); ylabel(Amplitude );
MATLAB Programs 905
Review Questions
16.1 (a) Generate unit impulse function
(b) Generate signal x(n)5u(n) 2 u(n 2 N)
(c) Plot the sequence, x(n)5A cos ((2p f n)/fs), where n50 to 100
fs5100 Hz, f51 Hz, A50.5
(d) Generate x (n)5exp (25n), where n50 to 10.
16.2 Consider a system with impulse response
(1 / 2) n , n = 0 to 4
h( n) =
0, elsewhere.
16.3 Consider the figure.
y (n)
( ) h 1 (n) h 2 (n)
()
h 3 (n) h 4 (n)
Fig. Q16.3
(a) Express the overall impulse response in terms of h1(n), h2(n), h3(n), h4(n)
(b) Determine h(n) when h1(n)5{1/2, 1/4, 1/2}
h2(n)5h3(n)5(n11) u(n)
h4(n)5d(n 2 2)
(c)Determine the response of the system in part (b) if x(n)5 d(n12)
13d(n 2 1) 2 4d(n 2 3).
16.4 Compute the overall impulse response of the system
3 (n)
( ) H1 H2 H4 y (n)
y 3(n)
H3
Fig. Q16.4
for 0# n# 99. The system H1, H2, H3, H4, are specified by
H1 : h1[n]5{1, 1/2, 1/4, 1/8, 1/16, 1/32}
H2 : h2[n]5{1, 1, 1, 1, 1}
H3 : y3[n]5(1/4) x(n)1(1/2) x(n 2 1)1(1/4) x(n 2 2)
H4 : y[n]50.9 y(n 2 1) 2 0.81 y(n 2 2)1V(n)1V(n 2 1)
Plot h(V) for 0#n#99.
16.5Consider the system with h(n)5an u(n), 21,a,1. Determine the response.
x(n)5u(n15) 2 u(n 2 10)
906 Digital Signal Processing
y (n)
h (n)
()
z 2 h(n)
Fig. Q16.5
16.6 (i) Determine the range of values of the parameter a for which the linear
time invariant system with impulse response
a n , n 0, n even
h( n) =
0, otherwise
is stable.
(ii)Determine the response of the system with impulse response
h(n)5anu(n) to the input signal x(n)5u(n) 2 u(n 2 10)
16.7Consider the system described by the difference equation y(n)5a (y11)1
bx (n). Determine b in terms of a so that S h(n)51.
(a)Compute the zero-state step response s(n) of the system and choose b
so that s(`)51.
(b)Compare the values of b obtained in parts (a) and (b). What did you
observe?
16.8Compute and sketch the convolution y(n) and correlation rxh(n) sequences
for the following pair of signals and comment on the results obtained.
1, 2, 4 1, 1, 1, 1, 1
x1 ( n) = h1 ( n) =
0, 1, 2, 3, 4 1 / 2, 1, 2, 1, 1 / 2
x2 ( n) = h2 ( n) =
1, 2, 3, 4 4, 3, 2, 1
x3 ( n) = h3 ( n) =
1, 2, 3, 4 1, 2, 3, 4
x4 ( n) = h4 ( n) =
16.9Consider the recursive discrete-time system described by the difference
equation.
y(n)5a1y(n 2 1) 2 a2(n 2 2)1b0 x(n)
where a1520.8, a250.64, b050.866
(a)Write a program to compute and plot the impulse response h(n) of the
system for 0#n#49.
(b)Write a program to compute and plot the zero-state step response s(n)
of the system for 0#n#100.
(c) Define an FIR system with impulse response hFIR(n) given by
h( n), 0 n 19
hFIR ( n) =
0, elsewhere
where h(n) is the impulse response computed in part (a). Write a
program to compute and plot its step response.
(d)Compare the results obtained in part (b) and part (c) and explain their
similarities and differences.
MATLAB Programs 907
etermine and plot the real and imaginary parts and the magnitude and phase
16.10 D
spectra of the following DTFT for various values of r and u
G(z)51/(1 2 2r(cos u) z211r2z22) for 0,r,1.
16.11Using MATLAB program compute the circular convolution of two length-N
sequences via the DFT based approach. Using this problem determine the
circular convolution of the following pairs of sequences:
(a) x(n)5{1, 2 3, 4, 2, 0, 2 2} h(n)5{3, 0, 1, 2 1, 2, 1}
(b) x(n)5{31j2, 221j, j3, h(n)5{ 1 2 j3, 41j2, 2 2 j2,
11j4, 231j3}, 231j5, 21j }
(c) x(n)5cos (pn/2) h(n)53 0#n#5 n
12 16
(a) H1 ( z ) = 3 + , z > 0.5
( 2 z 1 ) ( 4 z 1 )
3 ( 4 z 1 )
(b) H 2 ( z ) = 3 + , z > 0.5
(1 + 0.5 z 1 ) (1 + 0.25 z 2 )
20 10 4
(c) H 3 ( z ) = + , z > 0.4
(5 + 2 z )
1 2
(5 + 2 z ) (1 + 0.9 z 2 )
1
10 z 1
(d) H 4 ( z ) = 8 + + , z > 0.4
( 5 + 2 z 1 ) ( 6 + 5 z 1 + z 2 )
16.14 Determine the inverse z-transform of each z-transform given in Q16.13.
16.15 Consider the system
(1 2 z 1 + 2 z 2 z 3 )
H ( z) = , ROC 0.5 < z < 1
(1 z 1 )(1 0.5 z 1 )(1 0.2 z 1 )
(a) Sketch the pole-zero pattern. Is the system stable?
(b) Determine the impulse response of the system.
16.16 Determine the impulse response and the step response of the following
causal systems. Plot the pole-zero patterns and determine which of the
systems are stable.
3 1
(a) y( n) = y( n 1) y( n 2) + x( n)
4 8
908 Digital Signal Processing
(c) Repeat parts (a) and (b) using the Hamming window
(d) Repeat parts (a) and (b) using the Bartlett window.
16.21 A digital low-pass filter is required to meet the following specfications
Passband ripple1 dB
Passband edge 4 kHz
Stopband attenuation40 dB
Stopband edge 6 kHz
Sample rate 24 kHz
The filter is to be designed by performing a bilinear transformation on an
analog system function. Determine what order Butterworth, Chebyshev and
elliptic analog design must be used to meet the specifications in the digital
implementation.
16.22 An IIR digital low-pass filter is required to meet the following specfications
Passband ripple0.5 dB
Passband edge 1.2 kHz
Stopband attenuation40 dB
Stopband edge 2 kHz
Sample rate 8 kHz
Use the design formulas to determine the filter order for
(a) Digital Butterworth filter
(b) Digital Chebyshev filter
(c) Digital elliptic filter
16.23An analog signal of the form xa(t)5a(t) cos(2000 t) is bandlimited to the range
900F1100Hz. It is used as an input to the system shown in Fig. Q16.23.
( ) (n) a(n)
a (t )
A/D H ( ) D /A
Fig. Q16.23
(a) Determine and sketch the spectra for the signal x(n) and w(n).
(b)Use Hamming window of length M531 to design a low-pass linear
phase FIR filter H() that passes {a(n)}.
(c)Determine the sampling rate of A/D converter that would allow us to
eliminate the frequency conversion in the above figure.
16.24 Consider the signal x(n)5an u(m), |a|,1
(a) Determine the spectrum X()
(b)The signal x(n) is applied to a device (decimator) which reduces the
rate by a factor of two. Determine the output spectrum.
(c) Show that the spectrum is simply the Fourier transform of x(2n).
16.25Design a digital type-I Chebyshev low-pass filter operating at a sampling
rate of 44.1kHz with a passband frequency at 2kHz, a pass band ripple
of 0.4dB, and a minimum stopband attenuation of 50dB at 12kHz using
the impulse invariance method and the bilinear transformation method.
Determine the order of analog filter prototype and design the analog pro-
totype filter. Plot the gain and phase responses of the both designs using
910 Digital Signal Processing
MATLAB. Compare the performances of the two filters. Show all steps
used in the design.
Hint 1. The order of filter
cosh1 ( ( A2 1) /
N=
cosh1 ( s / p)
2. Use the function cheblap.
16.26 Design a linear phase FIR high-pass filter with following specifications:
Stopband edge at 0.5p, passband edge at 0.7p, maximum passband attenuation
of 0.15dB and a minimum stopband attenuation of 40dB. Use each of the
following windows for the design. Hamming, Hanning, Blackman and
Kaiser. Show the impulse response coefficients and plot the gain response of
the designed filters for each case.
16.27Design using the windowed Fourier series approach a linear phase FIR low-
pass filter with the following specifications: pass band edge at 1 rad/s, stop
band edge at 2rad/s, maximum passband attenuation of 0.2dB, minimum
stopband attenuation of 50dB and a sampling frequency of 10rad/s. Use each
of the following windows for the design: Hamming, Hanning, Blackman,
Kaiser and Chebyshev. Show the impulse response coefficients and plot the
gain response of designed filters for each case.
16.28Design a two-channel crossover FIR low-pass and high-pass filter pair for
digital audio applications. The low-pass and high-pass filters are of length
31 and have a crossover frequency of 2kHz operating at a sampling rate of
44.1KHz. Use the function fir1 with a Hamming window to design the low-
pass filter while the high-pass filter is derived from the low-pass filter using
the delay complementary property. Plot the gain responses of both filters
on the same figure. What is the minimum number of delays and multipliers
needed to implement the crossover network?
16.29Design a digital network butterworth low-pass filter operating at sampling
rate of 44.1kHz with a 0.5dB cutoff frequency at 2kHz and a minimum stop-
band attenuation of 45dB at 10kHz using the impulse invariance method
and the bilinear transformation method. Assume the sampling interval for
the impulse invariance design to be equal to 1. Determine the order of the
analog filter prototype and then design the analog prototype filter. Plot the
gain and phase responses of both designs. Compare the performances of the
filters. Show all steps used in the design. Does the sampling interval have
any effect on the design of the digital filter design based on the impulse
invariance method?
Hint The order of filter is
log10 (1 / k1 )
N=
log10 (1 / k )
and use the function buttap.