Anda di halaman 1dari 81

Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

Table of Contents
1 Experiment No.1: Verification of Sampling Theorem both in time and frequency domains ....................................... 5
1.1 Objective: To verify the sampling theorem for a signal of given frequency ........................................................ 5
1.2 Theory: ................................................................................................................................................................. 5
1.3 ALGORITHM: ..................................................................................................................................................... 6
1.4 MATLAB PROGRAM: ....................................................................................................................................... 7
1.5 RESULT: .............................................................................................................................................................. 9
1.6 EXPECTED WAVEFORM: ................................................................................................................................ 9
1.7 Exercise Problems: ............................................................................................................................................. 10
1.8 CONCLUSION: ................................................................................................................................................. 10
2 Experiment No.2: Evaluation of impulse response of a system ................................................................................. 11
2.1 Objective: ........................................................................................................................................................... 11
2.2 Theory: ............................................................................................................................................................... 11
2.3 Using the command deconv( ) (For Discrete time system): ............................................................................... 11
2.4 By solving the difference/differential equation: ................................................................................................. 12
2.5 ALGORITHM 1: ................................................................................................................................................ 13
2.5.1 MATLAB PROGRAM 1:........................................................................................................................... 13
2.5.2 RESULT: .................................................................................................................................................... 14
2.5.3 EXPECTED WAVEFORM: ...................................................................................................................... 14
2.6 ALGORITHM 2: ................................................................................................................................................ 14
2.6.1 MATLAB PROGRAM 2:........................................................................................................................... 15
2.6.2 RESULT: .................................................................................................................................................... 15
2.6.3 EXPECTED WAVEFORM: ...................................................................................................................... 15
2.7 Algorithm 3: ....................................................................................................................................................... 16
2.7.1 MATLAB PROGRAM 3:........................................................................................................................... 16
2.7.2 RESULT: .................................................................................................................................................... 17
2.7.3 EXPECTED WAVEFORM: ...................................................................................................................... 17
2.8 Exercise Problems: ............................................................................................................................................. 17
2.9 CONCLUSION: ................................................................................................................................................. 17
3 Experiment No.3: To perform linear convolution of given sequences ....................................................................... 18
3.1 Objective: To obtain the convolution of two finite duration sequences ............................................................. 18
3.2 Theory: ............................................................................................................................................................... 18
3.3 ALGORITHM 1: ................................................................................................................................................ 18
3.4 MATLAB PROGRAM 1: .................................................................................................................................. 18
3.5 RESULT: ............................................................................................................................................................ 19
3.6 EXPECTED WAVEFORM: .............................................................................................................................. 19
3.7 ALGORITHM 2: ................................................................................................................................................ 20
3.8 MATLAB PROGRAM 2: .................................................................................................................................. 20
3.9 RESULT: ............................................................................................................................................................ 21
3.10 EXPECTED WAVEFORM: .............................................................................................................................. 21
3.11 ALGORITHM 3: ................................................................................................................................................ 21
3.12 MATLAB PROGRAM 3: .................................................................................................................................. 22
3.13 EXPECTED WAVEFORM: .............................................................................................................................. 23
3.14 Exercise Problems .............................................................................................................................................. 23
3.15 CONCLUSION: ................................................................................................................................................. 23
4 Experiment No.4: To perform circular convolution of given sequences using (a) the convolution summation formula
(b) the matrix method and (c) Linear convolution from circular convolution with zero padding. ..................................... 24
4.1 Objective: To obtain the circular convolution of two finite duration sequences ................................................ 24
4.2 Theory: ............................................................................................................................................................... 24
4.3 Convolution summation formula: ....................................................................................................................... 25
4.3.1 ALGORITHM 1: ........................................................................................................................................ 25
4.3.2 MATLAB PROGRAM 1:........................................................................................................................... 25
4.3.3 RESULT: .................................................................................................................................................... 26

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 1 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

4.3.4 EXPECTED WAVEFORM: ...................................................................................................................... 26


4.4 Circular convolution using matrix method ......................................................................................................... 26
4.4.1 ALGORITHM 2: ........................................................................................................................................ 26
4.4.2 MATLAB PROGRAM 2:........................................................................................................................... 27
4.4.3 RESULT: .................................................................................................................................................... 28
4.4.4 EXPECTED WAVEFORM: ...................................................................................................................... 28
4.5 Linear convolution from circular convolution with zero padding. ..................................................................... 29
4.5.1 ALGORITHM 3: ........................................................................................................................................ 29
4.5.2 MATLAB PROGRAM 3:........................................................................................................................... 29
4.5.3 RESULT: .................................................................................................................................................... 30
Circular Convolution : ................................................................................................................................................ 30
y(m)==> ..................................................................................................................................................................... 30
2 .................................................................................................................................................................................. 30
5 .................................................................................................................................................................................. 30
10 ................................................................................................................................................................................ 30
16 ................................................................................................................................................................................ 30
12 ................................................................................................................................................................................ 30
11 ................................................................................................................................................................................ 30
4.5.4 Expected Waveform: .................................................................................................................................. 30
4.5.5 Exercise Problems ...................................................................................................................................... 31
4.5.6 CONCLUSION: ......................................................................................................................................... 31
5 Experiment No.5: Computation of N – point DFT and to plot the magnitude and phase spectrum. .......................... 32
5.1 Objective: To obtain the Discrete Fourier Transform (DFT) of a given finite duration sequences .................... 32
5.2 Theory: ............................................................................................................................................................... 32
5.3 ALGORITHM: ................................................................................................................................................... 32
5.4 MATLAB PROGRAM: ..................................................................................................................................... 32
5.5 Expected Waveform: .......................................................................................................................................... 33
5.6 Exercise Problems .............................................................................................................................................. 34
5.7 CONCLUSION: ................................................................................................................................................. 34
6 Experiment No.6: Linear and circular convolution by DFT and IDFT method ......................................................... 35
6.1 Objective: To obtain Linear and circular convolution using Discrete Fourier Transform (DFT) of two finite
duration sequences.......................................................................................................................................................... 35
6.2 Theory: ............................................................................................................................................................... 35
6.3 Linear convolution by DFT and IDFT method: .................................................................................................. 36
6.3.1 ALGORITHM 1: ........................................................................................................................................ 36
6.3.2 MATLAB PROGRAM 1:........................................................................................................................... 36
6.3.3 RESULT: .................................................................................................................................................... 37
6.3.4 Expected Waveform: .................................................................................................................................. 37
6.3.5 Exercise Problems ...................................................................................................................................... 38
6.3.6 CONCLUSION: ......................................................................................................................................... 38
6.4 Circular convolution by DFT and IDFT method: ............................................................................................... 38
6.4.1 ALGORITHM 2: ........................................................................................................................................ 38
6.4.2 MATLAB PROGRAM 2:........................................................................................................................... 39
6.4.3 RESULT: .................................................................................................................................................... 41
6.4.4 Expected Waveform: .................................................................................................................................. 41
6.4.5 Exercise Problems ...................................................................................................................................... 42
6.4.6 CONCLUSION: ......................................................................................................................................... 42
7 Experiment No.7: Solution of a given difference equation. ....................................................................................... 43
7.1 Objective: To solve a given difference equation and obtain the output of an LTI system.................................. 43
7.2 Theory: ............................................................................................................................................................... 43
7.3 ALGORITHM 1: ................................................................................................................................................ 44
7.4 MATLAB PROGRAM1: ................................................................................................................................... 44
7.5 RESULT: ............................................................................................................................................................ 45
7.6 Expected Waveform: .......................................................................................................................................... 45
8 Experiment No.8: Calculation of DFT and IDFT by FFT .......................................................................................... 46
8.1 Objective: To DFT & IDFT of a given sequence using FFT method . ............................................................... 46

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 2 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

8.2 Theory: ............................................................................................................................................................... 46


8.3 ALGORITHM: ................................................................................................................................................... 46
8.4 MATLAB PROGRAM: ..................................................................................................................................... 46
8.5 RESULT: ............................................................................................................................................................ 47
8.6 Expected Waveform: .......................................................................................................................................... 48
9 Design and implementation of IIR filters to meet given specification (Low pass, high pass, band pass and band
reject filters) ....................................................................................................................................................................... 50
9.1 Objective: To Design an IIR filter using Butterworth / Chebyshev filter and obtain the magnitude and
frequency response for the given system. ....................................................................................................................... 50
9.2 Theory: ............................................................................................................................................................... 50
9.3 BUTTERWORTH LOWPASS FILTERS: ......................................................................................................... 50
9.4 CHEBYSHEV LOWPASS FILTERS: ............................................................................................................... 51
9.5 Implementation of IIR Butterworth filter ........................................................................................................... 53
9.5.1 ALGORITHM 1: ........................................................................................................................................ 53
9.5.2 MATLAB PROGRAM 1:........................................................................................................................... 53
9.5.3 RESULT: .................................................................................................................................................... 54
9.5.4 Expected Waveform: .................................................................................................................................. 54
9.5.5 Exercise Problems ...................................................................................................................................... 55
9.6 Implementation of IIR Chebyshev filter ............................................................................................................. 55
9.6.1 ALGORITHM 2: ........................................................................................................................................ 55
9.6.2 MATLAB PROGRAM 2:........................................................................................................................... 56
9.6.3 RESULT: .................................................................................................................................................... 57
9.6.4 Expected Waveform: .................................................................................................................................. 57
9.6.5 Exercise Problems ...................................................................................................................................... 58
9.6.6 CONCLUSION: ......................................................................................................................................... 58
10 Design and implementation of FIR filters to meet given specification (Low pass, high pass, band pass and band
reject filters) using different window functions .................................................................................................................. 59
10.1 Objective: To Design an FIR filter using Rectangular/Hamming/Hanning/Blackman/Bartlett window and
obtain the magnitude and frequency response for the given system. .............................................................................. 59
10.2 Theory: ............................................................................................................................................................... 59
10.3 ALGORITHM 1: ................................................................................................................................................ 61
10.4 MATLAB PROGRAM 1: .................................................................................................................................. 61
10.5 RESULT: ............................................................................................................................................................ 62
10.6 Expected Waveform: .......................................................................................................................................... 63
10.7 Exercise Problems .............................................................................................................................................. 64
10.8 CONCLUSION: ................................................................................................................................................. 64
11 Design and implementation of FIR filters to meet given specification (Low pass, high pass, band pass and band
reject filters) using frequency sampling technique. ............................................................................................................ 65
11.1 Objective: To Design an FIR filter for the given specifications and frequency response for the given system
using frequency sampling technique. ............................................................................................................................. 65
11.2 Theory: ............................................................................................................................................................... 65
11.3 ALGORITHM: ................................................................................................................................................... 66
11.4 MATLAB PROGRAM: ..................................................................................................................................... 66
11.5 RESULT: ............................................................................................................................................................ 69
11.6 Exercise Problems .............................................................................................................................................. 70
11.7 Conclusion: ......................................................................................................................................................... 70
12 Realization of IIR and FIR filters ........................................................................................................................... 71
12.1 Objective: To realize IIR and FIR filter for the given specifications.................................................................. 71
12.2 Theory: ............................................................................................................................................................... 71
12.3 IIR FILTER STRUCTURES .............................................................................................................................. 71
12.3.1 Example : CASCADE FORM .................................................................................................................... 72
12.3.2 ALGORITHM: ........................................................................................................................................... 73
12.4 FIR FILTER STRUCTURES ............................................................................................................................. 73
12.4.1 Example: CASCADE FORM ..................................................................................................................... 74
12.4.2 ALGORITHM: (Same as the above Algorithm 12.3.2) .............................................................................. 74
12.5 MATLAB PROGRAM: ..................................................................................................................................... 74

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 3 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

12.6 Result: ................................................................................................................................................................. 76


12.7 Expected Block Diagram: ................................................................................................................................... 76
12.8 EXERCISE PROBLEMS: .................................................................................................................................. 77
12.9 CONCLUSION: ................................................................................................................................................. 77
13 REALIZATION OF A FIR FILTER TO MEET GIVEN SPECIFICATION USING DSP KIT ........................... 78
13.1 Objective: To realize FIR filter to meet given specification using DSP kit ........................................................ 78
13.2 Theory: Refer to Section 10.2 ...................................................................................................................... 78
13.3 CCStudio Procedure: .......................................................................................................................................... 78
13.4 ‘C’ PROGRAM WITH CC STUDIO: ................................................................................................................ 79
13.5 Simulation: ......................................................................................................................................................... 81
13.6 Expected Waveform: .......................................................................................................................................... 81

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 4 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

1 Experiment No.1: Verification of Sampling Theorem both in time and


frequency domains

1.1 Objective: To verify the sampling theorem for a signal of given frequency
1.2 Theory:
 Sampling is a process of converting a continuous time signal x(t) (analog signal) into
discrete time signal x(n) (digital signal) which is represented as a sequence of numbers.
 Sampling theorem generates x(n) from x(t) based on the sampling frequency (fs) which
determines the spacing between each samples.
 Sampling of input signal x(t) can be obtained by multiplying x(t) with an impulse train δ(t)
of period Ts as shown in Fig.1.1., as the sampled signal takes the period of impulse. The
process of sampling can be explained by the following mathematical expression Eq. (1).

Sampled signal y(t) = x(t). δ(t) . . . . . . (1)

Fig. 1.1 Representation of Sampling of signal y(t)


 The trigonometric Fourier seriesrepresentation of δ(t) is given by Eq.(2).

(2)
 Substitute δ(t) in Eq. 1 and obtain Eq. (3).

(3)
 Take Fourier transform on both sides of Eq. (3).

(4)

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 5 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

 To reconstruct x(t) , input signal spectrum X(w) should be recovered from sampled signal
spectrum Y(w) in Eq. (4), which is possible when there is no overlapping between the cycles
of Y(w) as shown in Fig.1.2.
 A continuous time signal can be represented in its samples and can be recovered back when
sampling frequency fs is greater than or equal to the twice the highest frequency component
of message signal given by Eq.(5)
𝒇𝒔 ≥ 𝟐 𝒇𝒎 (5)

Fig.1.2 Sampled signal spectrum


Using the MATLAB command freqz(B,A,N) frequency response for the given system can be
obtained for the N-point complex vector H and the N-point frequency vector W in radians/sample.

1.3 ALGORITHM:
Step 1: For an appropriate analog signal consider the spacing between the samples to be very small,
approximately 0.001sec with time duration of 0.2sec, represented as time base: t=0:0.001:0.2;
Step 2: Obtain the analog signal x(t) based on the frequencies f1 and f2 , i.e.,
x(t)=cos(2*pi*f1*t)+cos(2*pi*f2*t);
Step 3: Select the sampling frequency to be the maximum frequency among f1 and f2 .
Step 4: Illustrate the three conditions: under sampling, Nyquist rate sampling and over sampling for
a discrete time vector n=0:1/fs:0.2;
Step 5: To generate sampled signals, consider:
Case (i) Under sampling with fs=fm;
Case (ii) Nyquist rate sampling with fs=2*fm; and
Case (iii) Over sampling with fs=20*fm;

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 6 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

Step 5: Plot the reconstructed signals for the respective sampling frequencies in discrete time
domain ‘n’: x1=cos(2*pi*f1*n)+cos(2*pi*f2*n).
Step 6: The frequency domain sampling can be obtained using the command freqz( ) to observe the
reconstructed signal in frequency domain.
1.4 MATLAB PROGRAM:

%Verification of Sampling Theorem

clc; clear all; close all;


t=0:0.001:0.2;
f1=input('Enter the frequency-1 in Hz: ');
f2=input('Enter the frequency-2 in Hz: ');
x=cos(2*pi*f1*t)+cos(2*pi*f2*t);
fm=max(f1,f2);
% analog signal sampled at fs<<2fm (under sampling)
fs=fm;
n=0:1/fs:0.2;
x1=cos(2*pi*f1*n)+cos(2*pi*f2*n);
figure(1);
subplot(3,3,1);
plot(t,x,'r');
xlabel('----');
ylabel('amplitude');
title('input signal');

subplot(3,3,2);
stem(n,x1);
xlabel('---->n');
ylabel('amplitude');
title('under sampled signal');

