You are on page 1of 113

DSP Lab Manual TCL 56

DEPARTMENT OF TELECOMMUNICATION
ENGINEERING

DIGITAL SIGNAL PROCESSING LAB


LAB MANUAL
Vth Sem
TCL 56

In-charge Faculty
Mr. VENU K N
Mrs. Akshatha Kori

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Prerequisite Courses with codes: Signals & Systems (TC45)

Course Objectives
1. Understand the basic concepts of discrete-time signal processing like
sampling theorem.
2. Identify the concepts behind convolution, DFT & IDFT, auto correlation and
cross correlation.
3. Developing the solution for a difference equation and implement the same
by writing the program.
4. Identify the concepts behind FIR filters and design using different windows
like rectangular, hamming, hanning and Kaiser and implement the same
using matlab
5. Identify the concepts behind IIR filters and design the same using different
windows like rectangular, hamming, hanning and Kaiser and implement the
same using matlab

Course Outcomes
1. Analyze DSP concepts like Sampling theorem, convolution, DFT & IDFT,
correlation and solution for a difference equation on Mat-lab.
2. Computation of convolution and correlation.
3. Design of FIR filter by using different window methods.
4. Design IIR filter by using different window methods.
5. Design of FIR and IIR filters and implementation through DSP Processor.

Course
List of Experiments
Outcomes

Verification of sampling theorem. CO1


1

Impulse response of a given system CO1


2

Linear convolution of two given sequences. CO1


3

Circular convolution of two given sequences CO2


4

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Autocorrelation of a given sequence and


CO2
5
verification of its properties.
Cross correlation of given sequences and
CO2
6
verification of its properties.
Linear convolution of two sequences using DFT
and IDFT.
CO3
7
Circular convolution of two given sequences using
DFT and IDFT
Solving a given difference equation.
Computation of N point DFT of a given sequence CO3
8
and to plot magnitude and phase spectrum.

Design and implementation of FIR filter to meet


CO4
9 given specifications

Design and implementation of IIR filter to meet


CO4
10
given specifications.
Linear convolution of two given sequences using
radix-2 algorithm.
CO5
11
Circular convolution of two given sequences using
radix-2 algorithm

Computation of N- Point DFT of a given sequence.


Realization of an FIR filter (any type) to meet
CO5
12
given specifications. The input can be a signal
from function generator / speech signal

Computation of DFT and FFT of a given sequence CO5


13

Realization of an FIR and IIR filter to meet given


CO5
14
specifications.

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

COURSE DESIGN, DELIVERY AND ASSESMENT

Course Code and Title : Digital Signal Processing Lab, Course Credits : 0:0:1
TCL506
CIE : 50 Marks SEE : 50 Marks
Total No of Lab Hours : 24, No. of sessions: 12
Prepared by : Umesharaddy Date :31/08/2020
Reviewd by : Dr. B K Sujatha Date :31/08/2020

Prerequisites

Prerequisite Courses with codes : Signals & Systems(TC405)

Course Objectives
1. Understand the basic concepts of discrete-time signal processing like
sampling theorem.
2. Identify the concepts behind convolution, DFT & IDFT, auto correlation and
cross correlation.
3. Developing the solution for a difference equation and implement the same
by writing the program.
4. Identify the concepts behind FIR filters and design using different windows
like rectangular, hamming, hanning and Kaiser and implement the same
using matlab
5. Identify the concepts behind IIR filters and design the same using different
windows like rectangular, hamming, hanning and Kaiser and implement the
same using matlab

List of experiments:

Duratio
Sl No.
Topics n

1 Verification of sampling theorem. 2 hr

2 Impulse response of a given system 2 hr

3 Linear convolution of two given sequences. 2 hr

4 Circular convolution of two given sequences 2 hr

Autocorrelation of a given sequence and verification


5 2 hr
of its properties.

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Cross correlation of given sequences and verification


6 2 hr
of its properties.
Linear convolution of two sequences using DFT and
IDFT.
7 2 hr
Circular convolution of two given sequences using
DFT and IDFT
Solving a given difference equation.
8 Computation of N point DFT of a given sequence and 2 hr

to plot magnitude and phase spectrum.


Design and implementation of FIR filter to meet given
9 2 hr
Specifications

Design and implementation of IIR filter to meet given


10 2hr
specifications.

Linear convolution of two given sequences using


radixz2 algorithm.
11 2hr
Circular convolution of two given sequences using
radix-2 algorithm

Computation of N- Point DFT of a given sequence


Realization of an FIR filter (any type) to meet given
12 2hr
specifications. The input can be a signal from
function generator / speech signal
13 Computation of DFT and FFT of a given sequence 2hr

Realization of an FIR and IIR filter to meet given


14 2hr
specifications.
REFERENCE BOOKS:

1. Oppenheim & Schaffer, Discrete Time Signal Processing, PHI, 2003.


2. Proakis & Monalakis, Digital signal processing - Principles Algorithms &
Applications, Pearson education, 4th Edition, New Delhi, 2007.
3. S. K. Mitra, Digital Signal Processing, Tata Mc-Graw Hill, 2nd Edition, 2004.

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

4. Dr.D. Ganesh Rao, Vineeta P Gejji, Digital Signal Processing-, 2E,


Sanguine Technical Publications.

Course Outcomes
1. Analyze DSP concepts like Sampling theorem, convolution, DFT & IDFT,
correlation and solution for a difference equation on Mat-lab.
2. Computation of convolution and correlation.
3. Design of FIR filter by using different window methods.
4. Design IIR filter by using different window methods.
5. Design of FIR and IIR filters and implementation through DSP Processor.

SUBJECT WILL MAP TO PEO1, PEO2 AND PEO3.

Course Delivery:
The Course will be delivered through black board teaching, exercises, self-study and
demonstrations.

Course Assessment and Evaluation:

What To When/ Where Max Evidence Contributing


whom (Frequency in marks collected to Course
the course) Outcomes
Twice
Internal
(Average of two 20 Blue books C01-C05
assessment
tests)
Every lab
Direct Assessment Methods

session Lab Records,


Record &
CIE (Average of the 20 Observation C01-C05
Observation
all-experiment Books
marks)
Students Twice
(Summation of
Viva viva conducted 10 Bluebooks C01-C05
during two
tests)
End of course
Semester
(Answering 1
SEE End 50 Answer scripts C01-C05
Lab
examination
Experiment)
CO1 – CO5
Indire

sment
Asses

Meth

End of the Feedback


ods

Student’s feedback
ct

Students -
course forms

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Feedback
End of course - C01-C05
Course survey forms

Mapping Course Outcomes with Program Outcomes:

Course Programme Outcomes (PO) Program Specific


Outcomes Outcomes (PSO)

1 2 3 4 5 6 7 8 9 10 11 12 1 2 3

1. 3 3 - 1 2 - - - 2 - - 2 1 1

2. 3 3 - 1 2 - - - 2 - - 2 1 1

3. 3 2 - 2 3 - - - 2 - - 2 1 1

4. 3 3 - 1 2 - - - 2 1 1 2 2 1 2

5. 3 3 - 1 2 - - - 1 - 1 2 2 1 1

Overall 3 3 - 2 3 - - - 2 1 1 1 2 1 2

Justification for CO-PO mapping:

1) CO1 maps to PO1,2,4,5, 9

a. PO1: DFT - IDFT and their properties are derived requiring


mathematics and engineering concepts.
b. PO2: DFT & FFT(both DIT-FFT & DIF-FFT) include complex problems
that need analysis. So, the ability to formulate and analyze such
problems is dealt in the course.
c. PO5: Modern tool such as matlab simulation tool was used.

d. PO9: CO1 gives an ability to work effectively as an individual and


members or leader in diverse and multi-disciplinary teams

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

2) CO2 maps to PO1,2,4 ,5, 9


a. PO1: The knowledge of Symmetry & Anti Symmetry conditions for
linear phase of FIR filters require a good engineering background as
well as a foundation in mathematics.
b. PO2: Analysis of linear phase in FIR filters allow a student to simplify
a complex engineering problems.
c. PO3: With the design of FIR & IIR filters, the specified needs with
societal considerations are met.
d. PO4: The ability to analyze, design complex engineering problems are
dealt here.
e. PO5: Modern tool such as matlab simulation tool was used.
f. PO9: CO2 gives an ability to work effectively as an individual and
members or leader in diverse and multi-disciplinary teams

3) CO3 maps to PO1,2,4,5, 9