subplot(3,3,3);
plot(n,x1);
xlabel('---->n');
ylabel('amplitude');
title('reconstructed signal');

% analog signal sampled at fs=2fm (Nyquist rate)

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 7 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

fs=2*fm;
n=0:1/fs:0.2;
x2=cos(2*pi*f1*n)+cos(2*pi*f2*n);
subplot(3,3,4);
plot(t,x,'r');
xlabel('---->t');
ylabel('amplitude');
title('input signal');

subplot(3,3,5);
stem(n,x2);
xlabel('---->n');
ylabel('amplitude');
title('sampled at Nyquist rate');

subplot(3,3,6);
plot(n,x2);
xlabel('---->n');
ylabel('amplitude');
title('reconstructed signal');

% analog signal sampled at fs>>2fm(over sampling)


fs=20*fm;
n=0:1/fs:0.2;
x3=cos(2*pi*f1*n)+cos(2*pi*f2*n);
subplot(3,3,7);
plot(t,x,'r');
xlabel('---->t');
ylabel('amplitude');
title('input signal');
subplot(3,3,8);
stem(n,x3);
xlabel('---->n');
ylabel('amplitude');
title(' oversampled signal');
subplot(3,3,9);
plot(n,x3);
xlabel('---->n');

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 8 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

ylabel('amplitude');
title('reconstructed signal');
%For Frequency Domain Sampling
figure(2)%To perform
subplot(3,1,1)
[m,w]=freqz(x1,1,128);
plot(fs1*w/(2*pi), abs(m));
title('spectrum of undersampled signal');
subplot(3,1,2);
[m,w]=freqz(x2,1,128);
plot(fs2*w/(2*pi), abs(m));
title('spectrum of Nyquist sampled signal');
subplot(3,1,3);
[m,w]=freqz(x3,1,128);
plot(fs3*w/(2*pi), abs(m));
title('spectrum of over sampled signal');

1.5 RESULT:

Enter the frequency-1 in Hz: 10


Enter the frequency-2 in Hz: 20

1.6 EXPECTED WAVEFORM:


The sampled signals for sampling frequencies fs1=fm, fs2=2*fm & fs3=20*fm, is as shown in Fig.
1.3. Similarly sampling theorem implemented in frequency domain is as shown in Fig. 1.4.
input signal under sampled signal reconstructed signal
2 2 2

1 1.5 1.5
amplitude

amplitude

amplitude

0 1 1

-1 0.5 0.5

-2 0 0
0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2
---->t ---->n ---->n
input signal sampled at Nyquist rate reconstructed signal
2 2 2

1
1 1
amplitude

amplitude

amplitude

0
0 0
-1

-2 -1 -1
0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2
---->t ---->n ---->n
input signal oversampled signal reconstructed signal
2 2 2

1 1 1
amplitude

amplitude

amplitude

0 0 0

-1 -1 -1

-2 -2 -2
0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2 0 0.05 0.1 0.15 0.2
---->t ---->n ---->n

Fig. 1.3 Input signal, Sampled signal and reconstructed signal for three sampling frequencies.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 9 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

spectrum of undersampled signal


10

0
0 1 2 3 4 5 6 7 8 9 10
spectrum of Nyquist sampled signal
10

0
0 2 4 6 8 10 12 14 16 18 20
spectrum of over sampled signal
50

0
0 20 40 60 80 100 120 140 160 180 200

Fig. 1.4 Reconstructed signal for three sampling frequencies in Frequency Domain

1.7 Exercise Problems:


1) Observe the Nyquist sampling for: fs1=1.2*fm; fs2=2*fm;fs3=8*fm;
2) Observe the Nyquist sampling for: f1 = 100Hz, f2 = 200Hz and f3=1000Hz

1.8 CONCLUSION:
The analog signals should be sampled at frequencies greater than the sampling frequency based on
Nyquist rate to obtain a perfect smooth reconstructed signal.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 10 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

2 Experiment No.2: Evaluation of impulse response of a system

2.1 Objective:

To obtain the Impulse response h(n) for a given LTI system

2.2 Theory:

A linear system with input, x(t), and output, y(t), can be described in terms of its impulse response,
h(t) as shown in Fig 2.1, where Impulse Response of the system is the output signal of the system when
the input signal is an impulse function applied at time t = 0.

Fig. 2.1 LTI System


Using the convolution method, we can find the output to a corresponding input by evaluating the
convolution integral for continuous time system as given by Eq.(6):

𝑦(𝑡) = 𝑥(𝑡) ∗ ℎ(𝑡) = ∫−∞ 𝑥(𝜏) ∙ ℎ(𝑡 − 𝜏)𝑑𝜏 (6)
OR
Convolution sum for discrete time system is given as Eq.(7):
𝑦(𝑛) = 𝑥(𝑛) ∗ ℎ(𝑛) = ∑∞ 𝑛=−∞ 𝑥(𝑘) ∙ ℎ(𝑛 − 𝑘) (7)
There are two methods for evaluating the convolution integral and finding the impulse response
using MATLAB.

2.3 Using the command deconv( ) (For Discrete time system):

The practical significance of Fourier deconvolution in signal processing is that it can be used as a
computational way to reverse the result of a convolution occurring in the physical domain .
Deconvolution is usually performed by computing the Fourier Transform of the recorded
signal x(n) and the transfer function y(n), apply deconvolution in the Frequency domain, which in
the case of absence of noise is merely H(Ω)=Y(Ω)/X(Ω) where F, G, and H being the Fourier
Transforms of f(n), y(n), and h(n) respectively.

The command deconv(u,v:) deconvolves a vector v out of a vector u using long division, and returns
the quotient q and remainder r such that u = conv(v,q)+r. If u and v are vectors of polynomial
coefficients, then deconvolving them is equivalent to dividing the polynomial represented by u by
the polynomial represented by v.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 11 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

2.4 By solving the difference/differential equation:

An LTI discrete system can also be described by a linear constant coefficient difference equation of
the form shown in Eq. 8, or linear constant coefficient differential equation represented as given by
Eq. 9. This equation describes a recursive approach for computing the current output y(n), given the
input values x(n) and previously computed output values y(n-k).

∑N M
k=o a k y(n − k) = ∑k=0 bk x(n − k) (8)

𝑑𝑦(𝑡) 𝑑𝑥(𝑡)
∑N
k=o a k = ∑M
k=0 bk (9)
𝑑𝑡 𝑑𝑡

The impulse response for any system described by a differential equation can be represented using
the impulse command in MATLAB, i.e., idtf(), lsim( ), impulse()and impz().

The command idtf(): Constructs or converts to a transfer function with identifiable parameters.
Construction of SYS = idtf(NUM,DEN) creates a continuous-time transfer function SYS with
numerator NUM and denominator DEN. The parameter SYS consists of numerator and denominator
coefficients.

The command lsim(SYS,U,T) plots the time response of the dynamic system SYS to the input signal
described by U and T. The time vector T is expressed in the time units of SYS and consists of
regularly spaced time samples. The matrix U has as many columns as inputs in SYS and its ith row
specifies the input value at time T(i). For example,

t = 0:0.01:5; u = sin(t); lsim(sys,u,t)

Simulates the response of a single-input model SYS to the input u(t)=sin(t) during 5 time units.

The command impulse(SYS) : plots the impulse response of the dynamic system SYS. For systems
with more than one input, independent impulse commands are applied to each input channel uses the
time vector T for simulation (expressed in the time units of SYS).

For discrete-time models, T should be of the form Ti:Ts:Tf where Ts is the sampling time. For
continuous-time models, T should be of the form Ti:dt:Tf where dt is the sampling period for the
discrete approximation of SYS. The impulse is always assumed to arise at t=0 (regardless of Ti).

h = impulse(b, a, t)
Where b and a, are the vectors containing the ak and bj coefficients of the differential
equation, and t is the time over which the impulse response is to be found.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 12 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

The command impz(B,A,N)computes the impulse response of an LTI system, where the numerator
and denominator coefficients are vectors B and A,for N samples of the impulse response.

2.5 ALGORITHM 1:
Step (1) Obtain the input and output sequences.
Step (2) Use the command deconv() to obtain the impulse response of the given system
Step (3) Plot the impulse response h(n) for the obtained length N
Step (4) Verify the correctness of impulse response using the command conv( ), i.e., the output y1(n)
obtained using conv( ) should be same as the original Output sequence y(n).

2.5.1 MATLAB PROGRAM 1:

%Impulse response of a given system, using the MATLAB command deconv()for a


discrete system
x=input('The input sequence of the given system is x(n)=')
y=input('The output sequence of the given system is y(n)=')
h=deconv(y,x);
disp('The Impulse Response of the system is=')
disp(h);

% Graphical display of Impulse Response


N=length(h);
n=0:1:N-1;
stem(n,h);
xlabel('Time Index (n)');
ylabel('Impulse Response of the system h(n)');

%Verification of Impulse Response


y1=conv(x,h);
disp('The output sequence of the system is y1(n)');
disp(y1)
disp('This output y1(n) is same as that of given output y(n)');

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 13 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

2.5.2 RESULT:

COMMAND WINDOW:
>> impulse1
The input sequence of the given system is x(n)=[1,1,1,1]
x=
1 1 1 1
The output sequence of the given system is y(n)=[1,1,1,1]
y=
1 1 1 1
The impulse response of the system is=
1
The output sequence of the system is y1(n)
1 1 1 1
This output y1(n) is same as that of given output y(n)

2.5.3 EXPECTED WAVEFORM:


1

0.9
Impulse Response of the system h(n)

0.8

0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
Time Index (n)

2.6 ALGORITHM 2:

Step (1) Obtain the numerator and denominator coefficients as num and den respectively.
Step (2) Use the command idtf() to create the transfer function ‘G’ of the given continuous time
system with num and den.
Step (3) Select a suitable time frame ‘t’ in order to display the plot for impulse response.
Step (4) Use the command lsim(G,u,t), to plot the time response of the dynamic system ‘G’ to the
input signal described by u and t
Step (5) Plot the response y for the mentioned time frame.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 14 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

2.6.1 MATLAB PROGRAM 2:

% Evaluation of impulse response of a system for Continuous Time system, using


the MATLAB command lsim()
num = [1 4];
den = [1 20 5];
G = idtf(num,den);%creates a continuous-time transfer function ‘G’ with
numerator NUM and denominator DEN.
% evaluate response
t = 0:0.01:5;
u = sin(t);
y = lsim(G,u,t);%plots the time response of the dynamic system G to the
%input signal described by u and t.
% plot
figure;
plot(t,y)

2.6.2 RESULT:

COMMAND WINDOW:
G=

s+4
--------------
s^2 + 20 s + 5

2.6.3 EXPECTED WAVEFORM:


The impulse response obtained using lsim( ) command is as shown in Fig.2.3.

0.3

0.25

0.2

0.15

0.1

0.05

-0.05

-0.1
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

Fig. 2.3 Impulse response using lsim( )

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 15 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

2.7 Algorithm 3:

Step (1) Select an appropriate length ‘N’ for the impulse response.
Step (2) Obtain the numerator and denominator coefficients as ‘a’ and ‘b’ respectively
Step (3) Use the command impz() to obtain the impulse response of the given system.
Step (4) Plot the impulse response h(n) for the length N.

2.7.1 MATLAB PROGRAM 3:


%TO FIND THE IMPULSE RESPONSE OF A DISCRETE TIME SYSTEM, FOR THE GIVEN
DIFFERENCE EQUATION using MATLAB command impz( )
clc;
clear;
N=input('Length of impulse response required=')
b=[1];%Numerator coefficients
a=[1,-1,0.9];%Denominator coefficients
h=impz(b,a,N);
%Plot the impulse response sequence
n=0:N-1;
stem(n,h);
title('Impulse response');
xlabel('n');
ylabel('h(n)');
sum(h)

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 16 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

2.7.2 RESULT:

COMMAND WINDOW:
Length of impulse response required=100

N = 100

2.7.3 EXPECTED WAVEFORM:

The impulse response obtained using impz( ) command is as shown in Fig.2.4.


Impulse response
1

0.8

0.6

0.4

0.2
h(n)

-0.2

-0.4

-0.6

-0.8

-1
0 10 20 30 40 50 60 70 80 90 100
n

Fig. 2.4 Impulse response using impz( )

2.8 Exercise Problems:


1. Obtain the impulse response for a LTI system described by the difference equation:
y(n)=x(n)+0.4 x(n-1).
2. Obtain the impulse response for a LTI system described by differential equation:
𝑑𝑥(𝑡) 𝑑2 𝑥(𝑡)
𝑦(𝑡) = 𝑥(𝑡) + 5 +6 using the MATLAB command impulse().
𝑑𝑡 𝑑𝑡 2

2.9 CONCLUSION:
 A given system is stable if the impulse response is absolutely summable, i.e. if
∑∞
𝑘=−∞|ℎ(𝑘)| < ∞

 The process of deconvolution is valid only if the LTI system is invertible.


 Impulse response can be computed either for finite or infinite duration sequences.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 17 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

3 Experiment No.3: To perform linear convolution of given sequences


3.1 Objective: To obtain the convolution of two finite duration sequences
3.2 Theory:
A linear time invariant (LTI) system with input x(t), and output y(t), can be described in terms of its
impulse response h(t) as shown in Fig. 3.1

Fig. 3.1 LTI system


Using the convolution method, we can find the output to a corresponding input by evaluating the
convolution integral of continuous time system given by Eq. (6).

𝑦(𝑡) = 𝑥(𝑡) ∗ ℎ(𝑡) = ∫−∞ 𝑥(𝜏) ∙ ℎ(𝑡 − 𝜏)𝑑𝜏 (6)
OR
Convolution sum for discrete time system is given as Eq.(7):
𝑦(𝑛) = 𝑥(𝑛) ∗ ℎ(𝑛) = ∑∞ 𝑛=−∞ 𝑥(𝑘) ∙ ℎ(𝑛 − 𝑘) (7)

Convolution of two signals can be obtained using the MATLAB command conv(A, B) convolves
vectors A and B. The resulting vector is of length:

length MAX([LENGTH(A)+LENGTH(B)-1,LENGTH(A),LENGTH(B)]).

If A and B are vectors of polynomial coefficients, convolving them is equivalent to multiplying the
two polynomials.

3.3 ALGORITHM 1:
Step (1) Initialize the two discrete time sequences as x(n) and h(n).
Step (2) Identify the start and end point of both the sequences.
Step (3) Set the start and end point for the resultant sequence y(n)
Step (4) Perform convolution of x(n) and h(n) using the MATLAB command conv( )
Step (5) Plot the input sequence x(n), impulse sequence h(n) and the output sequence y(n).

3.4 MATLAB PROGRAM 1:


% To perform linear convolution using the MATLAB command conv()
clc;
clearall;
closeall;
x=[1,2,3,1];

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 18 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

h=[1,2,1,-1];
nx=[0:3];
nh=[-1:2];
ystart=nx(1)+nh(1);
yend=nx(length(x))+nh(length(h));
ny=[nyb:nye]
y=conv(x,h)
disp(y);
subplot(1,3,1);
stem(nx,x);
xlabel('---->n');
ylabel('Amplitude');
title('First input: x[n]');
subplot(1,3,2);
stem(nh,h);
xlabel('---->n');
ylabel('Amplitude');
title('Second input: h[n]');
subplot(1,3,3);
stem(ny,y);
xlabel('---->n');
ylabel('Amplitude');
title('Linear Convolution Output: y[n]');

3.5 RESULT:
COMMAND WINDOW:

Enter the first sequence: [2 1 2 1]


Enter the second sequence: [1 2 3 4]
Enter the range of the first sequence: 0:3
Enter the range of the second sequence: 0:3
2 5 10 16 12 11 4

3.6 EXPECTED WAVEFORM:


The input sequence x(n), impulse sequence h(n) and the output sequence y(n) using the MATLAB
command conv() is as shown in Fig.3.2

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 19 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

First input: x[n] Second input: h[n] Linear Convolution Output: y[n]
2 4 16

1.8
3.5 14
1.6
3 12
1.4

2.5 10
1.2

Amplitude

Amplitude

Amplitude
1 2 8

0.8
1.5 6

0.6
1 4
0.4

0.5 2
0.2