a. PO1: The realization of FIR & IIR filters require a good engineering
and science (modeling) background as well as a foundation in
mathematics.
b. PO2: Use of partial differential equations to solve IIR filter
expressions allow a deeper understanding of complex problems.
c. PO3: With the structures of FIR & IIR filters, the specified needs with
societal, environmental considerations are met.
d. PO4: In realizing both FIR & IIR filters, students will be able to
analyze complex engineering problems.
e. PO5: Modern tool such as matlab simulation tool was used.
f. PO9: CO3 gives an ability to work effectively as an individual and
members or leader in diverse and multi-disciplinary teams

4) CO4 maps to PO1,2,4,5, 9,10,11,12


a. PO1: Data representation & arithmetic in Harvard architecture for
signal processing require a good engineering background as well as
a foundation in mathematics.
b. PO2: Pipelining-Harvard and data representations allow a deeper
understanding of complex engineering problems.

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

c. PO4: Various processing like Extended parallelism and static super


scalar processing gives the ability for a student to analyze & design
complex engineering problems.
d. PO5: Modern tool such as matlab simulation tool was used.
e. PO9: CO4 gives an ability to work effectively as an individual and
members or leader in diverse and multi-disciplinary teams
f. PO10: The concepts of implementing applications on DSP processor
and communicating with peers requires effective reporting and
design documents
g. PO11: Knowledge of fixed point & floating processors & their
structure is a basic requirement for any career in communication
and electrical sciences
h. PO12: DSP projects are implemented on DSP processor hence proper
project planning and managing skills are required

5) CO5 maps to PO1,2,,4,5, 9,10,11,12


a. PO1: The architecture of 67x require a good engineering background
as well as a foundation in mathematics
b. PO2: The various addressing modes allow a student to simplify
complex engineering problems.
c. PO4: In implementing both FIR & IIR filters, students will be able to
analyze complex engineering problems.
d. PO5: Modern tool such as matlab simulation tool was used.
e. PO9: CO4 gives an ability to work effectively as an individual and
members or leader in diverse and multi-disciplinary teams
f. PO10: The concepts of implementing applications on DSP processor
and communicating with peers requires effective reporting and
design documents
g. PO11: Knowledge of fixed point & floating processors & their
structure is a basic requirement for any career in communication
and electrical sciences
h. PO12: DSP projects are implemented on DSP processor hence proper
project planning and managing skills are required

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM FOR GENERATING VARIOUS FORMS OF SIGNALS

PROGRAM:
%UNIT IMPULSE SIGNAL

y1=[1;zeros(999,1)];
subplot(4,3,1)
plot(y1,'r');
%axis([-1 500 -1.5 1.5 ]);------------->not required
xlabel('time(sec)')
ylabel('amplitude')
title('unit impulse signal');

%UNIT STEP SIGNAL


y2=ones(100,1);
subplot (4,3,2);
plot(y2,'b');
%axis([-5 200 -0.25 1.25 ]);------------->not required
xlabel('time(sec)')
ylabel('amplitude')
title('unit step signal');

%RAMP SIGNAL
t=(0:0.001:1);
y3=t;
subplot(4,3,3)
plot(y3,'b');
%axis([-200 1200 -0.5 1.5 ]);------------->not required
xlabel('time(sec)')
ylabel('amplitude')
title('ramp signal');

%SINE WAVE SIGNAL


y3=-pi:0.001:pi;
subplot(4,3,4:6);
plot(y3,sin(y3));
%axis([-5 5 -1.5 1.5 ]);------------->not required
xlabel('time(sec)')
ylabel('amplitude')
title('sine wave signal');

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

%EXPONENTIAL SIGNAL
t=(0:0.001:1);
y5=t.^2;
subplot(4,3,7:9)
plot(y5,'r');
%axis([-200 1200 -0.5 1.5 ]);------------->not required
xlabel('time(sec)')
ylabel('amplitude')
title('exponential signal');

%SQUARE WAVE SIGNAL


t=(0:0.001:1);
y6=square(4*t,50);
subplot(4,3,10:12)
plot(y6,'r');
%axis([-200 1200 -1.5 1.5 ]);------------->not required
xlabel('time(sec)')
ylabel('amplitude')
title('square signal');

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

OUTPUT:
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM TO PROVE SAMPLING THEOREM FOR A


SINUSOIDAL INPUTS

THEORITICAL CALCULATION:
1. COSINE
Input Signal = cos (2π 150t)

Frequency = 150 Hz

INPUT WAVEFORM

EXPECTED WAVEFORM

2. SINE
Input Signal = sin (2π 150t)

Frequency = 150 Hz

INPUT WAVEFORM

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
1. COSINE WAVEFORM
%UNDER SAMPLED SIGNAL
tfinal=0.05;
t=0:0.00005:0.05;
fa=input('enter analog frequency(in Hz):');
%Generate analog signal for the given frequency
xt=cos(2*pi*fa*t);
%condition considered for under sampling is fs is 1.3 times fmax
instead of 2 times of fmax
fs1=1.3*fa;
n1=0:1/fs1:tfinal;
%generate undersampled signal
xn1=cos(2*pi*fa*n1);
%desired frequency is fs is 1.3 times fmax
subplot(3,1,1);
plot(t,xt,'b',n1,xn1,'r*-');
title ('undersampled signal');

%OVER SAMPLED SIGNAL


%condition considered for over sampling that fs is 15 times fmax
instead of 2 times of fmax
fs1=15*fa;
n2=0:1/fs1:tfinal;
%generate oversampled signal
xn2=cos(2*pi*fa*n2);
%desired frequency is fs is 5 times fmax
subplot(3,1,2);
plot(t,xt,'b',n2,xn2,'r*-');
title ('oversampled signal');

%NYQUIST RATE SAMPLED SIGNAL


%condition for nyquist rate sampling is that fs is 2 times of fmax
fs1=2*fa;
n3=0:1/fs1:tfinal;
%generate oversampled signal
xn3=cos(2*pi*fa*n3);
%desired frequency is fs is 5 times fmax
subplot(3,1,3);
plot(t,xt,'b',n3,xn3,'r*-');
title ('nyquist rate sampled signal');

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

2. SINE WAVEFORM
%UNDER SAMPLED SIGNAL
tfinal=0.05;
t=0:0.00005:0.05;
fa=input('enter analog frequency(in Hz):');
%Generate analog signal for the given frequency
xt=sin(2*pi*fa*t);
%condition considered for under sampling is fs is 1.3 times fmax
instead of 2 times of fmax
fs1=1.3*fa;
n1=0:1/fs1:tfinal;
%generate undersampled signal
xn1=sin(2*pi*fa*n1);
%desired frequency is fs is 1.3 times fmax
subplot(3,1,1);
plot(t,xt,'b',n1,xn1,'r*-');
title ('undersampled signal');

%OVER SAMPLED SIGNAL


%condition considered for over sampling that fs is 15 times fmax
instead of 2 times of fmax
fs1=15*fa;
n2=0:1/fs1:tfinal;
%generate oversampled signal
xn2=sin(2*pi*fa*n2);
%desired frequency is fs is 5 times fmax
subplot(3,1,2);
plot(t,xt,'b',n2,xn2,'r*-');
title ('oversampled signal');

%NYQUIST RATE SAMPLED SIGNAL


%condition for nyquist rate sampling is that fs is 2 times of fmax
fs1=2*fa;
n3=0:1/fs1:tfinal;
%generate oversampled signal
xn3=sin(2*pi*fa*n3);
%desired frequency is fs is 5 times fmax
subplot(3,1,3);
plot(t,xt,'b',n3,xn3,'r*-');
title ('nyquist rate sampled signal');

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

OUTPUT:

COSINE WAVE
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

SINE WAVE
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: LINEAR CONVOLUTION OF TWO SEQUENCES USING


PROPERTIES OF DFT AND IDFT

THEORITICAL CALCULATION:
Let x1(n)={1,1,2} ={1,1,2,0} &

x2(n)={1,2}={1,2,0,0}
𝑁−1
DFT of x(n) = X(k) = ∑𝑛=0 𝑥(𝑛)𝑊𝑁𝑘𝑛 ;0≤ 𝑘 ≤N-1

X(k) = 𝑥 (0)𝑊4𝑘0 + 𝑥 (1)𝑊4𝑘1 + 𝑥(2)𝑊4𝑘2 + 𝑥 (3)𝑊4𝑘3 ;0≤ 𝑘 ≤3

For sequence one,

X1(k)= 1 + 1𝑊4𝑘1 + 2𝑊4𝑘2 + 0𝑊4𝑘3 ; 0≤ 𝑘 ≤3

For sequence two,

X2(k)= 1 + 2𝑊4𝑘1 + 0𝑊4𝑘2 + 0𝑊4𝑘3 ; 0≤ 𝑘 ≤3

TWIDDLE FACTOR
2𝜋
𝑊4𝑘𝑛 = ⅇ −𝑗 𝑁

𝑊40 = 1; 𝑊41 = −𝑗; 𝑊42 = −1; 𝑊43 = 𝑗