0 0 0
0 2 4 0 2 4 0 5 10
---->n ---->n ---->n

Fig. 3.2Input sequence x(n), Impulse sequence h(n) and Output sequence y(n)

3.7 ALGORITHM 2:
Step (1) Initialize the two discrete time sequences as x(n) and h(n).
Step (2) Identify the start point, end point and length of both the sequences.
Step (3) Set the length for the resultant sequence y(n)
Step (4) Perform convolution of x(n) and h(n) using ‘for’ loop with the convolution sum formula
mentioned in Eq. (7).
Step (5) Plot the input sequence x(n), impulse sequence h(n) and the output sequence y(n).

3.8 MATLAB PROGRAM 2:


% To perform linear convolution using convolution summation formula
clc;
clear all;
close all;
x=input('Enter the first sequence: ');
h=input('Enter the second sequence: ');
n1=input('Enter the range of the first sequence: ');
n2=input('Enter the range of the second sequence: ');
L=length(x);
M=length(h);
N=L+M-1;%length of output sequence y(n)
for n=1:1:N
y(n)=0;
for k=1:1:L
if n-k>=0 && n-k<M
y(n)=y(n)+x(k)*h(n-k+1);%Convolution Sum formula
end
end
end
disp(y);
subplot(1,3,1);
stem(n1,x);
xlabel('---->n');
ylabel('Amplitude');
title('First input: x[n]');
subplot(1,3,2);

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 20 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

stem(n2,h);
xlabel('---->n');
ylabel('Amplitude');

title('Second input: h[n]');


n3=n1(1)+n2(1):n1(end)+n2(end);
subplot(1,3,3);
stem(n3,y);
xlabel('---->n');
ylabel('Amplitude');
title('Linear Convolution Output: y[n]');

3.9 RESULT:
COMMAND WINDOW:
Enter the first sequence: [1 2]
Enter the second sequence: [1 2 4]
Enter the range of the first sequence: [0:1]
Enter the range of the second sequence: [0:2]
1 4 8 8
3.10 EXPECTED WAVEFORM:
The input sequence x(n), impulse sequence h(n) and the output sequence y(n) using the convolution
sum is as shown in Fig.3.3

First input: x[n] Second input: h[n] Linear Convolution Output: y[n]
2 4 8

1.8
3.5 7
1.6
3 6
1.4

2.5 5
1.2
Amplitude

Amplitude

Amplitude

1 2 4

0.8
1.5 3

0.6
1 2
0.4

0.5 1
0.2

0 0 0
0 0.5 1 0 1 2 0 2 4
---->n ---->n ---->n

Fig. 3.3Input sequence x(n), Impulse sequence h(n) and Output sequence y(n)

3.11 ALGORITHM 3:
Step (1) Define the continuous time input signal x(t) and impulse signal h(t).
Step (2) Express x(t) and h(t) in the form of step function using the MATLAB command
‘heaviside ()’ for the mentioned time range.
Step (3) Plot the signals x(t) and h(t) within the time range.
Step (4) Perform convolution of x(n) and h(n) using MATLAB command conv( ).
Step (5) Plot the output sequence y(n) for the mentioned time range.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 21 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

3.12 MATLAB PROGRAM 3:

% To perform linear convolution using the MATLAB command conv()for continuous