OUTPUT

K X1(k) X2(k)
0 1+1(1)+2(1)=4 1+2(1)=3
1 1+1(-j)+2(-1)=-1-j 1+2(-j)=1-2j
2 1+1(-1)+2(1)=2 1+2(-1)=-1
3 1+1(j)+2(-1)= -1+ j 1+2(j)=1+2j

X1(k)={4,-1- j,2,-1+ j}

X2(k)={3,1- 2j,-1,1+2j}

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Linear convolution in time domain is given by y(n)=x(n)*h(n)

Linear convolution in K-domain is given by Y(k)= X(k) H(k)

Therefore for the desired result Y(k)= X1(k) X2(k)

Y(k) = {(4)(3) (-1- j)( 1- 2j) (2)(-1) (-1+ j)( 1+2j) }

Therefore , Y(k) = {12,-3+1i,-2,-3-1i}


1 𝑁−1
IDFT of X(k) = x(n) = ∑𝑘=0 𝑋(𝑘 )𝑊𝑁−𝑘𝑛 ; 0≤ 𝑛 ≤N-1
𝑁

1 3
y(n)= ∑𝑘=0 𝑋(𝑘 )𝑊4−𝑘𝑛 ; 0≤ 𝑛 ≤N-1
4

1
y(n) = { 𝑌 (0)𝑊4−0𝑛 + 𝑌(1)𝑊4−1𝑛 + 𝑌(2)𝑊4−2𝑛 + 𝑌(3)𝑊4−3𝑛 } ; 0≤ 𝑛 ≤N-1
4

TWIDDLE FACTOR
2𝜋
𝑗
𝑊4−𝑘𝑛 =ⅇ 𝑁

𝑊40 = 1; 𝑊4−1 = 𝑗; 𝑊4−2 = −1; 𝑊4−3 = −𝑗

OUTPUT

n y(n)
1
0 {12+(-3+1i)(1)+(-2)(1)+( -3-1i)(1)}=1
4
1
1 {12+(-3+1i)(j)+(-2)(-1)+( -3-1i)(-j)}=3
4
1
2 {12+(-3+1i)(-1)+(-2)(1)+( -3-1i)(-1)}=4
4
1
3 {12+(-3+1i)(-j)+(-2)(-1)+( -3-1i)(j)}=1
4

y(n)={1,3,4,4}

The required sequence is given by y(n)={1,3,4,4}

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
%LINEAR CONVOLUTION OF TWO SEQUENCES USING DFT
AND IDFT

x1=input('Enter first sequence = ');


x2=input('Enter second sequence = ');
N=length(x1)+length(x2)-1;
X1=fft(x1,N);
disp('DFT of first sequence = ');
disp(X1);
X2=fft(x2,N);
disp('DFT of second sequence = ');
disp(X2);
Y=X1.*X2;
%TO OBTAIN DESIRED RESULT EACH ELEMENT OF FIRST VECTOR IS TO
MULTIPLIED WITH EACH TERM IN SECOND VECTOR SEPARATELY.

disp('DFT of the Linear convolution of the two sequences');


disp(Y);
y=ifft(Y,N);
disp('Linear convolution using DFT and IDFT');
disp(y);
n=0:1:N-1;
subplot(1,1,1);
stem(n,y);
xlabel('Time index n');
ylabel('Amplitude');
title('Linear convolution using DFT and IDFT');

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

OUTPUT:
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM TO FIND LINEAR CONVOLUTION WHEN THE


GIVEN SEQUENCE IS SINGLY SIDED i.e. RIGHT SIDED

THEORITICAL CALCULATION:
Let the two single sided sequences be x1(n) is {2, 3, 4} & x2(n) is {1, 2, 1}
i.e. x1(n) is {2,3,4} &
x2(n) is {1,2,1}

* 2 3 4
1 2 3 4
2 4 6 8
1 2 3 4
y(n) = x(n)*h(n)

Therefore the required result after single sided linear convolution is


y(n) = { 2,7,12,11,4 }

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
%SINGLE SIDED LINEAR CONVOLUTION
X1=input('Enter the first sequence =');
X2=input('Enter the second sequence =');
y=conv(X1,X2);
disp('Linear convolution of X1 and X2 is y =');
disp(y);
subplot(2,1,1);
stem(y);
xlabel('Time index n');
ylabel('Amplitude');
title('Convolution output');
subplot(2,2,3);
stem(X1);
xlabel('Time index n');
ylabel('Amplitude');
title('Plot of X1');
subplot(2,2,4);
stem(X2);
xlabel('Time index n');
ylabel('Amplitude');
title('Plot of X2');

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

OUTPUT:
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM TO FIND LINEAR CONVOLUTION WHEN THE


GIVEN SEQUENCE IS DOUBLY SIDED i.e. LEFT AND RIGHT
SIDED

THEORITICAL CALCULATION:

* 1 2 3 2 1 3 4
2 2 4 6 4 2 6 8
-3 -3 -6 -9 -6 -3 -9 -12
4 4 8 12 8 4 12 16
-1 -1 -2 -3 -2 -1 -3 -4
0 0 0 0 0 0 0 0
1 1 2 3 2 1 3 4
Therefore the required result after double sided linear convolution is