1 t≥0 e−t t≥0
%time signals x(t) = { and h(t) = {
0 t≤0 0 t≤0
%Define initial signals
% Convolution of Continuous time signals
clc;
clear all;
close all;
%Define initial signals
Ts = 0.01;
t_x = -5:Ts:5;
x = heaviside(t_x);
t_h = -5:Ts:5;
h = heaviside(t_h).*(exp(-(t_h)));
%Plot initial signals
figure(1)
plot(t_x,x);
xlabel('t');
ylabel('x(t)');
title('Input signal x(t)')
axis([min(t_x)-1 max(t_x)+1 min(x)-1 max(x)+1]);
figure(2)
plot(t_h,h);
xlabel('t');
ylabel('h(t)');
axis([min(t_h)-1 max(t_h)+1 min(h)-1 max(h)+1]);
title('Impulse Response h(t)')
%Convolution
y = Ts*conv(x,h);
t_y = min(t_x)+min(t_h):Ts:max(t_x)+max(t_h);
figure(3)
plot(t_y,y);
xlabel('t');
ylabel('y(t)');
axis([min(t_y)-1 max(t_y)+1 min(y)-1 max(y)+1]);
title('Output signal y(t)')

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 22 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

3.13 EXPECTED WAVEFORM:


The Input signal x(t), Impulse signal h(t) and Output signal y(t) using the convolution integration
MATLAB command conv( ) is as shown in Fig.3.4.

Input signal x(n) Impulse Response h(n) Output signal y(n)


2

2
1.5 1.5

1.5
1 1

1
x(t)

0.5

y(t)

z(t)
0.5
0.5

0
0
0

-0.5
-0.5
-0.5

-1
-6 -4 -2 0 2 4 6 -1 -1
t -6 -4 -2 0 2 4 6 -10 -8 -6 -4 -2 0 2 4 6 8 10
t t

Fig. 3.4 Input signal x(t), Impulse signal h(t) and Output signal y(t)

3.14 Exercise Problems


(1) x (n) =[2 1 2 -1] and h(n) = [1 2 3 4]
1 𝑡≥0 −𝑡
and ℎ(𝑡) = {𝑡𝑒 𝑡≥0
(2) 𝑥(𝑡) = {
0 𝑡≤0 0 𝑡≤0
3.15 CONCLUSION:
 From the process of convolution, the property of linearity and time invariance can be verified
effectively.
 The typical variation of output for different types of impulse responses can be analyzed.
 Convolution can be verified both graphically as well as mathematically

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 23 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

4 Experiment No.4: To perform circular convolution of given sequences using


(a) the convolution summation formula (b) the matrix method and (c) Linear
convolution from circular convolution with zero padding.

4.1 Objective: To obtain the circular convolution of two finite duration sequences
4.2 Theory:
Circular convolution is “the fundamental operation to compute discrete time signals”. Consider two
finite sequence discrete time signals with length N are x1[n] & x2[n], the Linear convolution of
periodic signals is represented by Eq. (10).
𝑦(𝑛) = 𝑥1 (𝑛) ∗ 𝑥2 (𝑛) = ∑∞
𝑛=−∞ 𝑥1 (𝑘) ∙ 𝑥2 (𝑛 − 𝑘) (10)
The circular convolution of x1(n) and x2(n) is represented in Eq.(11), where the shifting in this
operation is circular shifting for the given sequence of length N.
𝑦(𝑛) = 𝑥1 (𝑛) ⊛ 𝑥2 (𝑛) = ∑∞
𝑛=−∞ 𝑥1 (𝑘) ∙ 𝑥2 (𝑛 − 𝑘)𝑁 (11)

The Discrete Fourier Transformation (DFT) of signals x1(n) and x2(n) are represented as X1(k)
& X2(k) respectively. According to convolution property (time domain) of DFT, the convolution of
signals x1(n) and x2(n) is the product of signals their DFT signals given as Eq.(12).

(12)
If x1(n) contains L number of samples and x2(n) contains M number of samples, for L>M, the
circular convolution is performed using N=Max(L,M), by adding L-M number of zero samples to the
sequencex2(n) so that both the sequences are periodic with N.
The difference between circular an linear convolution is, in circular convolution the folding and
shifting operation of sequences is performed circularly by computing the index of one of the
sequence using modulus operation mod(N), while for linear convolution these is no modulus
operation
Circular convolution of two finite duration discrete time sequences can be found using: (a) the
convolution summation formula (b) the matrix method and (c) Linear convolution from circular
convolution with zero padding.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 24 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

4.3 Convolution summation formula:


4.3.1 ALGORITHM 1:
Step (1) Initialize the two discrete time sequences as x(n) and h(n).
Step (2) Identify the length of both the sequences.
Step (3) Set the length for the resultant sequence y(n)
Step (4) Perform convolution of x(n) and h(n) using ‘for’ loop with the circular convolution sum
formula mentioned in Eq. (9).
Step (5) Plot the input sequence x(n), impulse sequence h(n) and the output sequence y(n).

4.3.2 MATLAB PROGRAM 1:


%Circular Convolution using convolution sum equation
clc;
closeall;
clearall;
x=input('enter the first sequence');
h=input('enter the second sequence');
N1=length(x);
N2=length(h);
N=max(N1,N2);
% compute output y(n)
for n=0:N-1
y(n+1)=0;
for k=0:N-1
i=mod((n-k),N);% Calculation of x index
ifi<0
i=i+N;
end
y(n+1)=y(n+1)+h(k+1)*x(i+1);
end
end
disp('Circular convolution of x(n) and h(n)is y(n)=')
disp(y);
Ny=0:N-1;
subplot(3,1,1); stem(Ny,x); xlabel('---->n'); ylabel('Amplitude');
title('First input Signal x[n]');
subplot(3,1,2); stem(Ny,h); xlabel('---->n'); ylabel('Amplitude');
title('Second input Signal h[n]');

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 25 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

subplot(3,1,3); stem(Ny,y); xlabel('---->n'); ylabel('Amplitude');


title('Circular convolution y[n]');

4.3.3 RESULT:
COMMAND WINDOW:
Enter the first sequence[2 1 2 1]
Enter the second sequence[1 2 3 4]
Circular convolution of x(n) and h(n)is y(n)=
14 16 14 16
4.3.4 EXPECTED WAVEFORM:
The Input signalx(t), Impulse signal h(t) and Output signal y(t) using the circular convolution sum
formula is as shown in Fig.4.1.
First input Signal x[n]
2
Amplitude

0
0 0.5 1 1.5 2 2.5 3
---->n
Second input Signal h[n]
4
Amplitude

0
0 0.5 1 1.5 2 2.5 3
---->n
Circular convolution y[n]
20
Amplitude

10

0
0 0.5 1 1.5 2 2.5 3
---->n
Fig. 4.1Circular Convolution using convolution summation formula

4.4 Circular convolution using matrix method

4.4.1 ALGORITHM 2:
Step (1) Initialize the two discrete time sequences as x(n) and h(n).
Step (2) Identify the length of both the sequences.
Step (3) Set the length for the resultant sequence y(n)
Step (4)Append zeros to either of the sequences such that both the sequences are of length N.
Step (4) Perform convolution of x(n) and h(n) using ‘for’ loop with the circular convolution sum
formula mentioned in Eq. (9).
Step (5) Plot the input sequence x(n), impulse sequence h(n) and the output sequence y(n).

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 26 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

4.4.2 MATLAB PROGRAM 2:


%Cicular Convolution using Matrix Method

clc;
close all;
clear all;
x1=input('enter the 1st sequence x(n)=')
h1=input('enter the 1st sequence h(n)=')
N1=length(x1)
N2=length(h1)
N=max(N1,N2)
if(N1>N2);
h1=[h1,zeros(1,N-N2)]
else
x1=[x1,zeros(1,N2-N1)]
end;
x=transpose(x1);
h=transpose(h1);
temp=h;
for i=1:N-1;
temp=circshift(temp,1);
h=horzcat(h,temp);
end;
h
x
y=h*x

% To display and plot circular convolution


subplot(3,1,1);
stem(x1);
xlabel('N-->')
ylabel('Amplitude-->')
title('1st input sequence x[n]');

subplot(3,1,2);
stem(h1);
xlabel('N-->')
ylabel('Amplitude-->')

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 27 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

title('2nd input sequence x[n]');

subplot(3,1,3);
stem(y);
xlabel('N-->')
ylabel('Amplitude-->')
title('Circular convolved output y[n]');

4.4.3 RESULT:
COMMAND WINDOW:

4.4.4 EXPECTED WAVEFORM:


The Input signal x(t), Impulse signal h(t) and Output signal y(t) using the circular convolution
Matrix method is as shown in Fig.4.2.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 28 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

Input Signal: x(n)


2

0
1 1.5 2 2.5 3 3.5 4
Impulse Response: h(n)
4

0
1 1.5 2 2.5 3 3.5 4
Circular Convolution using MATRIX METHOD
20

10

0
1 1.5 2 2.5 3 3.5 4
Fig. 4.2 Circular Convolution using Matrix Method

4.5 Linear convolution from circular convolution with zero padding.


4.5.1 ALGORITHM 3:
Step (1) Initialize the two discrete time sequences as x(n) and h(n).
Step (2) Identify the length of both the sequences.
Step (3) Set the length for the resultant sequence y(n)
Step (4)Append zeros to both the sequences such that both the sequences are of same length.
Step (5) Perform convolution of x(n) and h(n) using ‘for’ loop with the convolution sum formula
mentioned in Eq. (8).
Step (6) Plot the input sequence x(n), impulse sequence h(n) and the output sequence y(n).

4.5.2 MATLAB PROGRAM 3:


% Linear Convolution via Circular Convolution
g1 = [2 1 2 1];
g2 = [1 2 3 4];
n1=length(g1);
n2=length(g2);
g1e = [g1 zeros(1,n2-1)];
g2e = [g2 zeros(1,n1-1)];
N1=length(g1e);
N2=length(g2e);
N=n1+n2-1;
for n=0:N-1

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 29 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

y(n+1)=0;
for k=0:N-1
i=mod((n-k),N);% Calculation of x index
if i<0
i=i+N;
end
y(n+1)=y(n+1)+g2e(k+1)*g1e(i+1);
end
end

disp('Circular Convolution : y(m)==>');


disp(y);

4.5.3 RESULT:
Circular Convolution :
y(m)==>
2
5
10
16
12
11
4.5.4 Expected Waveform:
The Input signalx(t), Impulse signal h(t) and Output signal y(t) using Linear convolution from
circular convolution with zero padding is as shown in Fig.4.3.
First input: x[n] Second input: h[n] Linear Convolution Output: y[n]
1 3 6

0.9
2.5 5
0.8

0.7
2 4
0.6
Amplitude

Amplitude

Amplitude

0.5 1.5 3

0.4
1 2
0.3

0.2
0.5 1
0.1

0 0 0
0 1 2 0 2 4 0 5
---->n ---->n ---->n

Fig. 4.3 Linear convolution from circular convolution with zero padding

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 30 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

4.5.5 Exercise Problems


(1) Perform the circular convolution of x (n) =[2 1 2 -1] and h(n) = [1 2 3 4].
(2) The input x(n) and impulse response h(n) of a LTI system is given as x(n) = [-1 1 2 -2] and
h(n)= [0.5 1 -1 2 0.75] respectively. Obtain the response if the system using (i) Linear
convolution, (ii) Circular convolution.
4.5.6 CONCLUSION:
 From the process of circular convolution, the property of circular time shifting can be
verified.

 If two discrete-time sequences of length N1 and N2, respectively, are zero-padded to


length N, such that N≥N1+N2−1, then the circular convolution of the sequences is
equal to the linear convolution of the sequences

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 31 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

5 Experiment No.5: Computation of N – point DFT and to plot the magnitude


and phase spectrum.

5.1 Objective: To obtain the Discrete Fourier Transform (DFT) of a given finite duration
sequences

5.2 Theory:
The Discrete Time Fourier Transform (DTFT) of a signal x(n) is given by Eq.13.
𝑋(𝜔) = ∑∞
𝑛=−∞ 𝑥(𝑛)𝑒
−𝑗𝜔𝑛
(13)
DTFT is a continuous function of frequency hence frequency analysis of digital systems cannot be
performed using DTFT, since, frequency domain signals are expected to be discrete in nature. Such
signals are discretized by sampling in one period and the resulting frequency domain signal is called
as Discrete Fourier Transform (DFT). These discrete time signal are of finite length L≤ N, the
number of frequency samples considered.

The N-pt DFT , X(k), of an N-pt sequence x(n), is now given by Eq.14.
−𝑗2𝜋𝑘𝑛
𝑋(𝑘) = ∑𝑁−1
𝑛=0 𝑥(𝑛)𝑒 𝑁 for 0 ≤ k ≤N-1 (14)
−𝑗2𝜋
Replacing 𝑒 𝑁 by WN , referred as phase factor or twiddle factor given by Eq.15.
𝑛𝑘
𝑋(𝑘) = ∑𝑁−1
𝑛=0 𝑥(𝑛)𝑊𝑁 for 0 ≤ k ≤N-1 (15)
WN satisfies property of periodicity and property of symmetry
𝑟+𝑁 𝑟+𝑁/2
𝑊𝑁 = 𝑊𝑁𝑟 ( periodicity) and 𝑊𝑁 = −𝑊𝑁𝑟 (symmetry)

5.3 ALGORITHM:
Step (1) Initialize the discrete time sequence as x(n).
Step (2) Identify the length of the sequence as N.
Step (3) Initialize the resultant DFT sequenceX(k) with zeros based on the length N.
Step (4)Perform DFT of the sequence x(n) using the Eq. (11).
Step (5)Plot the input sequence x(n) and the magnitude & phase angle for resultant sequence X(k).
5.4 MATLAB PROGRAM:
%N-point DFT of x(n)
x = [2 3 -1 4];
N = length(x);

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 32 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

X = zeros(4,1)
for k = 0:N-1
for n = 0:N-1
X(k+1) = X(k+1) + x(n+1)*exp(-j*pi/2*n*k)
magX=abs(X(k+1))
angX=angle(X(k+1))
end
end
t = 0:N-1
subplot(311)
stem(t,x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Time domain - Input sequence')
subplot(312)
stem(t,X)
xlabel('Frequency');
ylabel('|X(k)|');
title('Frequency domain - Magnitude response')
subplot(313)
stem(t,angle(X))
xlabel('Frequency');
ylabel('angle(X(k))');
title('Frequency domain - Magnitude response')

5.5 Expected Waveform:


The Input signal x(t) and resultant signal X(k) using DFT is as shown in Fig.5.1.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 33 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

Time domain - Input sequence


5

Amplitude
0

-5
0 0.5 1 1.5 2 2.5 3
Time (s)
6
x 10 Frequency domain - Magnitude response
10

|X(k)|
5

0
0 0.5 1 1.5 2 2.5 3
Frequency
Frequency domain - Magnitude response
1
angle(X(k))

-1
0 0.5 1 1.5 2 2.5 3
Frequency

Fig. 5.1DFT of a sequence x(n)


5.6 Exercise Problems
(1)Obtain the 8-point DFT of x (n) =[0 1 2 1].
(2) Obtain the 4-point DFT of x(n)=[1/3 1/3 1/3] .

5.7 CONCLUSION:
 The N-point DFT for a finite duration sequence x(n) of length L should be such that N>=L
 The N point DFT of x(n) should satisfy periodicity and symmetry properties.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 34 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

6 Experiment No.6: Linear and circular convolution by DFT and IDFT method
6.1 Objective: To obtain Linear and circular convolution using Discrete Fourier Transform
(DFT) of two finite duration sequences

6.2 Theory:
Discrete Fourier Transform (DFT) provides the frequency-domain (ω) representation for absolutely
summable time domain sequence x(n). The DFT of x(n) is expressed as X(k) as given by Eq. (16).
𝑗2𝜋𝑘

𝑋(𝑘) = ∑𝑁−1
𝑛=0 𝑥(𝑛) 𝑒 𝑁 (16)

DFT of a signal can be obtained by sampling the DTFT of the signal at N uniform sampling points.
Hence it is also referred to as N-point DFT. The value of N for a finite duration sequence x(n) of
length L should be such that N>=L in order to avoid aliasing of frequency response.

The Inverse DFT of X(k) gives back the time domain sequence given by Eq.17.
𝒋𝟐𝝅𝒌𝒏
𝟏 𝟏
𝒙(𝒏) = ∑𝑵−𝟏
𝒌=𝟎 𝑿(𝒌)𝒆
𝑵 = ∑𝑵−𝟏 −𝒌𝒏
𝒌=𝟎 𝑿(𝒌)𝑾𝑵 0 ≤ n ≤ N-1 (17)
𝑵 𝑵

According to Linear Convolution for discrete time system is given as Eq.(7) of Experiment No.3
𝑦(𝑛) = 𝑥(𝑛) ∗ ℎ(𝑛) = ∑∞
𝑛=−∞ 𝑥(𝑘) ∙ ℎ(𝑛 − 𝑘) (7)

By convolution of two signals the resulting vector is of length: (LENGTH(A)+LENGTH(B)-1)

Given x(n) and h(n) are transformed to respective DTFTs, X(ω) and H(ω), applying convolution
property of DTFT, i.e., DTFT{𝑥(𝑛) ∗ ℎ(𝑛)} = X(ω) H(ω), Y(ω) is obtained. Performing IDFT Y(ω)
can be converted back to time domain y(n). The process of Linear convolution using DFT & IDFT is
as shown in the block diagram Fig.6.1

x(n) (M-1) N- X(k)


Zeros point
Length ‘L’ padding
x(n)
DFT
length Y(k) N-
N=L+M-1
point y(n)
IDFT length
h(n) (L-1) N-
N=L+M-1
Zeros point
Length ‘M’ padding h(n)
DFT
length H(k)
N=L+M-1

Fig.6.1 Process of Linear convolution by DFT & IDFT


N-point Circular Convolution of two sequences, x(n) and h(n), is defined as Eq.18

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 35 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

y(n) = ∑N−1
m=0 x(m) h((n − m))N = x(n) N h(n) 0 ≤ n ≤ N-1 (18)
Given x(n) and h(n) are transformed to respective DFTs, X(k) and H(k). Apply the property of DFT:
DFT {x(n) N h(n) } = X(k) · H(k). By performing IDFT on Y(k), it can be converted back to time
domain y(n).
Here the size of DFT, N = L1 +L2 -1, represents the length of circular convolution length. Therefore,
circular convolution will be same as linear convolution, when both x(n) and y(n) are of same length.
6.3 Linear convolution by DFT and IDFT method:
6.3.1 ALGORITHM 1:
Step (1) Initialize the discrete time sequences as x1(n) and x2(n).
Step (2) Identify the length of the sequences as N1 and N2.
Step (3) Initialize the length of resultant DFT sequence X1(k) and X2(k) as n1 and n2
Step (4)Set the DFT sequences X1(k) and X2(h) by appending zeros based on the lengths N1 and
N2, such that both sequences are of same length.
Step (5) Perform DFT of the sequences x1(n) and x2(n), using the command fft( ).
Step (6) Obtain the Linear convolution y(n) using DFT as given in Eq.(12).
Step (7) Plot the input sequences x1(n) & x2(n) and the resultant sequence y(n).

6.3.2 MATLAB PROGRAM 1:


%Linear Convolution using DFT & IDFT
close all;
clear;
x=input('Enter the first time domain sequence')
h=input('Enter the second time domain sequence')

L1=length(x);
L2=length(h);
N=L1+L2-1;

X=fft(x,N)
H=fft(h,N)
Y=X.*H;
y=ifft(Y,N)

n = 0:L1-1;

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 36 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

subplot(3,1,1)
stem(n,x);
xlabel('Time (n)');
ylabel('x(n)');
title('Time domain - First sequence')

n = 0:L2-1;
subplot(3,1,2)
stem(n,h);
xlabel('Time (n)');
ylabel('h(n)');
title('Time domain - Second sequence')

n = 0:N-1;
subplot(3,1,3)
stem(n,y);
xlabel('Time (n)');
ylabel('y(n)');
title('Time domain - Linear Convolition sequence')

6.3.3 RESULT:
x=
1 2 2 1
Enter the second time domain sequence [3 1 1 2 3]
h=
3 1 1 2 3
y=
Columns 1 through 9
3.0000 7.0000 9.0000 9.0000 10.0000 11.0000 8.0000 3.0000
6.3.4 Expected Waveform:
The input signals x1(n) & x2(n) and resultant signal y(n) using DFT & IDFT method is as shown in
Fig.6.2.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 37 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

Time domain - First sequence


2

x(n)
1

0
0 0.5 1 1.5 2 2.5 3
Time (n)
Time domain - Second sequence
4

h(n)
2

0
0 0.5 1 1.5 2 2.5 3 3.5 4
Time (n)
Time domain - Linear Convolition sequence
20

y(n) 10

0
0 1 2 3 4 5 6 7
Time (n)

Fig. 6.2 Linear Convolution of two sequences x1(n) and x2(n) using DFT& IDFT method

6.3.5 Exercise Problems


(1) Perform the linear convolution of x (n) =[1 1 1] and h(n) = [1 2 3 1] using DFT.
(2) Perform the linear convolution of x (n) =[1 2] and h(n) = [1 2 3] using DFT.

6.3.6 CONCLUSION:
 When the sequence x(n) is of length L1 and h(n) is of length L2 then the resultant
sequence of linear convolution y(n) is of length, N= L1 +L2 -1.
 Linear Convolution satisfies folding, multiplication, addition and shifting properties.
 Linear convolution using DFT & IDFT method satisfies the Convolution property of
DTFT.
6.4 Circular convolution by DFT and IDFT method:

6.4.1 ALGORITHM 2:
Step (1) Initialize the discrete time sequences as x(n)and h(n).
Step (2) Identify the length of the sequences as L1 and L2 & N-point for the DFT of the sequences.
Step (3) Initialize the length of resultant DFT sequenceX(k) and H(k) as n1 and n2
Step (4) Set the DFT sequences X(k) and H(k) by appending zeros based on the lengths L1 and L2,
such that both sequences are of same length with reference to N.
Step (5)Perform DFT of the sequences x(n) and h(n), using the Eq. (12).
Step (6)Obtain the circular convolution y(n) as product of two DFTs X(k) and H(k) using Eq.(13).
Step (7)Plot the input sequences x(n) & h(n) and the resultant sequence y(n).

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 38 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

6.4.2 MATLAB PROGRAM 2:

N-point DFT
clc; clear all; close all;
x=input('Enter the first sequence x[n]: ');
N1=input('Enter the DFT size: ');
L1=length(x);
x=[x,zeros(1,N1-L1)];
for k=0:1:N1-1
X(k+1)=0;
for n=0:1:N1-1
X(k+1)=X(k+1)+x(n+1)*exp(-i*2*pi*k*n/N1);
end
end
Xmag=abs(X);
Xang=angle(X);
disp('DFT of First sequence X(k)');
disp(Xmag);
disp(Xang);
k=0:1:N1-1;
subplot(2,1,1); stem(k,Xmag); xlabel('-->k'); ylabel('Magnitude of X(k)');
title('Magnitudespectrum');
subplot(2,1,2); stem(k,Xang); xlabel('-->k'); ylabel('Phase of X(k) in
radians'); title('Phasespectrum');

pause;
h=input('Enter the second sequence h[n]: ');
N2=input('Enter the DFT size: ');
L2=length(h);
h=[h,zeros(1,N2-L2)];
for k=0:1:N2-1
H(k+1)=0;
for n=0:1:N2-1
H(k+1)=H(k+1)+h(n+1)*exp(-i*2*pi*k*n/N2);
end
end
Hmag=abs(H);
Hang=angle(H);

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 39 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

disp('DFT of Second sequence H(k)');


disp(Hmag);
disp(Hang);
k=0:1:N2-1;
subplot(2,1,1); stem(k,Hmag); xlabel('-->k'); ylabel('Magnitude of H(k)');
title('Magnitudespectrum');
subplot(2,1,2); stem(k,Hang); xlabel('-->k'); ylabel('Phase of H(k)in radians');
title('Phasespectrum');
pause;
Y=X.*H;
N=length(Y);
Ymag=abs(Y);
Yang=angle(Y);
disp('DFT of Output sequence Y(k)');
disp(Ymag);
disp(Yang);
k=0:1:N-1;
subplot(2,1,1); stem(k,Ymag); xlabel('-->k'); ylabel('Magnitude of Y(k)');
title('Magnitudespectrum');
subplot(2,1,2); stem(k,Yang); xlabel('-->k'); ylabel('Phase in radians for
Y(k)'); title('Phasespectrum');
pause;
%To obtain y(n)using IDFT
[P,Q]=size(Y);
if Q~=1,
Y=Y.';
P=Q;
end
y=zeros(P,1);
k=0:P-1;
for n=0:P-1;
y(n+1)=exp(i*2*pi*k*n/P)*Y;
end
y=y/P;
disp('IDFT of Output sequence y(n)');
disp(y)
pause;

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 40 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

subplot(3,1,1); stem(k,x); xlabel('---->n'); ylabel('Amplitude'); title('First


input Signal x[n]');
subplot(3,1,2); stem(k,h); xlabel('---->n'); ylabel('Amplitude'); title('Second
input Signal h[n]');
subplot(3,1,3); stem(k,y); xlabel('---->n'); ylabel('Amplitude');
title('Circular convolution via DFT is y[n]');

6.4.3 RESULT:
Enter the first sequence x[n]: [2 1 2 1]
Enter the DFT size: 4
DFT of First sequence X(k)
6.0000 0.0000 2.0000 0.0000 0 -2.2620 0 -1.1703
Enter the second sequence h[n]: [1 2 3 4]
Enter the DFT size: 4
DFT of Second sequence H(k)
10.0000 2.8284 2.0000 2.8284 0 2.3562 -3.1416 -2.3562
DFT of Output sequence Y(k)
60.0000 0.0000 4.0000 0.0000 0 0.0942 -3.1416 2.7567

IDFT of Output sequence y(n)


14.0000 - 0.0000i
16.0000 + 0.0000i
14.0000 - 0.0000i
16.0000 - 0.0000i

6.4.4 Expected Waveform:


The input signals x(n)& h(n) and resultant signal y(n) using DFT & IDFT method is as shown in
Fig.6.3.

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 41 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

First input Signal x[n]


2

Amplitude
1

0
0 0.5 1 1.5 2 2.5 3 3.5 4
---->nSignal h[n]
Second input
4

Amplitude
2

0
0 0.5 1 1.5 2 2.5 3 3.5 4
---->n
Circular convolution via DFT is y[n]
20

Amplitude
10
X= 4
0 Y= 10
0 0.5 1 1.5 2 2.5 3 3.5 4
---->n
Fig. 6.3 Circular Convolution of two sequences x(n) and h(n) using DFT & IDFT method

6.4.5 Exercise Problems


(1) Perform the circular convolution of x (n) =[4 3 2 2] and h(n) = [1 2 3 1]
(2) Perform the circular convolution of x (n) =[1 2] and h(n) = [1 2 3].

6.4.6 CONCLUSION:
 Circular convolution is said be same as linear convolution, when both x(n) and y(n) are of
same length.
 If the sequence x(n) is of length L1 and h(n) is of length L2, then length N of resultant
sequence of circular convolution is chosen as >= to max(L1, L2)
 When circular convolution length, N < L1+L2 -1, then circular convolution is linear
convolution plus aliasing.
 The linear convolution is generally applied to aperiodic sequences. Whereas the Circular
Convolution is used to study the interaction of two signals that are periodic

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 42 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

7 Experiment No.7: Solution of a given difference equation.

7.1 Objective: To solve a given difference equation and obtain the output of an LTI system.

7.2 Theory:
A discrete time LTI system (also called digital filters) as shown in Fig.7.1 is represented by a linear
constant coefficient difference equation Eq.19.

Fig. 7.1 Discrete time LTI system

y[n]  a1 y[n  1]  a2 y[n  2]  b0 x[n]  b1 x[n  1]  b2 x[n  2]; (19)

The system function H(z) is obtained by applying Z transform to the difference equation as shown in
Eq.20 . Further, Inverse Z transform of H(z) yields h(n) – impulse response.
Y ( z ) b0  b1 z 1  b2 z 2 (20)
H ( z)  
X ( z ) 1  a1 z 1  a 2 z 2

A LTI system is characterized in time domain using impulse response h(n), which is obtained by
applying an impulse input to the LTI system as shown in Fig.7.2 ,where the LTI system is normally
represented as a black box.

Fig. 7.2 LTI system with Impulse input


In order to determine the impulse response h(n), Deconvolution is usually performed by computing
the Fourier Transform of the recorded signal x(n) and the transfer function y(n), apply deconvolution
in the Frequency domain, which is represented as H(Ω)=Y(Ω)/X(Ω) where Y, X, and H being
the Fourier Transforms of yn), x(n), and h(n) respectively. The deconvolution operation is valid only
if the LTI system is ‘invertible
Consider the difference equation: y[n]+0.8y[n-2]+0.6y[n-3] =x[n]+0.7x[n-1]+0.5x[n-2]

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 43 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

This difference equation can be solved to obtain y[n], the output for a given input x[n] by
rearranging as: y[n] = x[n] + 0.7x[n-1]+0.5x[n-2]- 0.8y[n-2]- 0.6y[n-3].
The solution of the above difference equation is output y(n), that depends on the input x[n]
 If x[n]= δ[n], an impulse, then the computed output y[n] is the impulse response.
 If x[n]=u[n], a unit step input, then the computed output y[n] is a step response.
 If x[n] = cos(wn), a sinusoidal sequence, then the computed output y[n] is a steady state
response (wherein y[n] is of the same frequency as x[n], with only an amplitude gain and
phase shift.
The MATLAB function filter is used to compute the impulse response/ step response/ response
for any given input x[n].
Note: filter function evaluates the convolution of infinite sequences, h[n] and x[n], which is not
possible with conv function (since conv requires both the sequences to be finite).

7.3 ALGORITHM 1:
Step (1) Identify a difference equation of an LTI system
Step (2) Set the coefficients of x as vector ‘a’ and the coefficients of y as vector ‘b’.
Step (3) Initialize the length of output sequence y(n) as N.
Step (4) Set the given expression for input sequence as x.
Step (5)Calculate the output y(n) of the given LTI system using the command filter ( ) .
Step (6)Plot the input sequences x(n) and the output sequence y(n).

7.4 MATLAB PROGRAM1:


3 1
%The given difference equation is :𝑦(𝑛) − 𝑦(𝑛 − 1) + 𝑦(𝑛 − 1) = 𝑥(𝑛)
4 8

%Solve the given difference equation of an LTI system using the command filter( )
clc; clear all; close all;
b=input('Enter the coefficients of x: ');
a=input('Enter the coefficients of y: ');
N=input('Enter the length of the input: ');
n=0:1:N-1;
x=(1/2).^n;
y=filter(b,a,x);
disp(y);
subplot(2,1,1); stem(n,x); xlabel('---->n'); ylabel('Amplitude');

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 44 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

title('input Signal x[n]');


subplot(2,1,2); stem(n,y); xlabel('---->n'); ylabel('Amplitude');
title('response of the system');
7.5 RESULT:
Enter the coefficients of x: [1]
Enter the coefficients of y: [1 -3/4 1/8]
Enter the length of the input: 15
Columns 1 through 8
1.0000 1.2500 1.0625 0.7656 0.5039 0.3135 0.1877 0.1094
Columns 9 through 15
0.0625 0.0352 0.0195 0.0107 0.0059 0.0032 0.0017
7.6 Expected Waveform:
The input signal x(n)& output signal y(n) for solving difference equation of a LTI system are as
shown in Fig.7.3.
input Signal x[n]
1
Amplitude

0.5

0
0 2 4 6 8 10 12 14
---->n
response of the system
1.5
Amplitude

0.5

0
0 2 4 6 8 10 12 14
---->n

Fig. 7.3 Solution of difference equation of a LTI system


Exercise Problems
Solve the given difference equations:
1 1
(1) 𝑦(𝑛) − 2 𝑦(𝑛 − 1) + 4 𝑦(𝑛 − 1) = 𝑥(𝑛) + 2𝑥(𝑛 − 1)
1
(2) 𝑦(𝑛) + 2 𝑦(𝑛 − 1) − 𝑦(𝑛 − 3) = 3𝑥(𝑛 − 1) + 2𝑥(𝑛 − 2)

CONCLUSION:
−𝑗2𝜋
 The phase factor or twiddle factor represented as 𝑒 𝑁 or WN satisfies property of
periodicity and property of symmetry
 These DFT signals can be used for Linear filtering, Power Spectrum estimation and
Frequency analysis of signals

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 45 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

8 Experiment No.8: Calculation of DFT and IDFT by FFT

8.1 Objective: To DFT & IDFT of a given sequence using FFT method .

8.2 Theory:
Radix-2 Decimation in Time Fast Fourier Transform Algorithm (DIT-FFT) makes use of the Divide
and Conquer approach. The N-point DFT is obtained by decimating time-sequence, the number of
points of DFT, N, is expressed as a power of 2, i.e., N= 2v, as the value of N increases, the
computational efficiency of FFT increases. The time sequence is split into even indexed sequence
and odd indexed sequence. Each of them is used to obtain separate N/2 –point DFTs. The samples
of N/2-pt DFTs are suitably combined by an N- point combining algebra to obtain N- point DFT.
This is called as first level decomposition.
Further, each of the subsequences is split into even and odd samples. This leads to each of the N/2-pt
DFTs to be expressed as two N/4-pt DFTs. This is called as second level decomposition. The
decomposition process is continued until, the N-point DFT is obtained using 2-pt DFTs. N point
DFT is expressed as
−j2πkn
X(k) = ∑N−1
n=0 x(n)e N 0 ≤ k ≤N-1
Consider the case of N=8;
−j2πkn
X(k) = ∑7n=0 x(n)e 8 0≤k≤7
The complete signal flow graph for 8-point DFT is as shown in Fig. the 8-point DFT computation
requires 3 stages with 4 (N/2) butterfly operations in each stage. The processor performs in-place
computation. The input is fed in bit reversed while the outputs are extracted in normal order.

8.3 ALGORITHM:
Step (1) Initialize the discrete time sequences as x(n) and set the required DFT as N-point.
Step (2) Obtain the DFT of the sequence x(n) as X(k) using the command fft( ).
Step (3) Obtain the IDFT of the sequence X(k) as x(n) using the command ifft( ).
Step (4) Plot the input sequence x(n) corresponding to time domain ‘n’.
Step (5) Plot the magnitude and phase response of DFT sequence X(k).

8.4 MATLAB PROGRAM:

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 46 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

%N Point DFT &IDFT using FFT Computation


close all;
clear;
x=input('Enter the time domain sequence')
N=input('Enter the No. of points of DFT')

X=fft(x,N)
x1=ifft(X,N)
n = 0:length(x)-1;
stem(n,x);
title('Time sequence')
xlabel('Time (n)');
ylabel('x(n)');

k=0:N-1
figure
subplot(2,1,1)
stem(k,abs(X));
title('Frequency domain - Magnitude response')
xlabel('Frequency-k');
ylabel('Mag |X(k)|');

subplot(2,1,2)
stem(k,angle(X))
xlabel('Frequency k');
ylabel('angle(X)');
title('Frequency domain - Phase response')

8.5 RESULT:
Enter the time domain sequence: [1 2 2 1 2 1 1 2]
x= 1 2 2 1 2 1 1 2
Enter the No. of points of DFT8 N = 8

X=

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 47 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

Columns 1 through 3
12.0000 + 0.0000i 0.4142 - 1.0000i 0.0000 + 0.0000i
Columns 4 through 6
-2.4142 + 1.0000i 0.0000 + 0.0000i -2.4142 - 1.0000i
Columns 7 through 8
0.0000 + 0.0000i 0.4142 + 1.0000i

8.6 Expected Waveform:


The input sequence x(n) for computation of FFT is as shown in Fig.8.1 and magnitude & phase
response DFT signal X(k), using FFT is as shown in Fig.8.2.
Time sequence
2

1.8

1.6

1.4

1.2
x(n)

0.8

0.6

0.4

0.2

0
0 1 2 3 4 5 6 7
Time (n)

Fig. 8.1 Input sequence x(n) for DFT


Frequency domain - Magnitude response
15
Mag |X(k)|

10

0
0 1 2 3 4 5 6 7
Frequency-k
Frequency domain - Phase response
4

2
angle(X)

-2

-4
0 1 2 3 4 5 6 7
Frequency k

Fig. 8.2 DFT and IDFT of a sequence x(n) using FFT

Exercise Problems

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 48 of 81


Digital Signal Processing Lab Manual, EEE Department, BNMIT, Bengaluru

1. Obtain the DFT and IDFT of a signal x(n) = {1,2, 2,1,2,1,1,2} using DIT- FFT algorithm.
2. Obtain the 4-point DFT of the sequence x(n) = [1,1,2,3] using FFT and sketch the
magnitude and phase spectrum. Also perform IDFT on the frequency domain sequence
using IFFT to extract the time domain sequence.

CONCLUSION:
 The DFT X(k) obtained using FFT satisfies symmetry property.
 Computation of DFT using FFT is faster than the direct method

Department of Electrical & Electronics Engineering, B.N.M.I.T Page 49 of 81


Digital Signal Processing Lab Manual

9 Design and implementation of IIR filters to meet given specification (Low pass, high pass,
band pass and band reject filters)

9.1 Objective: To Design an IIR filter using Butterworth / Chebyshev filter and obtain the
magnitude and frequency response for the given system.

9.2 Theory:
IIR filters have infinite-duration impulse response. Two types of IIR Filters: Butterworth Filter and
Chebyshev Filter (Types I). Typically any IIR filters has the following approach as shown in Fig.9.1.

Fig.9.1 Implementation of Digital IIR Filters


9.3 BUTTERWORTH LOWPASS FILTERS:
This filter is characterized by the property that its magnitude response is flat in both passband and
stopband. The magnitude-squared response of an Nth-order low pass filter is given by Eq.21 and its
ideal Characteristics is as shown in Fig.9.2
1
|Ha (jΩ)|2 = Ω 2N
(21)
1+( )
Ωc

Fig.9.2 Ideal Characteristics of IIR Filters


The system function Ha(s) of IIR Filters is given in Eq.22 and the roots of the denominator
polynomial (or poles of Ha(s)Ha(−s)) are given by Eq.23.

1 (𝑗𝛺)2𝑁
𝐻𝑎 (𝑠)𝐻𝑎 (−𝑠) = |𝐻𝑎 (𝑗𝛺)|2 |𝛺=𝑠⁄ = 𝑠 2𝑁
= 𝑠2𝑁 +(𝑗𝛺 2𝑁
(22)
𝑗 1+( ) 𝑐)
𝑗𝛺𝑐

Department of Electrical & Electronics Engineering, B.N.M.I.T 50


Digital Signal Processing Lab Manual

1 𝜋
(2𝑘+𝑁+1)
𝑝𝑘 = (−1)2𝑁 (𝑗𝛺) = 𝛺𝑐 𝑒 𝑗2𝑁 , 𝑘 = 0, 1, 2, … . , 2𝑁 − 1 (23)
The Butterworth analog low pass filter is specified by the parameters passband edge frequency Ωp,
stopband edge frequency Ωs, passband attenuation in dB, Ap and stopband attenuation in dB As and
sampling frequency fsamp. The design of the this filter depends on the order N and the cut-off
frequency Ωc for given specifications as mentioned in Eq.24 & Eq.25.

𝑙𝑜𝑔10 [(10𝐴𝑝 ⁄10 −1)⁄(10𝐴𝑠 ⁄10 −1)]


𝑁= (24)
2𝑙𝑜𝑔10 (𝛺𝑝 ⁄𝛺𝑠 )

𝛺𝑝
𝛺𝑐 = 2𝑁
(25)
√(10𝐴𝑝 ⁄10 −1)

9.4 CHEBYSHEV LOWPASS FILTERS:


There are two types of Chebyshev filters.The Chebyshev- type I filters have equiripple response in
the passband Chebyshev-II filters have equiripple response in the stopband. The Butterworth filters
have monotonic response in both passband and stopband. By choosing a filter that has an equiripple
rather than a monotonic behavior, we can obtain a lower-order filter. The magnitude-squared
response of a Chebyshev-type I filter is given in Eq.26
1
|𝐻𝑎 (𝑗𝛺)|2 = 2( 𝛺 )
(26)
1+𝜖 2 𝐶𝑁
𝛺𝑐

where N is the order of the filter, 𝜖 is the passband ripple factor, which is related to Ap and CN (x) is
the Nth-order Chebyshev polynomial given by Eq.27
cos(𝑁 cos −1 (𝑥)), 0 ≤ 𝑥 ≤ 1
𝐶𝑁 (𝑥) = { (27)
𝑐𝑜𝑠ℎ(cosh−1 (𝑥)), 1 ≤ 𝑥 ≤ ∞
𝛺
Where 𝑥 = 𝛺𝑐

The equiripple response of the Chebyshev filters is due to this polynomial CN(x). Its key properties
are:
(a) for 0 <x<1, CN(x) oscillates between −1 and 1, and
(b) for 1 < x < ∞, CN(x) increases monotonically to ∞.
There are two possible shapes of|Ha(jΩ)|2, one for N odd and one for N even as shown in Fig.9.3

Department of Electrical & Electronics Engineering, B.N.M.I.T 51


Digital Signal Processing Lab Manual

Fig.9.3 Ideal characteristics of Chebyshev filters


If αp is the gain in dB at passband frequency Ωp and αs is the gain in dB at stopband
frequencies Ωs, he order of the filter is given by Eq.28
1
−1 100.1𝛼𝑠 ,𝑑𝐵 −1 2
cosh [( 0.1𝛼 ,𝑑𝐵 ) ]
10 𝑝 −1
N= Ω
(28)
cosh−1 ( 𝑠 )
Ω𝑝

The poles are given by pk = σk + jΩk, k =0,...,N−1 are the (left half-poles) as given in Eq.29
π (2k+1)π
σk = (aΩc ) cos [ 2 + ]
2N
π (2k+1)π
} k = 0, … . , N − 1 (29)
Ωk = (bΩc ) sin [ 2 + ]
2N

where
1 N N 1 N 1 1
a= ( μ − √1⁄μ), b = ( N√μ + √1⁄μ) and μ = ϵ + √1 + ϵ2
2 √ 2

The system function is given by Eq.30


K
Ha (s) = ∏k(s−pk )
(30)

Where K is a normalizing factor chosen to make


1 ; N odd
Ha (j0) = { 1 N even
;
√1 + ϵ 2

For Analog-to-Digital (ADC) filter transformations, i.e., conversion from s-domain to z-domain, the
most popular techniques used in practice are the Bilinear and Impulse Invariance transformations,
which preserve the system function representation from analog to digital domain.
In Impulse Invariance transformation, analog poles {pk} into digital poles {epkT} are represented
using the system function as in Eq.31 to obtain the digital filter.

Department of Electrical & Electronics Engineering, B.N.M.I.T 52


Digital Signal Processing Lab Manual

R
H(z) = ∑N k
k=1 1−epkT z−1 (31)

In Bilinear transformation the analog to digital conversion is obtained as H(z) a rational function in
−1
z as given in Eq.32
2 1−z−1
H(z) = Ha (T 1+z−1 ) (32)

9.5 Implementation of IIR Butterworth filter


9.5.1 ALGORITHM 1:
Step (1) Set the values of passband edge frequency, stopband edge frequency, passband attenuation
in dB and stopband attenuation in dB as fp, fs, Ap and As respectively for the sampling frequency
data fsamp.

Step (2) Express the passband edge frequency fp & stopband edge frequency fs in terms of sampling
frequency fsamp (in radians/sec).

Step (3) Obtain the order N as the lowest order and analog Butterworth filter using the command
buttord (N, wc ) for the cut-off frequency wc to use with Butterworth filter of the given
specifications.

Step (4) Design an order N, low pass analog (‘s’) Butterworth filter with angular cutoff frequency
wc rad/s using the command butter (N, wc,’s’) that returns the filter coefficients in length

N+1 vectors of b (numerator) and a (denominator).

Step (5) Convert the s-domain transfer function to a z-transform discrete equivalent obtained from
the bilinear transformation command bilinear(a,b,fsamp), where a and b are row vectors containing
numerator and denominator transfer function coefficients, where a(s)/b(s), in descending powers of
s, transforms to z-transform coefficients num(z)/den(z).

Step (6) Obtain the N-point frequency response of digital filter using the command
freqz(num,den,256,fsamp), where N=256 and sampling frequency as fsamp in Hz.

Step (7) Plot the magnitude and frequency response of the IIR Butterworth Low pass filter.

9.5.2 MATLAB PROGRAM 1:


%Butterworth IIR Lowpass filter

clc; clear all; close all;


fp=input('Enter the passband edge frequency: ');
fs=input('Enter the stopband edge frequency: ');

Department of Electrical & Electronics Engineering, B.N.M.I.T 53


Digital Signal Processing Lab Manual

Ap=input('Enter the passband attenuation in dB: ');


As=input('Enter the stopband attenuation in dB: ');
fsamp=input('Enter the sampling frequency in Hz: ');
wp=(2*pi*fp/fsamp);
ws=(2*pi*fs/fsamp);
wp=2*fsamp*tan(wp/2);
ws=2*fsamp*tan(ws/2);
[N,wc]=buttord(wp,ws,Ap,As,'s')%For analog Butterworth filter
[b,a]=butter(N,wc,'s');
[num,den]=bilinear(b,a,fsamp);
disp('Numerator, a=');disp(num);
disp('Denominator, d=');disp(den);
freqz(num,den,256,fsamp);
grid on;
xlabel('frequency in Hz');
ylabel('magnitude in dB');
title('Frequency response of LPF');

9.5.3 RESULT:
Enter the passband edge frequency: 200
Enter the stopband edge frequency: 400
Enter the passband attenuation in dB: 3
Enter the stopband attenuation in dB: 15
Enter the sampling frequency in Hz: 2000
N= 3
wc = 1.6430e+03
Numerator, a=
0.0311 0.0933 0.0933 0.0311
Denominator, d=
1.0000 -1.4703 0.9195 -0.2004
9.5.4 Expected Waveform:
The magnitude and frequency response of the IIR Butterworth Low pass filter is as shown in Fig.9.4.

Department of Electrical & Electronics Engineering, B.N.M.I.T 54


Digital Signal Processing Lab Manual

Frequency response of LPF


0

magnitude in dB
-50

-100

-150

-200
0 100 200 300 400 500 600 700 800 900 1000
frequency in Hz

Phase (degrees) 0

-100

-200

-300
0 100 200 300 400 500 600 700 800 900 1000
Frequency (Hz)
Fig. 9.4 Magnitude and frequency response of the IIR Butterworth Low pass filter

9.5.5 Exercise Problems


1. Design a Butterworth digital IIR low pass filter using bilinear transformation to satisfy

the following specifications: passband edge frequency: 1500, stopband edge frequency:
2000, passband attenuation in dB: 1, stopband attenuation in dB: 20 and sampling
frequency: 8000 Hz
2. Design a Butterworth digital IIR high pass filter using bilinear transformation by taking
T=0.1sec to satisfy the following specifications: passband edge frequency: 0.65π,
stopband edge frequency: 0.45 π, passband attenuation in dB: 0.707, stopband
attenuation in dB: 0.2.

9.6 Implementation of IIR Chebyshev filter


9.6.1 ALGORITHM 2:
Step (1) Set the values of passband edge frequency, stopband edge frequency, passband attenuation
in dB and stopband attenuation in dB as fp, fs, Ap and As respectively for the sampling frequency
data fsamp.
Step (2) Express the passband edge frequency fp & stopband edge frequency fs corresponding of
sampling frequency fsamp (in radians/sec).
Step (3) Obtain the order N as the lowest order and analog Chebyshev Type I filter using the
command cheb1ord (, wc ) for the cut-off frequency wc to use with Butterworth filter of the given
specifications.

Department of Electrical & Electronics Engineering, B.N.M.I.T 55


Digital Signal Processing Lab Manual

Step (4) Design an order N, low pass analog (‘s’) Chebyshev filter with angular cutoff frequency
wc rad/s using the command butter (N, wc,’s’) that returns the filter coefficients in length N+1
vectors of b (numerator) and a (denominator).
Step (5) Convert the s-domain transfer function to a z-transform discrete equivalent obtained from
the bilinear transformation command bilinear(a,b,fsamp), where a and b are row vectors containing
numerator and denominator transfer function coefficients, where a(s)/b(s), in descending powers of
s, transforms to z-transform coefficients num(z)/den(z).
Step (6) Obtain the frequency response of digital filter using the command freqz( ).
Step (7) Plot the magnitude and frequency response of the IIR Chebyshev Low pass filter.

9.6.2 MATLAB PROGRAM 2:

%Chebyshev(type-I) IIR Lowpass filter

clc; clear all; close all;


wp=input('enter the passband edge frequency: ');
ws=input('enter the stopband edge frequency: ');
Ap=input('enter the passband attenuation: ');
As=input('enter the stopband attenuation: ');
fsamp=input('enter the sampling frequency: ');
Apdb=-20*log10(Ap)
Asdb=-20*log10(As)
ohmp=2*fsamp*tan(wp/2);%convert rad/sec
ohms=2*fsamp*tan(ws/2);
[N,wc]=cheb1ord(ohmp,ohms,Apdb,Asdb,'s')%Order of filter
[b,a]=cheby1(N,Apdb,wc,'s');%Unnormalised transfer function fpr given tansfer
function
display('Analog Unnormalised trf')
Hs=tf(b,a)
[num,den]=bilinear(b,a,fsamp);
%disp('Numerator, a=');disp(num);
%disp('Denominator, b=');disp(den);

display('Digital trf')
Hz=tf(num,den,1/fsamp)

Department of Electrical & Electronics Engineering, B.N.M.I.T 56


Digital Signal Processing Lab Manual

w=0:pi/16:pi;
display('Frequency response is');
Hfreq=freqz(num,den,w)%Freq Response in z domain
display('Magnitude response is');
Hmag=abs(Hfreq)
plot(w/pi,Hmag,'k')
grid on;
ylabel('magnitude in dB');
title('Frequency response of IIR Chebyshev LPF');

9.6.3 RESULT:
Enter the passband edge frequency: 0.2*pi
Enter the stopband edge frequency: 0.32*pi
Enter the passband attenuation: 0.8
Enter the stopband attenuation: 0.2
Enter the sampling frequency: 1
Apdb = 1.9382
Asdb = 13.9794
N= 3
wc = 0.6498

9.6.4 Expected Waveform:


The magnitude and frequency response of the IIR Chebyshev Low pass filter is as shown in Fig.9.5.

Department of Electrical & Electronics Engineering, B.N.M.I.T 57


Digital Signal Processing Lab Manual

Frequency response of IIR Chebyshev LPF


1

0.9

0.8

0.7

magnitude in dB
0.6

0.5

0.4

0.3

0.2

0.1

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Fig. 9.5 magnitude and frequency response of the IIR Chebyshev Low pass filter

9.6.5 Exercise Problems


1. Design a Chebyshev digital IIR low pass filter using bilinear transformation by taking T=1sec
to satisfy the following specifications: passband edge frequency:0.2*pi , stopband edge
frequency: 0.6*pi, passband attenuation: 0.8, stopband attenuation: 0.2 and sampling frequency
1Hz
2. Design a digital filter using Chebyshev approximation and bilinear transformation to meet the
following specifications:
0.707 ≤ |H(ejω )| ≤ 1 for 0 ≤ ω ≤ 0.2π
|𝐻(𝑒 𝑗𝜔 )| ≤ 0.1 for 0.5𝜋 ≤ 𝜔 ≤ 𝜋

9.6.6 CONCLUSION:
 From the analysis of Butterworth digital IIR low pass filter, it can be observed that the

magnitude response is flat in both passband and stop band, hence it is referred to as
maximally flat response
 From the magnitude and frequency response of Chebyshev digital IIR low pass, it can be
observed that magnitude is monotonic outside the passband and satisfy the properties of
Chebyshev filters.
 Due to aliasing effect the Impulse Invariance method is restricted for lower frequencies,
while the bilinear transformation can applied either for lower or higher frequencies without
aliasing problem.
 It can be observed that the system function varies based on the order of the given system,
where sharp cut-off characteristics can be obtained with minimum order of the filter.

Department of Electrical & Electronics Engineering, B.N.M.I.T 58


Digital Signal Processing Lab Manual

10 Design and implementation of FIR filters to meet given specification (Low


pass, high pass, band pass and band reject filters) using different window
functions

10.1 Objective: To Design an FIR filter using Rectangular/Hamming/Hanning/Blackman/Bartlett


window and obtain the magnitude and frequency response for the given system.

10.2 Theory:
Finite impulse response (FIR) filters demonstrate the property of linear phase. There are three design
techniques for FIR filters, namely: (i) the window design,(ii) the frequency sampling design, and (iii)
the optimal equiripple design technique. In this experiment, the window design technique has been
discussed for design and implementation.
The system function for an impulse response h(n) of length M, is represented in Eq.33 and the
frequency response function is represented in Eq. For linear-phase: H(ejω) = −αω, −π<ω≤ π , where α
is a constant phase delay. Here h(n) must be symmetric, that is, h(n) = h(M −1 − n), 0 ≤ n ≤ (M −1)
with α = (M −1)/ 2. Hence h(n) is symmetric about α, which is the index of symmetry. The two
possible types of symmetry are: M odd, then α = (M−1)/2 is an integer and M even, then
α = (M −1)/2 is not an integer.

If the type of linear phase h(n)=−h(M−1−n), 0 ≤ n ≤(M−1); α = (M −1)/ 2 ,β = ±π/ 2, this indicates
that the impulse response h(n) is anti-symmetric where the index of symmetry is α = (M −1)/2.

𝑀−1

𝐻(𝑒 𝑗𝜔 ) = ∑ ℎ(𝑛)𝑒 −𝑗𝜔𝑛 , − 𝜋 < 𝜔 ≤ 𝜋


𝑛=0

𝐻(𝑧) = ∑𝑀−1
𝑛=0 ℎ(𝑛)𝑧
−1
= 𝑧 −(𝑀−1) ∑𝑀−1
𝑛=0 ℎ(𝑛)𝑧
𝑀−1−𝑛
(33)
In order to design a linear-phase and causal FIR filter, a proper system that is non-causal & with
infinite-duration impulse response is to be selected. This system is truncated (or windowed) by
selecting an appropriate windowing function and with an appropriate ideal filter as shown in Table 1.
Consider an ideal LPF of bandwidth ωc < π is given by Eq.34
1 ∙ 𝑒 −𝑗𝛼𝜔 , |𝜔| ≤ 𝜔𝑐
𝐻𝑑 (𝑒 𝑗𝜔 ) = { (34)
0, 𝜔𝑐 ≤ |𝜔| ≤ 𝜋
where ωc is the cut-off frequency, and α is the sample delay.

Department of Electrical & Electronics Engineering, B.N.M.I.T 59


Digital Signal Processing Lab Manual

The impulse response of this filter is of infinite duration and is given by Eq.35
𝜋
1
ℎ𝑑 (𝑛) = ℱ −1 [𝐻𝑑 (𝑒 𝑗𝜔 )] = ∫ 𝐻𝑑 (𝑒 𝑗𝜔 )𝑒 𝑗𝜔𝑛 𝑑𝜔
2𝜋
−𝜋
1 𝜋 sin[𝜔𝑐 (𝑛−𝛼)]
= 2𝜋 ∫−𝜋 1 ∙ 𝑒 −𝑗𝜔𝛼 𝑒 𝑗𝜔𝑛 𝑑𝜔 = (35)
𝜋(𝑛−𝛼)

To obtain a causal and linear-phase FIR filter h(n) of length M as per the Eq.36
ℎ (𝑛), 0 ≤ 𝑛 ≤ 𝑀 − 1 𝑀−1
ℎ(𝑛) = { 𝑑 𝑎𝑛𝑑 𝛼 = 2 (36)
0, 𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒
This system is truncated (or windowed) by selecting an appropriate windowing function and with an
appropriate ideal filter. In general, h(n) can be thought of as being formed by the product of hd(n)
and a window function w(n) as given by Eq.37
h(n) = hd(n)·w(n) (37)
𝑆𝑜𝑚𝑒 𝑠𝑦𝑚𝑚𝑒𝑡𝑟𝑖𝑐 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛 𝑤𝑖𝑡ℎ 𝑟𝑒𝑠𝑝𝑒𝑐𝑡 𝑡𝑜 𝛼 𝑜𝑣𝑒𝑟 0 ≤ 𝑛 ≤ 𝑀 − 1
where w(n) ={
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Commonly used window function characteristics are as shown in Table 1
Table 1: Window Function characteristics
Window Transition width Min.
Name ∆𝜔 Stopband
Attenuation Representative Equation
Approx. Exact
Value
Rectangular 4𝜋 1.8𝜋 21dB 1, 0 ≤ 𝑛 ≤ 𝑀 − 1
𝑤(𝑛) = {
𝑀 𝑀 0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Bartlett 8𝜋 6.1𝜋 25dB 2𝑛 𝑀−1
, 0≤𝑛≤
𝑀 𝑀 𝑀−1 2
𝑤(𝑛) 2𝑛 𝑀−1
2− , ≤ 𝑛 ≤ 𝑀 − 1,
𝑀−1 2
{ 0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Hann 8𝜋 6.2𝜋 44dB 2𝜋𝑛
0.5 [1 − cos ( )] 0 ≤ 𝑛 ≤ 𝑀 − 1
𝑀 𝑀 𝑤(𝑛) = { 𝑀−1
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Hamming 8𝜋 6.6𝜋 53dB 2𝜋𝑛
𝑀 𝑀 𝑤(𝑛) = {0.54 − 0.46 cos (𝑀 − 1) 0≤𝑛 ≤𝑀−1
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

Blackman 12𝜋 11𝜋 74dB 𝑤(𝑛)


𝑀 𝑀 2𝜋𝑛 2𝜋𝑛
= {0.42 − 0.5 cos (𝑀 − 1) + 0.08 cos (𝑀 − 1) 0 ≤ 𝑛 ≤ 𝑀 − 1
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

Ideal or desired impulse response functions for different filters is as mentioned in Table 2

Department of Electrical & Electronics Engineering, B.N.M.I.T 60


Digital Signal Processing Lab Manual

Table 2: Ideal (desired) impulse response for Different filters

FilterIdeal(desired) frequency Ideal(desired) impulse response


Response
Lowpass 𝐻𝑑 (𝜔) sin 𝜔𝑐 (𝑛 − 𝜏)
ℎ 𝑑 (𝑛) = 𝑓𝑜𝑟 𝑛 ≠ 𝜏
𝑒 −𝑗𝜏𝜔 ; −𝜔𝑐 ≤ 𝜔 ≤ 𝜔𝑐 𝜋(𝑛 − 𝜏)
= { 0; −𝜋 ≤ 𝜔 ≤ −𝜔𝑐 𝜔𝑐
ℎ𝑑 (𝑛) = 𝑓𝑜𝑟 𝑛 = 𝜏
0; 𝜔𝑐 ≤ 𝜔 ≤ 𝜋 𝜋
Highpass 𝐻𝑑 (𝜔) sin 𝜔𝑐 (𝑛 − 𝜏)
−𝑗𝜏𝜔 ℎ𝑑 (𝑛) = 𝑓𝑜𝑟 𝑛 ≠ 𝜏
𝑒 ; −𝜋 ≤ 𝜔 ≤ −𝜔𝑐 𝜋(𝑛 − 𝜏)
= { 𝑒 −𝑗𝜏𝜔 ; 𝜔𝑐 ≤ 𝜔 ≤ 𝜋 𝜔𝑐
ℎ𝑑 (𝑛) = 1 − 𝑓𝑜𝑟 𝑛 = 𝜏
0; − 𝜔𝑐 ≤ 𝜔 ≤ 𝜔𝑐 𝜋
Bandpass 𝐻𝑑 (𝜔) ℎ𝑑 (𝑛)
𝑒 −𝑗𝜏𝜔
; −𝜔𝑐2 ≤ 𝜔 ≤ 𝜔𝑐1 sin 𝜔𝑐2 (𝑛 − 𝜏) − sin 𝜔𝑐1 (𝑛 − 𝜏)
= 𝑓𝑜𝑟 𝑛
𝑒 −𝑗𝜏𝜔 ; 𝜔𝑐1 ≤ 𝜔 < 𝜔𝑐2 𝜋(𝑛 − 𝜏)
= 0; −𝜋 ≤ 𝜔 < −𝜔𝑐2 ≠𝜏
0; −𝜔𝑐1 < 𝜔 < 𝜔𝑐1 1
ℎ𝑑 (𝑛) = 𝑓𝑜𝑟 𝑛 = 𝜏
{ 0; 𝜔𝑐2 < 𝜔 ≤ 𝜋 𝜋
Bandstop 𝐻𝑑 (𝜔) ℎ𝑑 (𝑛)
𝑒 −𝑗𝜏𝜔 ; −𝜋 ≤ 𝜔 ≤ −𝜔𝑐2 sin 𝜔𝑐2 (𝑛 − 𝜏) + sin 𝜋(𝑛 − 𝜏) − sin 𝜔𝑐1 (𝑛 − 𝜏)
−𝑗𝜏𝜔 = 𝑓𝑜𝑟
𝑒 ; −𝜔𝑐1 ≤ 𝜔 < 𝜔𝑐1 𝜋(𝑛 − 𝜏)
= 𝑒 −𝑗𝜏𝜔 ; 𝜔𝑐2 < 𝜔 < 𝜋 ≠𝜏
𝜔𝑐2 − 𝜔𝑐1
0; −𝜔𝑐2 ≤ 𝜔 ≤ −𝜔𝑐1 ℎ𝑑 (𝑛) = 1 − ( ) 𝑓𝑜𝑟 𝑛 = 𝜏
{ 0; 𝜔𝑐1 < 𝜔 < 𝜔𝑐2 𝜋

10.3 ALGORITHM 1:
Step (1) Set the values of passband edge frequency and length of the filter to obtain the desired
frequency response.
Step (2) Assign the variables hd as desired impulse response and hna as the cut-off frequency in
rad/sec.
Step (3) For adjusting the filter order of the given window, it must be an odd number and the order
of filter must be one less than that of the window
Step (4) Design an order N for a low pass digital FIR filter with angular cutoff frequency wc rad/s
using the command fir1( ).
Step (5) Obtain the frequency response of digital filter using the command freqz( ).
Step (6) Plot the magnitude and frequency response of the FIR Low pass filter.
10.4 MATLAB PROGRAM 1:
% Program for designing and implementing the low pass FIR filter using
% window functions

Department of Electrical & Electronics Engineering, B.N.M.I.T 61


Digital Signal Processing Lab Manual

clear all
wc = input('Enter the pass band edge frequency in radians:');% example wc =
0.2*pi
N = input('Enter the length of the filter:');
hd = zeros(1,N);
a = (N-1)/2;
hna = wc/pi;
k = 1:1:((N-1)/2);
n = k - 1-((N-1)/2);
hd(k) = (sin(wc*n))./(pi*n);% Desired response for low pass filter
w_rec(k) = 1;
% w_bar = 1-2*abs(k -(N-1)/2)/(N-1);
% w_ham = 0.54 - 0.46*cos(2*pi*(k-1)/(N-1));
% w_han = 0.5 - 0.5*cos(2*pi*(k-1)/(N-1));
% w_blk = 0.42 - 0.5*cos(2*pi*(k-1)/(N-1))+0.08*cos(2*pi*(k-1)/(N-1));
hn(k) = hd(k);% if the window function is rectangular window, otherwise
%hd(k) should be multiplied by the window function given.
hn = [hn hna]
w =0:pi/16:pi
Hw1 = hna*exp(-j*w*a);
Hw2 = 0;
for m =1:1:a
Hw3 = hn(m)* ((exp(j*w*(1-m)))+(exp(-j*w*(1-m+2*a))));
Hw2 = Hw2+Hw3;
end
Hw = Hw2 +Hw1
H_mag = abs(Hw)
plot(w/pi,H_mag,'k');
grid;
title('Magnitude response of LPF FIR filter')
xlabel('Normalized frequency,\omega/\pi')
ylabel('Magnitude')

10.5 RESULT:
Enter the pass band edge frequency in radians: 1
Enter the length of the filter: 7

Department of Electrical & Electronics Engineering, B.N.M.I.T 62


Digital Signal Processing Lab Manual

hn =
0.0150 0.1447 0.2678 0.3183
10.6 Expected Waveform:
The magnitude response of the FIR Low pass filter is as shown in Fig.10.1. for rectangular window
and Fig.10.1. for Hanning window

Magnitude response of LPF FIR filter


1.4

1.2

0.8
Magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency, /

Fig. 10.1 magnitude response of the FIR Low pass filter for Rectangular window
Magnitude response of LPF FIR filter
1.4

1.2

0.8
Magnitude

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized frequency, /

Fig. 10.2 magnitude response of the FIR Low pass filter for Hanning window

Department of Electrical & Electronics Engineering, B.N.M.I.T 63


Digital Signal Processing Lab Manual

10.7 Exercise Problems


1. Design an ideal high pass filter with a frequency response
π
1 ≤ |ω| ≤ π
4
Hd (ω) = { π . Find the values of h(n) for N=11. Find the H(z). plot the
0 |ω| ≤
4

magnitude response.
π 3π
2. Design an ideal band pass filter with frequency response Hd (ω) = 1, for ≤ |ω| ≤ .
4 4

Use rectangular window with N=11

10.8 CONCLUSION:
 From the magnitude response of FIR low pass filter, it can be observed that the ringing
effect or the oscillations near the band edges are very prominent in rectangular window,
while the other window functions display tapering of oscillations decaying to zero.
 FIR filters are inherently stable and satisfy the linear phase property
 The type of window function to be used depends on the specifications of the given
system including pass band frequency, stop band frequency and order of the filter ‘M’.

Department of Electrical & Electronics Engineering, B.N.M.I.T 64


Digital Signal Processing Lab Manual

11 Design and implementation of FIR filters to meet given specification (Low


pass, high pass, band pass and band reject filters) using frequency sampling
technique.

11.1 Objective: To Design an FIR filter for the given specifications and frequency response for the
given system using frequency sampling technique.

11.2 Theory:

In frequency sampling technique, the design approach for the system function H (z) can be obtained
from the samples H(k) of the frequency response H(ejω) given by Eq.38. If h(n) is the impulse
response of an M-point FIR filter and H(k) be its M-point DFT then system function H(z) is
represented as Eq.39.
1−𝑒 −𝑗𝜔𝑀 𝐻(𝑘)
𝐻(𝑒 𝑗𝜔 ) = ∑𝑀−1
𝑘=0 (38)
𝑀 1−𝑒 −𝑗𝜔 𝑒 𝑗2𝜋𝑘/𝑀
1−𝑧 −𝑀 𝐻(𝑘)
H(z) = ∑𝑀−1
𝑛=0 ℎ(𝑛)𝑧
−𝑛
= ∑𝑀−1
𝑘=0 (39)
𝑀 1−𝑧 −1 𝑒 𝑗2𝜋𝑘/𝑀

𝐻(0) 𝑘=0
Where, H(k) = 𝐻(𝑒 𝑗2𝜋𝑘/𝑀 ) = {
𝐻 ∗ (𝑀 − 𝑘) 𝑘 = 1, 2, … , 𝑀 − 1
For linear phase filters, h(n) = ± h(M – 1 – N). where + for type 1 and type 2 linear phase filters
and – for type 3 and type 4 linear phase filters.

Consider an ideal low pass filter Hd(ejω), choose the filter length M and then sample Hd(ejω) at M
equi-spaced frequencies between 0 and 2π. The actual response H(ejω) is represented as interpolation
of the samples H(k) as shown in Fig.11.1

.
Fig. 11.1 Ideal and approximated response H(ejω) represented as interpolation of the samples H(k)

Department of Electrical & Electronics Engineering, B.N.M.I.T 65


Digital Signal Processing Lab Manual

From the frequency samples, the approximation error, which is the difference between the ideal and
the actual response, is zero at the sampled frequencies. This approximation error at all other
frequencies depends on the shape of the ideal response; that is, the sharper the ideal response, the
larger the approximation error. The error is larger near the band edges and smaller within the band.
Usually, the optimum design method with variation of number of samples ‘M’, is used to minimize
error in the stopband by varying values of the transition band samples.

11.3 ALGORITHM:
Step (1) Set the values of length of the filter (M) to obtain the desired frequency response.
Step (2) Calculate the frequency sampling index ‘α’ and frequency of sampling ‘w1’
Step (3) Assign the variables Hrs as Ideal impulse response, Hdr as the desired frequency response
and wd1 as the ideal frequency to obtain the impulse response plot.
Step (4) The function Hr_Type 2 is used to obtain the low pass filter coefficients for the impulse
response.
Step (5) Obtain the frequency response of digital filter using the function freqz_m( ).
Step (6) Plot the magnitude and frequency response of the FIR Low pass filter using Frequency
Sampling technique.

11.4 MATLAB PROGRAM:

% Consider low pass filter specifications: Example 14, Page 246 Vinay K Ingle.
% wp =0 .2*pi
% ws =0 .3*pi,
% Rp =0 .25 dB
% As = 50 dB
% Design an FIR filter using the frequency sampling approach.
% Solution Let us choose M =20 sothat we have a frequency sample at wp, that is,
% at k = 2:
% wp =0.2*pi = (2*pi/20)* 2
% and the next sample at ws, that is, at k = 3:
% ws =(0.3*pi/20)% 3
% Thus we have 3 samples in the passband [0 < w <wp] and 7 samples in the
stopband [ws < w < pi].
%We have Hr (k) = [1 ,1,1,0,...,0(15 zeros) ,1,1]

Department of Electrical & Electronics Engineering, B.N.M.I.T 66


Digital Signal Processing Lab Manual

%Since M = 20, a = (20-1)/2 =9.5 and since this is a Type-2 linear-phase filter,
we have
% angle of H(k)= [-9.5 *pi*k for 0< k < 9 and +9.5 *pi*(20 -k) for 10< k < 19
% we assemble H (k) and determine the impulse response h(n). The MATLAB script
follows:
clear all
M = 20;
alpha = (M-1)/2;
l = 0:M-1;
wl = (2*pi/M)*l;
Hrs = [1,1,1,zeros(1,15),1,1]; %Ideal Amp Res sampled
Hdr = [1,1,0,0];
wd1 = [0,0.25,0.25,1]; %Ideal Amp Res for plotting
k1 = 0:floor((M-1)/2);
k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH);
h = real(ifft(H,M));
[db,mag,pha,rd,w]=freqz_m(h,1);
[Hr,ww,a,L]=Hr_Type2(h);
subplot(2,2,1);plot(wl(1:11)/pi,Hrs(1:11),'o',wd1,Hdr);
axis([0,1,-0.1,1.1]);
title('Frequency Samples: M=20')
xlabel('frequency in pi units');
ylabel('Hr(k)')
subplot(2,2,2);
stem(l,h);
axis([-1,M,-0.1,0.3])
title('Impulse Response');
xlabel('n');
ylabel('h(n)');
subplot(2,2,3);
plot(ww/pi,Hr,wl(1:11)/pi,Hrs(1:11),'o');
axis([0,1,-0.2,1.2]);
title('Amplitude Respons')
xlabel('frequency in pi units');
ylabel('Hr(w)')
subplot(2,2,4);

Department of Electrical & Electronics Engineering, B.N.M.I.T 67


Digital Signal Processing Lab Manual

plot(w/pi,db);
axis([0,1,-60,10]);
grid
title('Magnitude Response');
xlabel('frequency in pi units');
ylabel('Decibels');

%Function for Hr_Type2( )


function [Hr,w,b,L] = Hr_Type2(h);

% Computes Amplitude response of Type-2 LP FIR filter


% [Hr,w,b,L] = Hr_Type2(h)
% Hr = Amplitude Response
% w = frequencies between [0 pi] over which Hr is computed
% b = Type-2 LP filter coefficients
% L = Order of Hr
% h = Type-2 LP impulse response
M = length(h);
L = M/2;
b = 2*[h(L:-1:1)];
n = [1:1:L]; n = n-0.5;
w = [0:1:500]'*pi/500;
Hr = cos(w*n)*b';

%Function for freqz_m( )


function [db,mag,pha,grd,w] = freqz_m(b,a);
% Modified version of freqz subroutine
% [db,mag,pha,grd,w] = freqz_m(b,a);
% db = Relative magnitude in dB computed over 0 to pi radians
% mag = absolute magnitude computed over 0 to pi radians
% pha = Phase response in radians over 0 to pi radians
% grd = Group delay over 0 to pi radians
% w = 501 frequency samples between 0 to pi radians
% b = numerator polynomial of H(z) (for FIR: b=h)
% a = denominator polynomial of H(z) (for FIR: a=[1])
[H,w] = freqz(b,a,1000,'whole');
H = (H(1:1:501))'; w = (w(1:1:501))';

Department of Electrical & Electronics Engineering, B.N.M.I.T 68


Digital Signal Processing Lab Manual

mag = abs(H);
db = 20*log10((mag+eps)/max(mag));
pha = angle(H);
% pha = unwrap(angle(H));
grd = grpdelay(b,a,w);
% grd = diff(pha);
% grd = [grd(1) grd];
% grd = [0 grd(1:1:500); grd; grd(2:1:501) 0];
% grd = median(grd)*500/pi;

11.5 RESULT:
The magnitude response of the FIR Low pass filter using frequency sampling technique is as shown
in Fig.11.2.
Frequency Samples: M=20 Impulse Response
0.3
1
0.2
Hr(k)

h(n)
0.5 0.1

0
0
-0.1
0 0.5 1 0 5 10 15 20
frequency in pi units n
Amplitude Respons Magnitude Response

1 0
Decibels

-20
Hr(w)

0.5

-40
0
-60
0 0.5 1 0 0.5 1
frequency in pi units frequency in pi units

Fig. 11.2 Magnitude response of the FIR Low pass filter using frequency sampling technique

Department of Electrical & Electronics Engineering, B.N.M.I.T 69


Digital Signal Processing Lab Manual

11.6 Exercise Problems


1. Design a low pass filter with the specifications wp=0.2 π, Rp=0.25 π dB, ws=0.3 π and As=50dB
using Frequency sampling technique. Consider the number of samples as M=40.
2. Design a bandpass filter using frequency filtering technique for the design specifications: lower
pass band edge amplitude Rp1=1dB @ w1p=0.35π, upper pass band edge amplitude Rp2=1dB
@ w2p=0.65 π, lower stop band edge amplitude As1=60dB @ w1s=0.2π, upper stop band edge
amplitude As2=20dB @ w2s=0.8 π .

11.7 Conclusion:
 Observe the sampling technique with different values of ‘M’ and analyze the ripples present in
the transition band to get better result of attenuation in stopband of specified range.
 Perform the frequency sampling technique for low pass, high pass and band pass filters and
analyze the frequency response for optimized design of FIR filters.

Department of Electrical & Electronics Engineering, B.N.M.I.T 70


Digital Signal Processing Lab Manual

12 Realization of IIR and FIR filters


12.1 Objective: To realize IIR and FIR filter for the given specifications.
12.2 Theory:
To process any signals using a system, it requires designing and implementing these systems in the
form of filters. These filters can be either IIR or FIR or the form of its implementation (structures).
IIR filters as designed and modeled by rational system functions using difference equations. Such
filters are termed autoregressive moving average (ARMA) or, more generally, as recursive filters.

Implementation of Filters for a LTI systems requires the three important elements to describe digital
filter structures. These elements are (i) Adder, (ii) Multiplier (gain) and (iii) Delay element (shift)
These basic elements can be used to describe various structures of both IIR and FIR filters.
MATLAB is a convenient tool in the development of these structures that require operations on
polynomials.

12.3 IIR FILTER STRUCTURES


The system function of an IIR filter is given by Eq.40.

𝐵(𝑧) ∑𝑀 𝑏𝑛 𝑧 −1 𝑏0 +𝑏1 𝑧 −1+⋯+𝑏𝑀 𝑧 −𝑀


𝐻(𝑧) = = ∑𝑁=0 −1
= ; 𝑎0 = 1 (40)
𝐴(𝑧) 𝑛=0 𝑎𝑛 𝑧 1+𝑎1 𝑧 −1 +⋯+𝑎𝑁 𝑧 −𝑁

where bn and an are the coefficients of the filter. We have assumed without loss of generality that a0
=1. The order of such an IIR filter is called N if aN ≠ 0. The difference equation representation of an
IIR filter is expressed as Eq.41.
𝑦(𝑛) = ∑𝑀 𝑁
𝑚=0 𝑏𝑚 𝑥(𝑛 − 𝑚) − ∑𝑚=1 𝑎𝑚 𝑦(𝑛 − 𝑚) (41)
Three different structures can be used to implement an IIR filter:
1. Direct form: In this form the difference equation is implemented directly as given. There are two
parts to this filter, namely the moving average part and the recursive part (or equivalently, the
numerator and denominator parts). Therefore this implementation leads to two versions: direct form
I and direct form II structures.
2. Cascade form: In this form the system function H(z) is factored into smaller 2nd-order sections,
called biquads. The system function is then represented as a product of these biquads. Each biquad is

Department of Electrical & Electronics Engineering, B.N.M.I.T 71


Digital Signal Processing Lab Manual

implemented in a direct form, and the entire system function is implemented as a cascade of biquad
sections.
3. Parallel form: This is similar to the cascade form, but after factorization, a partial fraction
expansion is used to represent H(z) as a sum of smaller 2nd-order sections. Each section is again
implemented in a direct form, and the entire system function is implemented as a parallel network of
sections. IIR filters are generally described using the rational form version (or the direct form
structure) of the system function.
12.3.1 Example : CASCADE FORM
In this form the system function H(z) is written as a product of 2nd-order sections with real
coefficients as in Eq.42. This is done by factoring the numerator and denominator polynomials into
their respective roots and then combining either a complex conjugate root pair or any two real roots
into 2nd-order polynomials in Eq.42. If we assume that N is an even integer, then H(z) is represented
as in Eq.44.

𝑏0 +𝑏1 𝑧 −1 +⋯+𝑏𝑀 𝑧 −𝑁
𝐻(𝑧) = (42)
1+𝑎1 𝑧 −1 +⋯+𝑎𝑁 𝑧 −𝑁
𝑏 𝑏
1+ 1 𝑧 −1 +⋯+ 𝑁 𝑧 −𝑁
𝑏 𝑏
= 𝑏0 1+𝑎0 𝑧 −1 +⋯+𝑎0 𝑧 −𝑁 (43)
1 𝑁

1+𝐵 𝑧 −1 +𝐵 𝑧 −2
𝑏0 ∏𝑁 𝑘,1 𝑘,2
𝑘=1 1+𝐴 𝑧 −1 +𝐴 𝑧 −2 (44)
𝑘,1 𝑘,2

Where, K is equal to N/2 , and Bk,1, Bk,2, Ak,1, and Ak,2 are real numbers representing the
coefficients of 2nd-order sections. The 2nd-order section Hk(z) is given in Eq.45
𝑌𝑘+1 (𝑧) 1+𝐵𝑘,1 𝑧 −1 +𝐵𝑘,2 𝑧 −2
𝐻𝑘 (𝑧) = = ; 𝑘 = 1, 2, … , 𝐾 (45)
𝑌𝑘 (𝑧) 1+𝐴𝑘,1 𝑧 −1 +𝐴𝑘,2 𝑧 −2

With 𝑌1 (𝑧) = 𝑏0 𝑋(𝑧); 𝑌𝐾+1 (𝑧) = 𝑌(𝑧) is called the kth biquad section. The input to the kth
biquad section is the output from the (k − 1)th biquad section, and the output from the kth biquad is
the input to the (k+1)th biquad. Now each biquad section Hk(z) can be implemented in direct form II,
as shown in Fig.12.1.The entire filter is then implemented as a cascade of biquads .

Department of Electrical & Electronics Engineering, B.N.M.I.T 72


Digital Signal Processing Lab Manual

Fig.12.1 Biquad section structure


12.3.2 ALGORITHM:
Step (1): Given the coefficients {bn} and {an} of the direct form filter, we have to obtain the
coefficients b0, {Bk,i}, and {Ak,i}. This is done by the following function dir2cas. This function
converts the b and a vectors into K × 3 B and A matrices. It begins by computing b0, which is equal
to b0/a0 (assuming a0 ≠ 1). It then makes the vectors b and a of equal length by zero-padding the
shorter vector. This ensures that each biquad has a nonzero numerator and denominator.
Step (2): Next it computes the roots of the B(z) and A(z) polynomials. Using the cplxpair function,
these roots are ordered in complex conjugate pairs. Now every pair is converted back into a 2nd-
order numerator or denominator polynomial using the poly function. The SP toolbox function, tf2sos
(transfer function to 2nd-order section), also performs a similar operation.
Step (3): The cascade form is implemented using the following casfiltr function. It employs the
filter function in a loop using the coefficients of each biquad stored in B and A matrices. The input is
scaled by b0, and the output of each filter operation is used as an input to the next filter operation.
Step (4): The output of the final filter operation is the overall output. The MATLAB function,
cas2dir converts a cascade form to a direct form. This is a simple operation that involves
multiplication of several 2nd-order polynomials. For this purpose, the MATLAB function conv is
used in a loop over K factors. The SP toolbox function, sos2tf also performs a similar operation.

12.4 FIR FILTER STRUCTURES


A finite-duration impulse response filter has a system function of the form Eq.46.

𝐻(𝑧) = 𝑏0 + 𝑏1 𝑧 −1 + 𝑏2 𝑧 −2 + ⋯ + 𝑏𝑀−1 𝑧1−𝑀 = ∑𝑀−1


𝑛=0 𝑏𝑛 𝑧
−𝑛
(46)
Hence the impulse response h(n) is given by Eq.47.

𝑏 ,0 ≤ 𝑛 ≤ 𝑀 −1
ℎ(𝑛) = { 𝑛 (47)
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
The difference equation representation is giveN as Eq.48.
y(n) = b0x(n) + b1x(n − 1) +… + bM−1x(n −M + 1) (48)
which is a linear convolution of finite support.

The order of the filter is M − 1, and the length of the filter (which is equal to the number of
coefficients) is M. The FIR filter structures are always stable, and they are relatively simple
compared to IIR structures.

Department of Electrical & Electronics Engineering, B.N.M.I.T 73


Digital Signal Processing Lab Manual

Furthermore, FIR filters can be designed to have a linear-phase response, which is desirable in some
applications.
We will consider the following four structures:
1. Direct form: In this form the difference equation is implemented directly as given.
2. Cascade form: In this form the system function H(z) is factored into 2nd-order factors, which are
then implemented in a cascade connection.
3. Linear-phase form: When an FIR filter has a linear-phase response, its impulse response exhibits
certain symmetry conditions. In this form we exploit these symmetry relations to reduce
multiplications by about half.
4. Frequency-sampling form: This structure is based on the DFT of the impulse response h(n) and
leads to a parallel structure. It is also suitable for a design technique based on the sampling of
frequency response H(ejω).

12.4.1 Example: CASCADE FORM


The system function H(z) is converted into products of 2nd-order sections with real coefficients as in
Eq.49. These sections are implemented in direct form and the entire filter as a cascade of 2nd-order
sections as in Eq.50.
𝐻(𝑧) = 𝑏0 + 𝑏1 𝑧 −1 + 𝑏2 𝑧 −2 + ⋯ + 𝑏𝑀−1 𝑧 −1+𝑀
𝑏 𝑏 𝑏𝑀−1
= 𝑏0 (1 + 𝑏1 𝑧 −1 + 𝑏2 𝑧 −2 + ⋯ + 𝑧 −1+𝑀 ) (49)
0 0 𝑏0

= 𝑏0 ∏𝐾
𝑘=1(1 + 𝐵𝑘,1 𝑧
−1
+ 𝐵𝑘,2 𝑧 −2 ) (50)
𝑀
where K is equal to ⌊ 2 ⌋, and Bk,1 and Bk,2 are real numbers representing the coefficients of 2nd -order

sections. For M = 7 the cascade form is shown in Figure below.


12.4.2 ALGORITHM: (Same as the above Algorithm 12.3.2)
For the FIR cascade form, we will use dir2cas function by setting the denominator vector a equal to
1. Similarly, cas2dir can be used to obtain the direct form from the cascade form.

12.5 MATLAB PROGRAM:


function [b0,B,A] = dir2cas(b,a);
% DIRECT-form to CASCADE-form conversion (cplxpair version)
% [b0,B,A] = dir2cas(b,a)
% b0 = gain coefficient

Department of Electrical & Electronics Engineering, B.N.M.I.T 74


Digital Signal Processing Lab Manual

% B = K by 3 matrix of real coefficients containing bk’s


% A = K by 3 matrix of real coefficients containing ak’s
% b = numerator polynomial coefficients of DIRECT form
% a = denominator polynomial coefficients of DIRECT form
% compute gain coefficient b0
b0 = b(1); b = b/b0; a0 = a(1); a = a/a0; b0 = b0/a0;
M = length(b); N = length(a);
if N > M
b = [b zeros(1,N-M)];
elseif M > N
a = [a zeros(1,M-N)]; N = M;
else
NM = 0;
end
K = floor(N/2); B = zeros(K,3); A = zeros(K,3);
if K*2 == N;
b = [b 0]; a = [a 0];
end
%
broots = cplxpair(roots(b)); aroots = cplxpair(roots(a));
for i=1:2:2*K
Brow = broots(i:1:i+1,:); Brow = real(poly(Brow));
B(fix((i+1)/2),:) = Brow;
Arow = aroots(i:1:i+1,:); Arow = real(poly(Arow));
A(fix((i+1)/2),:) = Arow;
end

Example:
b=[1 -3 11 -27 18]; a=[16 12 2 -4 -1];
b0 = b(1); b = b/b0; a0 = a(1); a = a/a0; b0 = b0/a0;
M = length(b); N = length(a);

Department of Electrical & Electronics Engineering, B.N.M.I.T 75


Digital Signal Processing Lab Manual

if N > M
b = [b zeros(1,N-M)];
elseif M > N
a = [a zeros(1,M-N)]; N = M;
else
NM = 0;
end
K = floor(N/2); B = zeros(K,3); A = zeros(K,3);
if K*2 == N
b = [b 0]; a = [a 0];
end
broots = cplxpair(roots(b)); aroots = cplxpair(roots(a));
for i=1:2:2*K
Brow = broots(i:1:i+1,:); Brow = real(poly(Brow));
B(fix((i+1)/2),:) = Brow;
Arow = aroots(i:1:i+1,:); Arow = real(poly(Arow));
A(fix((i+1)/2),:) = Arow;
end

12.6 Result:
Output
A=
1.0000 1.0000 0.5000
1.0000 -0.2500 -0.1250

B=
1.0000 -0.0000 9.0000
1.0000 -3.0000 2.0000

b0 = 0.0625
12.7 Expected Block Diagram:
The Digital FIR Low pass filter structure using Direct to Cascade form is as shown in Fig.12.2

Department of Electrical & Electronics Engineering, B.N.M.I.T 76


Digital Signal Processing Lab Manual

Fig 12.2 Digital FIR Low pass filter structure using Direct to Cascade form

12.8 EXERCISE PROBLEMS:


1. For the given difference equation determine the cascade form structure:
1 1
𝑦(𝑛) − 𝑦(𝑛 − 1) + 𝑦(𝑛 − 1) = 𝑥(𝑛) + 2𝑥(𝑛 − 1)
2 4
2. For the given difference equation determine the parallel form structure
16𝑦(𝑛) + 12𝑦(𝑛 − 1) + 2𝑦 − 4𝑦(𝑛 − 3) − 𝑦(𝑛 − 4) = 𝑥(𝑛) − 3𝑥(𝑛 − 1) +
11𝑥(𝑛 − 2) − 27𝑥(𝑛 − 3) + 18𝑥(𝑛 − 4)
12.9 CONCLUSION:
 These digital FIR and IIR filter structures help to determine the computational complexity for
the given system.
 The efficiency of implementation of these structures can be easily defined using linear phase
structures.

Department of Electrical & Electronics Engineering, B.N.M.I.T 77


Digital Signal Processing Lab Manual

13 REALIZATION OF A FIR FILTER TO MEET GIVEN SPECIFICATION USING DSP


KIT
13.1 Objective: To realize FIR filter to meet given specification using DSP kit
13.2 Theory: Refer to Section 10.2
13.3 CCStudio Procedure:
1. Click on the Desktop icon “Setup CCStudio v3.3”. Remove if any board connected.
2. Click factory board
3. Select family  67xx
4. Select platform  AHxds510USB emulator
5. Select device  C671x AHXDS510USB emulator
6. Click on add button and then Save & quit
7. Click yes to start CCStudio

Step1: Create a new project


Project  New
Project Name: ………..…..
Location: C:\CCStudio\my project\ ….
Project Type: Executable [.out]
Target: TMS320C67xx and Finish
Step 2: Create source file
File  New  Source file
Save the Source file in project folder
File  Save (with .C extension)

Step 3: Add source file to the project.


Project  Add file to project  <Source File>

Step 4: Add rts6700.lib


Project  Add files to project  rts6700.lib (or) rts6713.lib
Path: C:\CCstudio\c6000\cgtools\lib\rts6700.lib (or) rts6713.lib

Step 5: Compile
Project  compile file (Ctrl + F7)

Step 6: Build
Project  build (F7)
(This will create a .out file in project folder)
Step 7: Load the program

Department of Electrical & Electronics Engineering, B.N.M.I.T 78


Digital Signal Processing Lab Manual

File  load  select the .out in debug folder in project folder

Step 8: Run the program


Debug  Run (F5)

Step 9: To view the output graphically


Select View  Graph  Time and frequency.

13.4 ‘C’ PROGRAM WITH CC STUDIO:


#include<stdio.h>
#include<math.h>
#define pi 3.141592
float fp,fs,fsamp,As,wp,ws,wc,tw,win[100],h[100],hd[100];
int n,k,N,alpha;
void main()
{
printf("enter the passband frequency:");
scanf("%f",&fp);
printf("enter the stopband frequency:");
scanf("%f",&fs);
As=printf("enter the stopband attenuation in dB:");
scanf("%f",&As);
printf("enter the sampling frequency:");
scanf("%f",&fsamp);
wp=2*pi*fp/fsamp;
ws=2*pi*fs/fsamp;
wc=(wp+ws)/2;
tw=ws-wp;
if(As<=21)
k=2;
else if(As>21 && As<=53)
k=4;
else
k=6;

Department of Electrical & Electronics Engineering, B.N.M.I.T 79


Digital Signal Processing Lab Manual

N=ceil(2*pi*k/tw);
if((N%2)==0)
N=N+1;
printf(“%d”,N);
for(n=0;n<N;n++)
{
if(As<=21)
win[n]=1;
else if(As>21 && As<=53)
win[n]=0.54-0.46*cos(2*pi*n/(N-1));
else
win[n]=0.42-0.5*cos(2*pi*n/(N-1))+0.08*cos(4*pi*n/(N-1));
}
alpha=(N-1)/2;
for(n=0;n<N;n++)
{
if(n==alpha)
{
h[n]=wc/pi;
hd[n]=h[n]*win[n];

}
else
{
h[n]=sin(wc*(n-alpha))/(pi*(n-alpha));
hd[n]=h[n]*win[n];
}
}
printf("low pass filter coeffs:");
for(n=0;n<N;n++)
printf("%f\t",hd[n]);
}

Department of Electrical & Electronics Engineering, B.N.M.I.T 80


Digital Signal Processing Lab Manual

13.5 Simulation:
Enter the pass band frequency: 1500
Enter the stop band frequency: 2000
Enter the stop band attenuation in dB: 60
Enter the sampling frequency: 8000

N=97
Low pass filter coeffs:
0.000000 0.000003 0.000005 -0.000019 -0.000035 0.000036 0.000106
-0.000019 -0.000214 -0.000076 0.000330 0.000288 -0.000387 -
0.000631 0.000287 0.001069 0.000078 -0.001495
-0.000794 0.001722 0.001874 -0.001505 -0.003204 0.000584 0.004513

0.001229 -0.005364 -0.003961 0.005204 0.007384 -0.003450 -0.010958

-0.000378 0.013818 0.006517 -0.014812 -0.014845 0.012567 0.024826

-0.005469 -0.035534 -0.008675 0.045774 … …… …… ……..


13.6 Expected Waveform:
The magnitude response of the FIR Low pass filter is as shown in Fig.13.1. using rectangular
window technique.

Fig.13.1 Magnitude response of the FIR Low pass filter using rectangular window technique

Department of Electrical & Electronics Engineering, B.N.M.I.T 81

Anda mungkin juga menyukai