y(n)={2,1,4,2,6,9,3,2,15,-3,3,4}

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
%DOUBLE SIDED LINEAR CONVOLUTION
X1 =input('Enter the first sequence =');
x1=input('Enter position of zero in the first sequnce = ');
%enter position considering first term as zero not 1.
disp('sequence 1');
disp(X1);
n1 =(length(X1)-(length(X1)+x1)):(length(X1)-(x1+1));
%the above statement helps in determining the range of values
that is taken up by n1
X2 =input('Enter the second sequence =');
x2=input('Enter position of zero in the second sequnce =
');
n2 = (length(X2)-(length(X2)+x2)):(length(X2)-(x2+1));
%the above statement helps in determining the range of values
that is taken up by n2
disp('sequence 2');
disp(X2);
ybegin = n1(1)+n2(1);
yend = n1(length(X1))+n2(length(X2));
ny=[ybegin:yend];
y=conv(X1,X2);
disp('Linear convolution of the two sequence');
disp(y);
subplot(3,2,1:2);
stem(ny,y);
xlabel('Amplitude');
ylabel('Time index n');
title('Convolution output');
subplot(3,2,3:4);
stem(n1,X1);
xlabel('Amplitude');
ylabel('Time index n');
title('Plot of input X1');
subplot(3,2,5:6);
stem(n2,X2);
xlabel('amplitude');
ylabel('time index n');
title('Plot of input X2');

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

OUTPUT:
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM TO DETERMINE OUTPUT RESPONSE OF A


DIFFERENCE EQUATION FOR THE FOLLOWING INPUTS

1. COSINE INPUT
2. IMUPLSE INPUT
3. UNIT STEP INPUT

THEORITICAL CALCULATION:
 A difference equation with constant coefficient describes a LTI system.
 Difference equation containing past samples of output leads to recursive
system, whose impulse response is of infinite duration(IIR).for such systems
the impulse response is computed for large value of ‘n’ (say 100).
 The function ‘filter’ evaluates the convolution of an infinite sequence (IIR)
and x[n], which isn’t possible with ‘conv’ function as it requires both the
sequence to be finite.
 The difference equation having only y[n] and present and past samples of
input, represents a system whose impulse response is finite in nature hence
both functions ‘filter’ and ‘conv’ can be used.

Let the difference equation be given by:

y(n)-1.5y(n-1)+y(n-2)=2x(n-2

Therefore,
Y(z)
H(z) =
X(z)
Y(z) 2z−2
H(z) = =
X(z) 1−1.5z−1 +1z−2

Y(z)=X(z)H(z)

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Number of samples at output = 100

1. COSINE INPUT

x(n) = cos(0.05Πn) ; 0 ≤ n ≤N-1

1−z−1 cos(0.05Π)
X(z) = ROC ∈ ∀ |𝑧|>1
1−2z−1 cos(0.05Π)+z−2

1−z−1cos(0.05Π) 2z−2
Y(z) = x 1−1.5z−1+1z−2
1−2z−1 cos(0.05Π)+z−2

2. IMPULSE INPUT

x(n) = 𝛿 (n) ; 0 ≤ n ≤N-1

X(z) = 1 ROC ∈ ∀ z
2z−2
Y(z) = 1 x
1−1.5z−1 +1z−2

3. UNIT STEP INPUT

x(n) = u(n) ; 0 ≤ n ≤N-1


1
X(z) = ROC ∈ ∀ |𝑧|>1
1−z−1
1 2z−2
Y(z) = x
−1 1−1.5z−1 +1z−2
1−z

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
%DIFFERENCE EQUATION-COSINE INPUT
N=input('The length of the impulse response required: ');
b=input('The co-efficients of numerator: ');
a=input('The co-efficients of denominator: ');
n=0:N-1;
x=cos(0.05*pi*n);
h=filter(b,a,x);
subplot(211);
stem(n,x);
xlabel('Time index n');
ylabel('Amplitude');
title('cosine input');
subplot(212);
stem(n,h);
xlabel('Time index n');
ylabel('Amplitude');
title('Cosine input response');

%DIFFERENCE EQUATION-IMPULSE INPUT

N=input('The length of the impulse response required: ');


b=input('The co-efficients of numerator: ');
a=input('The co-efficients of denominator: ');
n=0:N-1;
x=[1,zeros(1,N-1)];
h=filter(b,a,x);
subplot(211);
stem(n,x);
xlabel('Time index n');
ylabel('Amplitude');
title('Impulse input');
subplot(212);
stem(n,h);
xlabel('Time index n');
ylabel('Amplitude');
title('Impulse input response');

%DIFFERENCE EQUATION-UNIT STEP INPUT


N=input('The length of the unit response required: ');
b=input('The co-efficients of numerator: ');
a=input('The co-efficients of denominator: ');

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

n=0:N-1;
x=ones(1,N);
h=filter(b,a,x);
subplot(211);
stem(n,x);
xlabel('Time index n');
ylabel('Amplitude');
title('Unit input');
subplot(212);
stem(n,h);
xlabel('Time index n');
ylabel('Amplitude');
title('Unit input response');

OUTPUT:
COSINE INPUT
WORKSPACE

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

COMMAND WINDOW

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

IMPULSE INPUT
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

UNIT STEP INPUT


WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM TO DETERMINE DFT OF A GIVEN SEQUENCE AND


SHOWCASE ITS MAGNITUDE AND PHASE SPECTRUM

THEORITICAL CALCULATION:
 Discrete Fourier Transform (DFT) is used for performing frequency analysis
of discrete time signals.
 DFT gives a discrete frequency domain representation whereas the other
transformations are continuous in frequency domain.
 N point DFT of discrete time signals x (n) is given by
𝑁−1
DFT of x (n) = X (k) = ∑𝑛=0 𝑥 (𝑛)𝑊𝑁𝑘𝑛 ; 0≤ 𝑘 ≤N-1
2𝜋
, where 𝑊𝑁𝑘 is called as Twiddle factor given by 𝑊4𝑘𝑛 = ⅇ −𝑗 𝑁

Determine DFT of {1, 1, 0, and 0} and showcase its magnitude and phase
spectrum.

Let x (n) = {1, 1, 0, 0}

X (k) = 𝑥 (0)𝑊4𝑘0 + 𝑥 (1)𝑊4𝑘1 + 𝑥 (2)𝑊4𝑘2 + 𝑥(3)𝑊4𝑘3 ; 0≤ 𝑘 ≤3

For sequence one,

X (k) = 1 + 1𝑊4𝑘1 + 0𝑊4𝑘2 + 0𝑊4𝑘3 ; 0≤ 𝑘 ≤3

TWIDDLE-FACTOR
2𝜋𝑛
𝑊4𝑘𝑛 = ⅇ −𝑗 𝑁

𝑊40 = 1; 𝑊41 = −𝑗; 𝑊42 = −1; 𝑊43 = 𝑗

OUTPUT

K X(k)
0 1+1(1)=2
1 1+1(-j)=-1-j
2 1+1(-1)=0

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

3 1+1(j)= 1+ j

Therefore the required result after linear convolution is y(n)= {2,1-j,0,1+j}

Magnitude = √ ((real part) 2+ (complex part) 2)

X(k) |X(k)|
2 2
1-j √2
0 0
1+j √2
−1
Phase = tan (complex part/ real part)

X(k) phase
2 0
1-j −𝜋/2
0 0
1+j 𝜋/2

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
%DFT OF A GIVEN SEQUENCE

x1=input('Enter the sequence:');


N=input('Enter the length:');
X=fft(x1,N);
%DFT of the given sequence found using function 'fft'
disp('DFT of the given sequence is ');
disp(X);
n=0:1:N-1;

subplot(2,1,1);
p=abs(X);
disp('amplitude of each term in DFT of the given sequence is ');
disp(p);
%magnitude of each term in DFT
stem(n,p);
xlabel('length');
ylabel('magnitude of X(k)');
title('magnitude spectrum');

q=angle(sym(X));
%if q=angle(X);is used instead of q=angle(sym(X));the phase
angle retrned
%is term of absolute value not in terms of 'PI'

%phase angle of each term in DFT


disp('phase angle of each term in DFT of the sequence is');
disp(q);
subplot(2,1,2);
stem(n,q);
xlabel('length');
ylabel('phase of X(k)');
title('angle spectrum');

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

OUTPUT:
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM FOR CORSS –CORRELATION AND AUTO


CORRELATION

THEORITICAL CALCULATION:
According to Cross-correlation
−∞
rxy(l)= ∑𝑛=∞ 𝑥(𝑛)y(n − l) ; l = ±1, ±2, ±3, ±4, ±5, ±6, ±7 ….

OR
−∞
rxy(l)= ∑𝑛=∞ 𝑥(𝑛 + 𝑙)y(n) ; l = ±1, ±2, ±3, ±4, ±5, ±6, ±7 ….

Similarly,
−∞
ryx(l)= ∑𝑛=∞ 𝑦(𝑛)x(n − l) ; l = ±1, ±2, ±3, ±4, ±5, ±6, ±7 ….

OR
−∞
ryx(l)= ∑𝑛=∞ 𝑦(𝑛 + 𝑙)x(n) ; l = ±1, ±2, ±3, ±4, ±5, ±6, ±7 ….

Therefore,

rxy(l)= ryx(-l)

We know that,
−∞
X(n)*H(n)= ∑𝑚=∞ 𝑥 (𝑛)y(n − m)
−∞ −∞
Therefore, rxy(l)= ∑𝑛=∞ 𝑥(𝑛)y(n − l) = ∑𝑛=∞ 𝑥 (𝑛)y(−(l − n)) ;

l = ±1, ±2, ±3, ±4, ±5, ±6, ±7 ….

ryx(l)= x(l)*y(-l)

Cross-correlation calculates correlation between two different sequences of a


random process and Autocorrelation is handled as a special case of cross-
correlation.

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

1.CROSS-CORRELATION

x(l)= [2 -1 3 7 1 2 -3]

y(-l)= [5 -2 1 4 -2 2 -1 1]

ryx(l)= x(l)*y(-l)

2 -1 3 7 1 2 -3

5 -2 1 4 -2 2 -1 1

2 -1 3 7 1 2 -3

-2 1 -3 -7 -1 -2 3 x

4 -2 6 14 2 4 -6 x x

4 -2 6 14 2 4 -6 x x x

8 -4 12 28 4 8 -12 x x x x

2 -1 3 7 1 2 -3 x x x x x

4 -2 6 14 2 4 -6 x x x x x x

10 -5 15 35 5 10 -15 x x x x x x x

10 -9 19 36 -14 33 0 7 13 -18 16 -7 5 -3

ANSWER:

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

2.AUTOCORRELATION

x(l)= [1 2 3 4]

x(-l)= [4 3 2 1]

ryx(l)= x(l)*x(-l)

1 2 3 4

4 3 2 1

1 2 3 4

2 4 6 8 x

3 6 9 12 x x

4 8 12 16 x x x

4 11 20 30 20 11 4

ANSWER:

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
%GENERAL PROGRAM FOR CROSS CORRELATION
X1 = input('Enter the first sequence = ');
x1=input('Enter position of zero in the first sequnce = ');
%enter position assuming that the leftmost element is beginings as zero and
%the position of zero in the sequence is with respect to this leftmost
element

n1 =(length(X1)-(length(X1)+x1)):(length(X1)-(x1+1));
%(x1+1)is subtracted instead of x1 as position numbering begins from with a
%zero

X2 = input('Enter the second sequence = ');


x2=input('Enter position of zero in the second sequnce = ');
n2 = (length(X2)-(length(X2)+x2)):(length(X2)-(x2+1));
%(x2+1)is subtracted instead of x1 as position numbering begins from with a
%zero
ybegin = n1(1)-n2(length(X2));
%n1(1)is the first element of vector n1
%n2(length(X2) is the last element of vector n2

%notice values of (n1(1)),(n2(length(X2)-1)),ybegin),yend in the workspace

if length(X2)==length(X1)
yend =ybegin+(length(X2)+length(X1))-2;
%this involves subtraction with 2 as yend is found with respect to
%ybegin(which is by itself a position)i.e
%[((length(X2)+length(X1))-1)-1]

else
yend =ybegin+(length(X2)+length(X1))-2+abs((length(X1)-length(X2)));
%although yend=ybegin+(length(X2)+length(X1))-(length(X1)-
length(X2))equals to
%one extra term than required ,its used to accomodate one extra zero
%seen at right most end of plot

end
ny=[ybegin:yend];
if length(X1)>length(X2)
X2=[zeros(1,abs((length(X1)-length(X2)))) X2];
end
%concatenation of 2 matrices
[r,lag]=xcorr(X1,X2);

disp('The cross correlated O/P is as following:');


disp(r);
stem(ny,r);
xlabel('Position');
ylabel('Cross correlated O/P');
title('Cross correlation');

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

OUTPUT:
CROSS-CORRELATION
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AUTOCORRELATION
WORKSPACE

COMMAND WINDOW

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM TO FIND CIRCULAR CONVOLUTION WHEN THE


GIVEN SEQUENCES ARE

1. EQUAL IN LENGTH
2. UNEQUAL IN LENGTH

THEORITICAL CALCULATION:
1. EQUAL IN LENGTH

Let x1(n)= {1,1,2,1} and x2(n)= {1,2,3,4}

N x1(n) x2(n-m)4 SUM


1 1,1,2,1 1,4,3,2 1+4+6+2=13
2 1,1,2,1 2,1,4,3 2+1+8+3=14
3 1,1,2,1 3,2,1,4 3+2+2+4=11
4 1,1,2,1 4,3,2,1 4+3+4+1=12

ANSWER : (13, 14, 11, 12)

2. UNEQUAL IN LENGTH

Let x1(n)= {1,1,2,1,3} and x2(n)= {1,2,3,4}

N x1(n) x2(n-m)5 SUM


1 1,1,2,1,3 1,0,4,3,2 1+0+8+3+6=18
2 1,1,2,1,3 2,1,0,4,3 2+1+0+4+9=16
3 1,1,2,1,3 3,2,1,0,4 3+2+2+0+12=19
4 1,1,2,1,3 4,3,2,1,0 4+3+4+1+0=12
5 1,1,2,1,3 0,4,3,2,1 0+4+6+2+3=15

ANSWER : (18,16,19,12,15)

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
%GENERAL CIRCULAR CONVOLUTION PROGRAM
X1=input('Enter the first sequence:');
X2=input('Enter the second sequence:');
if length(X1)>length(X2)
b=length(X1);
else
b=length(X2);
end
%b is the length of the largest sequence of the two

y = cconv(X1,X2,b);

%b is required in this as a parameter otherwise the result


consists of
%length(a)+length(B)-1 terms
disp('Linear convolution of X1 and X2 is y =');
disp(y);
subplot(2,2,1:2);
stem(y);
xlabel('Time index n');
ylabel('Amplitude');
title('Convolution output');
subplot(2,2,3);
stem(X1);
xlabel('Time index n');
ylabel('Amplitude');
title('Plot of X1');
subplot(2,2,4);
stem(X2);
xlabel('Time index n');
ylabel('Amplitude');
title('Plot of X2');

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

OUTPUT:
EQUAL LENGTH
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

UNEQUAL LENGTH
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM TO DETERMINE CIRCULAR CONVOLUTION USING


DFT AND IDFT GIVEN THE SEQUENCES ARE

1. EQUAL IN LENGTH
2. UNEQUAL IN LENGTH

THEORITICAL CALCULATION:
1. EQUAL

Let x1(n)={1,1,2,1} and x2(n)={1,2,3,4}


𝑁−1
DFT of x(n) = X(k) = ∑𝑛=0 𝑥(𝑛)𝑊𝑁𝑘𝑛 ; 0≤ 𝑘 ≤N-1

X (k) = 𝑥 (0)𝑊4𝑘0 + 𝑥 (1)𝑊4𝑘1 + 𝑥(2)𝑊4𝑘2 + 𝑥 (3)𝑊4𝑘3 ;0≤ 𝑘 ≤3

For sequence one,

X1(k) = 1 + 1𝑊4𝑘1 + 2𝑊4𝑘2 + 1𝑊4𝑘3 ; 0≤ 𝑘 ≤3

For sequence two,

X2(k) = 1 + 2𝑊4𝑘1 + 3𝑊4𝑘2 + 4𝑊4𝑘3 ; 0≤ 𝑘 ≤3

Therefore, Y (k) = X1(k) X2(k)

Y (k) =(1 + 12) + (3 + 11)𝑊4𝑘1 + (7 + 4)𝑊4𝑘2 + 12𝑊4𝑘3 ; 0≤ 𝑘 ≤3

Y (k) =13+14𝑊4𝑘1 + 11𝑊4𝑘2 + 12𝑊4𝑘3 ; 0≤ 𝑘 ≤3

ANSWER : (13,14,11,12)
TWIDDLE FACTOR
2𝜋
𝑊4𝑘𝑛 = ⅇ −𝑗 𝑁

𝑊40 = 1; 𝑊41 = −𝑗; 𝑊42 = −1; 𝑊43 = 𝑗

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

2. UNEQUAL

Let x1(n)={1,1,0,0} and x2(n)={1,2,0}


𝑁−1
DFT of x(n) = X(k) = ∑𝑛=0 𝑥(𝑛)𝑊𝑁𝑘𝑛 ; 0≤ 𝑘 ≤N-1

X (k) = 𝑥 (0)𝑊4𝑘0 + 𝑥 (1)𝑊4𝑘1 + 𝑥(2)𝑊4𝑘2 + 𝑥 (3)𝑊4𝑘3 ;0≤ 𝑘 ≤3

For sequence one,

X1(k) = 1 + 1𝑊4𝑘1 + 0𝑊4𝑘2 + 0𝑊4𝑘3 ; 0≤ 𝑘 ≤3

For sequence two,

X2(k) = 1 + 2𝑊4𝑘1 + 0𝑊4𝑘2 + 0𝑊4𝑘3 ; 0≤ 𝑘 ≤3

Therefore, Y (k) = X1(k) X2(k)

Y (k) = 1 + 3𝑊4𝑘1 + 2𝑊4𝑘2 + 0𝑊4𝑘3 ; 0≤ 𝑘 ≤3

ANSWER : (1,3,2,0)

TWIDDLE FACTOR
2𝜋
𝑊4𝑘𝑛 = ⅇ −𝑗 𝑁

𝑊40 = 1; 𝑊41 = −𝑗; 𝑊42 = −1; 𝑊43 = 𝑗

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
%CIRCULAR CONVOLUTION OF TWO SEQUENCES USING DFT AND IDFT
METHOD.

x1=input('Enter first sequence:');


x2=input('Enter second sequence:');
N=max(length(x1),length(x2));
X1=fft(x1,N);
X2=fft(x2,N);
Y=X1.*X2;
y=ifft(Y,N);
disp('Linear convolution using DFT and IDFT');
disp(y);
n=0:1:N-1;
subplot(1,1,1);
stem(n,y);
xlabel('time');
ylabel('amplitude');
title('circular convolution using DFT and IDFT');

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

OUTPUT:
EQUAL
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

UNEQUAL
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM FOR DESIGNING FILTERS USING BILINEAR


TRANSFORMATION

1. BUTTERWORTH LOWPASS FILTER


2. CHEBYSHEV LOWPASS FILTER

THEORITICAL CALCULATION:

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

1. BUTTERWORTH LOWPASS FILTER


Pass band edge frequency (fp) = 200 Hz

Pass band attenuation (Kp) = - 1 dB

Stop band edge frequency (fs) = 300 Hz

Stop band attenuation (Ks) = - 4 dB

Sampling frequency = 2000 Hz

ANALOG TO DIGITAL SPECIFICATION:

ω=ΩxT ; where T (i.e. Sampling time) =1/2000 sec


2𝜋×200
ωp=Ωpx T = 2πfpT = = 0.2 π rad
2000

2𝜋×300
ωs=Ωsx T = 2πfsT = = 0.3 π rad
2000

PREWARP THE BAND EDGE DIGITAL FREQUENCY USING T = 1 sec


2 𝜔
Ω’ = × tan
𝑇 2

2 0.2𝜋
Ω p’ = × tan = 0.6498 rad / sec
1 2

2 0.3𝜋
Ω s' = × tan = 1.0191 rad / sec
1 2

DESIGN OF ANALOG FILTER


-Kp
10 10 -1
[log10 { -K }] 100.1 -1
s [log10 { }]
10 10 -1 100.4 -1
N = Ωp = 0.6498 = 1.96 ≈ 2
[2 log( )] [2 log( )]
Ωs 1.0191

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Ωp 0.6498
Ωc = 1 = 1 = 0.9109 rad /sec
-Kp 2𝑁 0.1 4
(10 -1)
(10 10 -1)

Ωs 1.0191
Ωc = 1 = 1 = 0.9190 rad /sec
-Ks 2𝑁 0.4 4
(10 -1)
(10 10 -1)

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Therefore the idealized normalized equation of the filter is given by

1
𝐻2 (𝑠) =
[𝑠 2 + √2𝑠 + 1]

For required analog low pass filter

Ha(s) = H d (s) s->s/0.9190


1
𝐻𝑎 (𝑠) = 2
𝑠 𝑠
[{ } + √2 { } + 1]
0.919 0.919

0.844561
Ha(s) =
s2 +1.2996 s1 +0.844561

APPLYING BLT TO GET H(z)


2 1−𝑧 −1
H(z) = H a (s) 𝑠 → × [ ]
𝑇 1+𝑧 −1

0.844561
H(z) = 2 1
2 1−𝑧−1 2 1−𝑧−1
{1×[ ]} +1.2996 { ×[ ]} +0.844561
1+𝑧−1 1 1+𝑧−1

0.1135 𝑧 2+0.2269 𝑧 1+0.1135


H(z) =
𝑧 2 −0.8478𝑧+0.3016

2. CHEBYSHEV LOWPASS FILTER

Pass band edge frequency (fp) = 100 Hz


Pass band attenuation (Kp) = - 2 dB
Stop band edge frequency (fs) = 500 Hz
Stop band attenuation (Ks) = - 20 dB

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Sampling frequency = 4000 Hz

ANALOG TO DIGITAL SPECIFICATION:

ω =ΩxT ; where T (i.e. Sampling time) =1/4000 sec


2𝜋×100
ωp = Ωp x T = 2πfpT = = 0.05 π rad
4000

2𝜋×500
ωs = Ωs x T = 2πfsT = = 0.25 π rad
4000

PREWARP THE BAND EDGE DIGITAL FREQUENCY USING T = 1 sec


2 𝜔
Ω‘ = × tan
𝑇 2

2 0.05𝜋
Ωp‘= × tan = 0.1574 rad / sec
1 2

2 0.25𝜋
Ωs‘= × tan = 0.8284 rad / sec
1 2

DESIGN OF ANALOG FILTER

2
1
Kp = 20𝑙𝑜𝑔 = -2 ⇒∈ = √1010 − 1 = 0.7648
√1+∈2

1
𝛿p = 1− = 0.20567
√1+∈2

1
Ks = 20𝑙𝑜𝑔 𝛿𝑠 = -2 ⇒ 𝛿𝑠 =
10
= 0.1

Ωp′ 0.1574
K = = = 0.19
Ωs′ 0.8284

(1−𝛿𝑝)2 −1
D=√ = 0.0768
𝛿𝑠 2 −1

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

1
𝑐𝑜𝑠ℎ−1 ( )
𝑑
N≥ 1 ⇒ 𝑁 ≥ 1.39
𝑐𝑜𝑠ℎ−1 (𝑘)

N = 2

1 1+√1+ɛ2 1 1 1+√1+ɛ2 −1
A = { } − {
𝑁 }𝑁 = 0.568
2 ɛ 2 ɛ

1 1+√1+ɛ2 1 1 1+√1+ɛ2 −1
B = { }𝑁 + { }𝑁 = 1.15
2 ɛ 2 ɛ
π
𝜎𝑘 = −a sin((2k − 1) )
2N

π
𝛺𝑘 = −a cos ((2k − 1) ) ; Where k=1,2,3 …. 2N
2N

K 𝜎𝑘 𝛺𝑘
1 -0.401 0.813
2 -0.401 -0.813

Therefore S1= - 0.401 + j 0.813 & S2= - 0.413 - j 0.813

V2(s) = s2 + 0.802 s + 0.82177

b0 = 0.82177
0.82177
KN = = 0.653
√1+𝜖 2

0.653
H2(s) =
s2 +0.802s+0.82177

Ha(s)=H2(s)s->s/(0.1574)
0.653
Ha(s)= s s
( )2 +0.644( )+0.7074
0.1574 0.1574

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

0.01618
Ha(s)=
s2 +0.126s+0.0204

APPLYING BLT TO GET H(z)


2 1−𝑧 −1
H(z) = H a (s) 𝑠 → × [ ]
𝑇 1+𝑧 −1

0.01618
H(z) = 2 1
2 1−𝑧−1 2 1−𝑧−1
{1×[ ]} +0.126 { ×[ ]} +0.0204
1+𝑧−1 1 1+𝑧−1

0.00378 𝑧 2+0.0076 𝑧 1 +0.00378


H(z) =
𝑧 2 −1.863𝑧+0.8820

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
%DIGITAL BUTTERWORTH LOWPASS FILTER USING
BILINEAR TRANSFORM.
% Digital Butterworth Lowpass Filter using Bilinear
Transformation
% inputs : 200, 1, 300, 4, 2000
fp = input('Enter pass band edge frequency in Hz = ');
Ap = input('Enter pass band ripple in dB = ');
fs = input('Enter stop band edge frequency in Hz = ');
As = input('Enter stop band ripple in dB = ');
Fs = input('Enter the sampling frequency in Hz = ');

W1 = 2*pi*fp/Fs;
W2 = 2*pi*fs/Fs;

% Prewarping
Wp = 2*tan(W1/2);
Ws = 2*tan(W2/2);

[n, Wc] = buttord(Wp, Ws, Ap, As, 's');


disp('The order of the filter is N = ');
disp(n);
disp('The cutoff frequency is = ');
disp(Wc);

disp('The Analog filter numerator and denominator coefficients


are ');
[num, den] = butter(n, Wc, 's');
disp(num);
disp(den);
disp('The Digital filter numerator and denominator coefficients
are ');
[b, a] = bilinear(num, den, 1);
freqz(b,a, 512, Fs); % 512 point complex frequency response
vector
disp(b);
disp(a);

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

%DIGITAL CHEBYSHEV LOWPASS FILTER USING BILINEAR


TRANSFORM.
% Digital Chebyshev-I Lowpass Filter using Bilinear
Transformation
fp = input('Enter pass band edge frequency in Hz = ');
Ap = input('Enter pass band ripple in dB = ');
fs = input('Enter stop band edge frequency in Hz = ');
As = input('Enter stop band ripple in dB = ');
Fs = input('Enter the sampling frequency in Hz = ');

W1 = 2*pi*fp/Fs;
W2 = 2*pi*fs/Fs;

% Prewarping
Wp = 2*tan(W1/2);
Ws = 2*tan(W2/2);

[n, Wc] = cheb1ord(Wp, Ws, Ap, As, 's');


disp('The order of the filter is N = ');
disp(n);
disp('The cutoff frequency is = ');
disp(Wc);

disp('The Analog filter numerator and denominator coefficients


are ');
[num, den] = cheby1(n, Ap, Wc, 's');
disp(num);
disp(den);
disp('The Digital filter numerator and denominator coefficients
are ');
[b, a] = bilinear(num, den, 1);
freqz(b,a, 512, Fs); % 512 point complex frequency response
vector
disp(b);
disp(a);

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

OUTPUT:
BLT -BUTTERWORTH LOWPASS
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

BLT-CHEBYSHEV LOWPASS
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM TO DESIGN AN ANALOG CHEBYSHEV FILTER

1. LOWPASS FILTER
2. HIGH PASS FILTER
3. BANDPASS FILTER

THEORITICAL CALCULATION:
For a Chebyshev filter the magnitude response is given by

Then,

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Where,

Order of filter is given by

Where,

1. LOWPASS FILTER

Pass band edge frequency (fp) = 2Hz i.e. Ωp = 4 𝛱 rad/sec


Pass band attenuation (Kp) = -3dB
Stop band edge frequency (fs) = 5Hz i.e. Ωs =10 𝛱 rad/sec
Stop band attenuation (Ks) = -10dB

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

N ≥ 1.12

N = 2

1 1+√1+ɛ2 1 1 1+√1+ɛ2 −1
A = { }𝑁 − { }𝑁 = 0.4560239
2 ɛ 2 ɛ

1 1+√1+ɛ2 1 1 1+√1+ɛ2 −1
B = { }𝑁 + { }𝑁 = 1.09907
2 ɛ 2 ɛ

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

π
𝜎𝑘 = −a sin((2k − 1) )
2N

π
𝛺𝑘 = −a cos ((2k − 1) ) ; Where k=1,2,3 …. 2N
2N

K 𝜎𝑘 𝛺𝑘
1 -0.322 0.777
2 -0.322 -0.777

Therefore S1= - 0.322 + j 0.777 & S2= - 0.322 - j 0.777

0.5008
H2(s)=
s2 +0.644s+0.7074
0.7074
KN =
√1+𝜖 2

Ha(s)=H2(s)s->s/(4π)
0.5008
Ha(s)= s s
(4π)2+0.644(4π)+0.7074

79.083
Ha(s)=
s2 +8.093s+111.708

2. HIGHPASS FILTER

No theory required

3. BAND PASS FILTER

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

No Theory required

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
%DESIGN OF ANALOG CHEBYSHEV LOW PASS FILTER
fp = input('Enter pass band edge frequency in Hz = ');
rp = input('Enter pass band ripple in dB = ');
fs = input('Enter stop band edge frequency in Hz = ');
rs = input('Enter stop band ripple in dB = ');
Wp = 2*pi*fp;
disp(Wp);
Ws = 2*pi*fs;
disp(Ws);
[n, Wp] = cheb1ord(Wp, Ws, rp, rs, 's');
disp('The order of the filter is N = ');
disp(n);
 Wp is the Chebyshev natural frequency to use with
CHEBY1 to achieve the required specifications.
disp('The cutoff frequency is = ');
disp(Wp);
disp('The numerator and denominator coefficients of the analog
filter are ');
% for low pass
[b, a] = cheby1(n, rp, Wp,'low','s');
disp('Numerator co-efficients :');
disp(b);
disp('Denominator co-efficients :');
disp(a);
[h, w] = freqs(b, a);
m = 20*log10(abs(h));
an = (angle(h)*180/pi);
subplot(211);
plot(w, m);
title('Frequency response of analog Chebyshev filter');
xlabel('Frequency in rad/s');
ylabel('Magnitude in dB');
grid on;
subplot(212);
plot(w, an);
title('Phase response of analog Chebyshev filter');
xlabel('Frequency in rad/sec');
ylabel('Phase(degrees)');
grid on;

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

OUTPUT:
CHEBYSHEV LOWPASS
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM FOR DESIGNING AN ANALOG BUTTERWORTH


FILTER

1. LOWPASS FILTER
2. HIGH PASS FILTER
3. BANDPASS FILTER

THEORITICAL CALCULATION:
For a butterworth filter

Magnitude frequency response is given by

Order of filter is given by

Cutoff frequency is given by

, using pass band parameters


OR

, using stop band parameters


OR
the mean of the above two can considered depending on requirement

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

ANALOG TO ANALOG CONVERSION

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

1. LOWPASS FILTER
Pass band edge frequency (fp) = 2Hz i.e. Ωp = 4 Π rad/sec

Pass band attenuation (Kp) = -3dB

Stop band edge frequency (fs) = 5Hz i.e. Ωs =10 Π rad/sec

Stop band attenuation (Ks) = -10dB

10π
Ωs = = 2.5 rad/sec (backward transformation for low pass filter)
4𝜋

New normalized Ω p = 1

New normalized Ω s = 2.5


-Kp
10 10 -1
[log10 { -K }] 100.3 -1
s [log10 { }]
10 10 -1 101 -1
N = Ωp = 1 = 1.2015 ≈ 2
[2 log( )] [2 log( )]
Ωs 2.5

Ωp 1
Ωc = 1 = 1 = 1 rad /sec
-Kp 2𝑁 0.3 4
(10 -1)
(10 10 -1)

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Ωs 2.5
Ωc = 1 = 1 = 1.4434 rad /sec
-Ks 2𝑁 1 4
(10 -1)
(10 10 -1)

Therefore the idealized normalized equation of the filter is given by


1
𝐻2 (𝑠) =
[𝑠 2 + √2𝑠 + 1]

Required normalized Low pass transform is given by

H d (s) = H2(s) s->s/1.4434

(In order to get a curve which satisfy cutoff frequency closely we use Ωc based on cutoff parameter
instead of one based on pass band based cutoff)

For required analog low pass filter

Ha(s) = H d (s) s->s/4π = H2(s) s->s / (4π x 1.4434) = H2(s) s->s/18.138

1
𝐻𝑎 (𝑠) = 2
𝑠 𝑠
[{ } + √2 { } + 1]
18.138 18.138

328.9868
Ha(s) =
s2 +25.6510s1 +328.9868

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

2. HIGHPASS FILTER
Pass band edge frequency (fp) = 5Hz i.e. Ωp = 10 𝛱 rad/sec

Pass band attenuation (Kp) = -3dB

Stop band edge frequency (fs) = 2Hz i.e. Ωs =4 𝛱 rad/sec

Stop band attenuation (Ks) = -10dB

Normalized filter

10π
Ωs = = 2.5 rad/sec (backward transformation for high pass filter)
4𝜋

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

New normalized Ω p = 1

New normalized Ω s = 2.5


-Kp
10 10 -1
[log10 { -K }] 100.3 -1
s [log10 { }]
10 10 -1 101 -1
N = Ωp = 1 = 1.2015 ≈ 2
[2 log( )] [2 log( )]
Ωs 2.5

Ωp 1
Ωc = 1 = 1 = 1 rad/sec
-Kp 2𝑁 0.3 4
(10 -1)
(10 10 -1)

Ωs 2.5
Ωc = 1 = 1 = 1.4434 rad/sec
-Ks 2𝑁 1 4
(10 -1)
(10 10 -1)

Therefore the idealized normalized equation of the filter is given by

1
𝐻2 (𝑠) =
[𝑠 2 + √2𝑠 + 1]

Required normalized Low pass transform is given by

H d (s) = H2(s) s->s/1.4434

(In order to get a curve which satisfy cutoff frequency closely we use Ωc based on cutoff parameter
instead of one based on pass band based cutoff)

For required analog high pass filter

Ha(s) = H2(s) s->10π / 1.4434s i.e. H2(s) s->21.765 /s

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

1
𝐻𝑎 (𝑠) =
21.765 2 21.765
[{ } +{ } + 1]
𝑠 𝑠

s2
Ha(s) =
s2 +30.781s1 +473.73

3. BANDPASS FILTER

Lower pass band edge frequency (f l) = 50Hz i.e. Ω l = 100π rad/sec

Higher pass band edge frequency (f u) = 20kHz i.e. Ω u = 40000π rad/sec

Pass band attenuation (Kp) = -3.0103 dB

Lower stop band edge frequency (f1) = 20Hz i.e. Ω1 =40π rad/sec

Lower stop band edge frequency (f2) = 45kHz i.e. Ω2 =90000π rad/sec

Stop band attenuation (Ks) = -20dB

Ωc = 4 𝛱/(100.3-1)^0.25 = 12.581 rad/sec

OR

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Ωc = 10 𝛱/(101-1)^0.25 = 18.138 rad/sec

−Ω1 2 +Ω𝑙 Ω𝑢
A = = 2.51
Ω1 (Ω𝑙 −Ω𝑢 )

Ω2 2 −Ω𝑙 Ω𝑢
B = = 2.25
Ω2 (Ω𝑢 −Ω𝑙 )

Ωs = Min{|A|,|B|} = 2.25

-Kp
10 10 -1
[log10 { -K }] 100.30103 -1
s [log10 { }]
10 10 -1 102 -1
N = Ωp = 1 = 2.83 ≈ 3
[2 log( Ωs )] [2 log(2.25)]

Ωp 1
Ωc = 1 = 1 = 0.99979 rad/sec
-Kp 2𝑁 0.30103 6
(10 -1)
(10 10 -1)

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Ωs 2.25
Ωc = 1 = 1 = 1.0461 rad/sec
-Ks 2𝑁 2 6
(10 -1)
(10 10 -1)

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

Therefore the idealized normalized equation of the filter is given by


1
𝐻3 (𝑠) =
[𝑠 3 + 2𝑠 2 + 2𝑠 + 1]

Required normalized Low pass transform is given by

H d (s) = H2(s) s->s/1.046

(In order to get a curve which satisfy cutoff frequency closely we use Ωc based on cutoff parameter
instead of one based on pass band based cutoff)

For required analog low pass filter

Ha(s) = H3 (s) 𝑠2 +Ω𝑙 Ω𝑢 = H3 (s) 𝑠2 +3.949 ×107


𝑠→ 𝑠→
𝑠(Ω𝑙−Ω𝑢 ) 𝑠(1.2538×105 )

Therefore the required band pass filter is given by

1.9695 x 1015 s3
Ha(s) = 6
s +2.51 x 105 s5 +3.154 x 1010 s4 +1.989 x 1015 s3
+1.2453 x 1018 s2 +3.9073 x 1020 s+6.1529 x 1022

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
%ANALOG BUTTERWORTH LOW PASS FILTER
fp = input('Enter pass band edge frequency in Hz = ');
rp = input('Enter pass band ripple in dB = ');
fs = input('Enter stop band edge frequency in Hz = ');
rs = input('Enter stop band ripple in dB = ');
Wp = 2*pi*fp;
disp('pass band edge frequency in rad/sec:');
disp(Wp);
Ws = 2*pi*fs;
disp('stop band edge frequency in rad/sec:');
disp(Ws);
[n, Wn] = buttord(Wp, Ws, rp, rs,'s');
disp('The order of the filter is N = ');
disp(n);
disp('The cutoff frequency is = ');
disp(Wn);
disp('The numerator and denominator coefficients of the analog
filter are ');
[b, a] = butter(n,Wn,'low','s');
disp('Numerator co-efficients :');
disp(b);
disp('Denominator co-efficients :');
disp(a);
[h, w] = freqs(b, a);
m = 20*log10(abs(h));
an = (angle(h)*180/pi);
subplot(211);
plot(w, m);
title('Frequency response of analog butterworth filter');
xlabel('Frequency in rad/s');
ylabel('Magnitude in dB');
grid on;
subplot(212);
plot(w, an);
title('Phase response of analog Butterworth filter');
xlabel('Frequency in rad/sec');
ylabel('Phase(degrees)');
grid on;

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

%ANALOG BUTTERWORTH HIGH PASS FILTER


fp = input('Enter pass band edge frequency in Hz = ');
rp = input('Enter pass band ripple in dB = ');
fs = input('Enter stop band edge frequency in Hz = ');
rs = input('Enter stop band ripple in dB = ');
Wp = 2*pi*fp;
disp('pass band edge frequency in rad/sec:');
disp(Wp);
Ws = 2*pi*fs;
disp('stop band edge frequency in rad/sec:');
disp(Ws);
[n, Wn] = buttord(Wp, Ws, rp, rs,'s');
disp('The order of the filter is N = ');
disp(n);
disp('The cutoff frequency is = ');
disp(Wn);
disp('The numerator and denominator coefficients of the analog
filter are ');
[b, a] = butter(n,Wn,'high','s');
disp('Numerator co-efficients :');
disp(b);
disp('Denominator co-efficients :');
disp(a);
[h, w] = freqs(b, a);
m = 20*log10(abs(h));
an = (angle(h)*180/pi);
subplot(211);
plot(w, m);
title('Frequency response of analog butterworth filter');
xlabel('Frequency in rad/s');
ylabel('Magnitude in dB');
grid on;
subplot(212);
plot(w, an);
title('Phase response of analog Butterworth filter');
xlabel('Frequency in rad/sec');
ylabel('Phase(degrees)');
grid on;

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

%ANALOG BUTTERWORTH BANDPASS FILTER

fp1 = input('Enter lower pass band edge frequency in Hz = ');


fp2 = input('Enter higher pass band edge frequency in Hz = ');
rp = input('Enter pass band ripple in dB = ');
fs1 = input('Enter stop band edge frequency in Hz = ');
fs2 = input('Enter stop band edge frequency in Hz = ');
rs = input('Enter stop band ripple in dB = ');
Wp = 2*pi.*[fp1 fp2];
% similarly Wp = 2*pi*[fp1 fp2];
disp('pass band frequncies are:');
disp(Wp);
disp('stop band frequncies are:');
Ws = 2*pi.*[fs1 fs2];
% similarly Ws = 2*pi*[fs1 fs2];
disp(Ws);
[n, Wn] = buttord(Wp, Ws, rp, rs, 's');
disp('The order of the filter is N = ');
disp(n);
disp('The cutoff frequency is = ');
disp(Wn);
disp('The numerator & denominator coefficients of the filter is');
[b, a] = butter(n,Wn,'s');
disp('Numerator co-efficients :');
disp(b);
disp('Denominator co-efficients :');
disp(a);
[h, w] = freqs(b, a);
m = 20*log10(abs(h));
an = (angle(h)*180/pi);
subplot(211); plot(w, m);
title('Frequency response of analog butterworth filter');
xlabel('Frequency in rad/s');
ylabel('Magnitude in dB');
grid on;
subplot(212); plot(w, an);
title('Phase response of analog Butterworth filter');
xlabel('Frequency in rad/sec');
ylabel('Phase(degrees)');
grid on;

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

OUTPUT:
BUTTERWORTH LOWPASS
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

BUTTERWORTH HIGHPASS
WORKSPACE

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

BUTTERWORTH BANDPASS
WORKSPACE

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

COMMAND WINDOW

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

GRAPH

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

AIM: PROGRAM FOR DESIGNING AN FINITE IMPULSE RESPONSE


FILTER DEPENDING ON THE SPECIFICATION

THEORY:
The window function that satisfies the pass band or stop band specifications is
selected (refer table). The number of coefficients is determined using the appropriate
relationship between the filter length and transition bandwidth.
Filter coefficients are given by
h(n) = hd(n) w(n)
where hd(n) is the ideal desired impulse response of the filter which is obtained by
inverse Fourier transform of the desired frequency response H D(ω) and w(n) is the
window function.
The desired filter can be a low pass, high pass, band pass or band reject filter.
Routine fir1 in its various forms is used to design filters based on various windows.
if you need help use the matlab help or happy googling

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

PROGRAM:
%PLOT THE MAGNITUDE RESPONSE AND CHECK THE
SPECIFICATION OF THE OBTAINED FILTER

1. Pass band edge frequency = 21 KHz


Stop band edge frequency = 4 KHz
Pass band attenuation = 2dB
Stopband attenuation = 40dB
Sampling frequency = 20Khz

clc
clear
closeall
% Pass band and Stop band edge frequencies
fp =2000;
fs=4000;
Fs=20000; % sampling frequency
fn=Fs/2; %normalizing to half the sampling frequency
fc=(fs+fp)/2/fn; %cut off frequency (normalized to fn)
%normalized transition width
tw=(fs-fp)/Fs;
N=ceil(4/tw);
% as stop band attenuation is = 40db
wn=harming(N);% window coefficients
%calculate truncated ideal impulse response coeffs
hd =fir1(N-1,fc,boxcar(N));
% to obtain Windowed coefficients
hn=fir1(N-1,fc,wn);
% Frequency response
[H,f] = freqz(hn,1,512,Fs);
mag = 20*log10(abs(H));
plot(f,mag)
grid on
xlabel(‘Frequency(Hz)’);
ylabel(‘Magnitude response (dB)’);
title('Frequency response of BPF’);

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

2. Passband = 150 - 250 Hz


Transition width = 50 Hz
Passbandripple = 0.1 dB
Stopband attenuation = 60dB
Sampling frequency = 1 KHz

clc
clear
closeall
%Passband and transition width
fp1=150;
fp2=250;
tw=50;
Fs=1000; % sampling frequency
fn=Fs/2; % normalised to half the sampling frequency
fc1=(fp1-(tw/2))/fn; % cutoff frequency(normalised to fn)
fc2=(fp2+(tw/2))/fn;
tw=tw/Fs; %Normailsed transition width
% stopband attenuation is 60db so we choose blackman window
N=ceil(6/tw);
wn=blackman(N);
%calculate truncated ideal impulse response coeffs
hn=fir1(N-1,[fcl,fc2),boxcar(N));
% obtain windowed coefficients
hn=firl(N-1,[fcl,fc2],wn);
[H,f]=freqz(hn,1,512,Fs);
mag =20*log10(abs(H));
plot(f,mag)
grid on;
xlabel(‘Frequency(Hz)’);
ylabel('Magnitude response (dB)’);
title(‘Frequency response of BPF’);

Dept. of Telecommunication Engineering MSRIT


DSP Lab Manual TCL 56

%FIR FILTER USING HAMMING WINDOW(KNOWN WINDOW


LENGTH)

N=input(‘Enter the window length = ’);


fc=input(‘Enter the cut-off frequency = ’);
fs=input('Enter the sampling frequency = ');
wc=2πfc/fs;
wh=(hamming(N));
b=fir1(N-1,wc,wh);
[h,omega]=freqz(b,1,256);
mag=20*log10(abs(h));
plot(omega/pi,mag);
grid on;
xlabel(‘Frequency in radians in terms of pi’);
ylabel(‘Gain in dB’);
title(‘Response of FIR Filter using Hamming Window’);
disp(‘Hamming window co-efficients’),
disp(wh);
disp(‘FIR Filter output’);
disp(b);

%FIR FILTER USING HAMMING WINDOW(UNKNOWN WINDOW


LENGTH)

wp=input(‘Passband frequency =’);


ws=input(‘Stopband frequency =’);
wt= ws-wp:
N=(8/wt)+1
N=round(N);
wh=(hamming(N));
b=fir1(N-1,wp,wh);
disp(‘impulse response co-efficients =’);
disp(b);
freqz(b);
title(‘Response of FIR filter using Hamming window’);

Dept. of Telecommunication Engineering MSRIT

You might also like