DSP Lab Manual

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 34

DEPARTMENT OF ELECTRONICS &

COMMUNICATION ENGINGEERING

COURSE FILE

Digital Signal Processing Lab


(5EC4-22)

LAB MANUAL
V SEM ECE

SESSION: 2021-22

PREPARED BY:-

POOJA KUMARI

Asst. Professor

Dept. Of Electronics & Communication Engg.

ACEIT, Jaipur
LIST OF EXPERIMENTS
5EC4-22: Digital Signal Processing Lab
MM 75
S.no NAME OF EXPERIMENT Mapping
. with CO

1. Introduction: Objective, scope and outcome of the course.

2. Introduction to MATLAB CO 1

3. Generation of continuous and discrete elementary signals (periodic CO 1


and non-periodic) using mathematical expression.

4. Generation of Continuous and Discrete Unit Step Signal. CO 1

5. Generation of Exponential and Ramp signals in Continuous & CO 1


Discrete domain.

6. Perform basic operations on signals like adding, subtracting, shifting CO 1


and scaling.

7. To Plot Continuous and Discrete time Convolution of two signals. CO 2

8. To generate uniform random numbers between (0, 1). CO 2

9. To generate random sequences with arbitrary distributions, means CO 3


and variances for following :
(a) Rayleigh distribution
(b) Normal distributions: N(0,1).
(c) Gaussian distribution: N(μ,σ).
(d). random binary wave.

10. To find DFT / IDFT of given DT signal. CO 2

11. To implement Circular convolution CO 3

12. MATLAB code for implementing z-transform and inverse z- CO 4,


transform.

13. Perform inverse z-transform using residuez MATLAB function. CO 4


14. To design FIR filter (LP/HP) using windowing technique using CO 5
simulink.

15. To develop program for for designing IIR filter. CO 5

5EC4-22: Digital Signal Processing Lab

COURSE OBJECTIVE

1 . To understand MATLAB

2 To understand basic operations on Discrete signals.

3 To understand filter designing.

COURSE OUTCOMES
After completion of this course, students will be able to –

CO 1 Understand the mathematical operation on discrete signals.

CO 2 Sketch the magnitude and phase response of DFT, Inverse DFT and FFT
of discrete time signals.
Calculate linear and circular convolution of discrete sequences and
CO 3
generate random sequences.

CO 4 Implement Z transform and inverse Z transform of discrete signals

CO 5 Model IIR and FIR filter using window techniques


LAB ASSESMENT CRITERIA:
5EC4-22: Digital Signal Processing Lab

TOTAL LAB MARKS: 75 Marks

INTERNAL: 45 Marks

EXTERNAL: 30 Marks

For assessment of work done during mid semester the Internal marks (60% component) is to
be distributed under the following heads:

1. Performance of Practical – 50%


2. Timely submission of records – 20%
3. Quiz/Viva – 10%
4. Internal midterm practical-20%

For assessment of external marks (40% component) is to be distributed as:

1. Comprehensive Examination through Quiz/Viva/Performance – 40%


RESPONSIBILITIES OF USERS

Users are expected to follow some fairly obvious rules of conduct:

ALWAYS
 Enter the lab on time and leave at proper time.
 Wait for the previous class to leave before the next class enters.
 Keep the bag outside in the respective racks.
 Utilize lab hours in the corresponding.
 Turn off the machine before leaving the lab unless a member of lab staff has
specifically told you not to do so.
 Leave the labs at least as nice as you found them.
 If you notice a problem with a piece of equipment (e.g. a computer doesn't respond)
or the room in general (e.g. cooling, heating, lighting) please report it to lab staff
immediately. Do not attempt to fix the problem yourself.

NEVER
 Don't abuse the equipment.
 Do not adjust the heat or air conditioners. If you feel the temperature is not properly
set, inform lab staff; we will attempt to maintain a balance that is healthy for people
and machines.
 Do not attempt to reboot a computer. Report problems to lab staff.
 Do not remove or modify any software or file without permission.
 Do not remove printers and machines from the network without being explicitly told
to do so by lab staff.
 Don't monopolize equipment. If you're going to be away from your machine for more
than 10 or 15 minutes, log out before leaving. This is both for the security of your
account, and to ensure that others are able to use the lab resources while you are not.
 Don’t use internet, internet chat of any kind in your regular lab schedule.
 Do not download or upload of MP3, JPG or MPEG files.
 No games are allowed in the lab sessions.
 No hardware including USB drives can be connected or disconnected in the labs
without prior permission of the lab in-charge.
 No food or drink is allowed in the lab or near any of the equipment. Aside from the
fact that it leaves a mess and attracts pests, spilling anything on a keyboard or other
piece of computer equipment could cause permanent, irreparable, and costly damage.
(and in fact has) If you need to eat or drink, take a break and do so in the canteen.
 Don’t bring any external material in the lab, except your lab record, copy and books.
 Don’t bring the mobile phones in the lab. If necessary then keep them in silence
mode.
 Please be considerate of those around you, especially in terms of noise level. While
labs are a natural place for conversations of all types, kindly keep the volume turned
down.
If you are having problems or questions, please go to either the faculty, lab in-charge or the
lab supporting staff. They will help you. We need your full support and cooperation for
smooth functioning of the lab.

INSTRUCTIONS (SAFETY PRECAUTIONS)

BEFORE ENTERING IN THE LAB

 All the students are supposed to prepare the theory regarding the next experiment.
 Students are supposed to bring the practical file and the lab copy.
 Previous programs should be written in the practical file.
 All the students must follow the instructions, failing which he/she may not be allowed
in the lab.
WHILE WORKING IN THE LAB

 Adhere to experimental schedule as instructed by the lab in-charge.


 Get the previously executed program signed by the instructor.
 Get the output of the current program checked by the instructor in the lab copy.
 Each student should work on his/her assigned computer at each turn of the lab.
 Take responsibility of valuable accessories.
 Concentrate on the assigned practical and do not play games
 If anyone caught red handed carrying any equipment of the lab, then he/she will have
to face serious consequences.
EXPERIMENT NO. 1
AIM:-
Introduction to MATLAB.

REQUIREMENTS:-
SOFTWARE: MATLAB (Version: 7.7.0 R2008b)

The MATLAB high-performance language for technical computing integrates computation,


visualization, and programming in an easy-to-use environment where problems and solutions
are expressed in familiar mathematical notation. Typical uses include

 Math and computation


 Algorithm development
 Data acquisition
 Modeling, simulation, and prototyping
 Data analysis, exploration, and visualization
 Scientific and engineering graphics
 Application development, including graphical user interface building

MATLAB is an interactive system whose basic data element is an array that does not require
dimensioning. It allows you to solve many technical computing problems, especially those
with matrix and vector formulations, in a fraction of the time it would take to write a program
in a scalar non-interactive language such as C or Fortran.

The name MATLAB stands for matrix laboratory. MATLAB was originally written to
provide easy access to matrix software developed by the LINPACK and EISPACK projects.
Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the
state of the art in software for matrix computation.

MATLAB has evolved over a period of years with input from many users. In university
environments, it is the standard instructional tool for introductory and advanced courses in
mathematics, engineering, and science. In industry, MATLAB is the tool of choice for high-
productivity research, development, and analysis.

MATLAB features a family of add-on application-specific solutions called toolboxes. Very


important to most users of MATLAB, toolboxes allow you to learn and apply specialized
technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that
extend the MATLAB environment to solve particular classes of problems. You can add on
toolboxes for signal processing, control systems, neural networks, fuzzy logic, wavelets,
simulation, and many other areas.
The MATLAB System

The MATLAB system consists of following main parts:

1. Desktop Tools and Development Environment

This part of MATLAB is the set of tools and facilities that help you use and become more
productive with MATLAB functions and files. Many of these tools are graphical user
interfaces. It includes: the MATLAB desktop and Command Window, an editor and
debugger, a code analyzer, browsers for viewing help, the workspace, and files, and other
tools.

2. Mathematical Function Library

This library is a vast collection of computational algorithms ranging from elementary


functions, like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like
matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier transforms.

3. The Language

The MATLAB language is a high-level matrix/array language with control flow statements,
functions, data structures, input/output, and object-oriented programming features. It allows
both "programming in the small" to rapidly create quick programs you do not intend to reuse.
You can also do "programming in the large" to create complex application programs intended
for reuse.

4. Graphics

MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as
annotating and printing these graphs. It includes high-level functions for two-dimensional and
three-dimensional data visualization, image processing, animation, and presentation graphics.
It also includes low-level functions that allow you to fully customize the appearance of
graphics as well as to build complete graphical user interfaces on your MATLAB
applications.

5. External Interfaces

The external interfaces library allows you to write C and Fortran programs that interact with
MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking), for
calling MATLAB as a computational engine, and for reading and writing MAT-files.
How to Start MATLAB?

MATLAB ICON

Current
Directory Command Window Workspace

Command
History

Editor Window to write program

RESULT: -Study of introduction of MATLAB have done.


VIVA-QUESTIONS:

1. What are the important commands used in MATLAB?

2. What is the extension to save the file in MATLAB?

3. What are the applications of MATLAB.


EXPERIMENT NO. 2
AIM:-
Generation of continuous and discrete elementary signals (periodic and non-periodic) using
mathematical expression

REQUIREMENTS:-

SOFTWARE: MATLAB (Version: 7.7.0 R2008b)

PROGRAM:
(a) Code for plotting of Continuous periodic Sinusoidal function -

x=0:0.05:7
y= sin(x)
plot(x,y)
Title ('Graph of Continuous Sin Function')
xlabel ('Time')
ylabel ('Amplitude')

(b) Code for plotting of Discrete periodic Sinusoidal function -

x=0:0.05:7
y= sin(x)
stem(x,y)
Title ('Graph of Discrete Sin Function')
xlabel ('Time')
ylabel ('Amplitude')

(c) Code for plotting of Continuous non-periodic Logarithmic function –

x=0:0.05:7
y= log(x)
plot(x,y)
Title('Graph of Continuous Log Function ')
xlabel('Time')
ylabel('Amplitude')

(d) Code for plotting of discrete non-periodic Logarithmic function –

x=0:0.05:7
y= log(x)
stem(x,y)
Title ('Graph of Discrete Log Function ')
xlabel ('Time')
ylabel ('Amplitude')
OUTPUT RESULTS:
Graph of Continuous Sin Function
1

0.8

0.6

0.4

0.2

Amplitude
0

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7
Time

Plot of Continuous periodic Sinusoidal function

Graph of Discrete Sin Function


1

0.8

0.6

0.4

0.2
A m plitude

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7
Time

Plot of Discrete periodic Sinusoidal function

Graph of Continuous Log Functi on


2

1.5

0.5
A m p lit u d e

-0.5

-1

-1.5

-2

-2.5

-3
0 1 2 3 4 5 6 7
Time

Plot of Continuous non-periodic Logarithmic function


2
Graph of Discrete Log Function

1.5

0.5

0
A m p litu d e

-0.5

-1

-1.5

-2

-2.5

-3
0 1 2 3 4 5 6 7

Plot of Discrete non-periodic Logarithmic function


Time

RESULT: we have successfully generated continuous and discrete elementary signals


(periodic and non-periodic) using mathematical expression.

VIVA-QUESTIONS:

1. What is the function is of built in function and subplot?


2. What do you mean by statement subplot (3,3,1)?
3. Give the difference between stem and plot command.
EXPERIMENT NO. 3

AIM: Generation of Continuous and Discrete Unit Step Signal.

SOFTWARE: MATLAB (Version: 7.7.0 R2008b)

PROGRAM:
(A) Code for plotting of Continuous Unit Step signal-

x= -3:1:3
y= [zeros(1,3), ones(1,4)]
plot(x,y)
Title(‘Plot of Continuous Unit Step Siganl’)
xlabel(‘Time’)
ylabel(‘Amplitude’)

(B) Code for plotting of Continuous Unit Step signal-

x= -3:1:3
y= [zeros(1,3), ones(1,4)]
stem(x,y)
title(‘Plot of Discrete Unit Step Siganl’)
xlabel(‘Time’)
ylabel(‘Amplitude’)

OUTPUT RESULTS :
Plot of Continuous Unit Step Siganl Plot of Discrete Unit Step Siganl
1 1

0.9 0.9

0.8 0.8

0.7 0.7

0.6 0.6
Amplitude
Amplitude

0.5 0.5

0.4 0.4

0.3 0.3

0.2 0.2

0.1 0.1

0 0
-3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 3
Time Time

(a) Plot of Continuous Unit Step Signal (b) Plot of Continuous Unit Step Signal

RESULT: we have successfully generated Continuous and Discrete Unit Step Signal.

VIVA-QUESTIONS:

1. What is Impulse signal?

2. What is Impulse response?

3. Define Step response.


EXPERIMENT NO. 4
AIM: Generation of Exponential and Ramp signals in Continuous & Discrete domain.

SOFTWARE: MATLAB (Version: 7.7.0 R2008b)

PROGRAM:

(a) Code for plotting of Continuous Exponential function -

x=-3:0.1:3
y= exp(x)
plot(x,y)
Title ('Graph of Continuous Exponential Function')
xlabel ('Time')
ylabel ('Amplitude')

(b) Code for plotting of Discrete Exponential function -

x=-3:0.1:3
y= exp(x)
stem(x,y)
Title ('Graph of Discrete Exponential Function')
xlabel ('Time')
ylabel ('Amplitude')

(c) Code for plotting of Continuous Ramp function –

x=0:0.05:10
y= (x)
plot(x,y)
Title ('Graph of Continuous Ramp Function ')
xlabel ('Time')
ylabel ('Amplitude')

(d) Code for plotting of Discrete Ramp function –

x=0:0.05:10
y= (x)
stem(x,y)
Title ('Graph of Discrete Ramp Function ')
xlabel ('Time')
ylabel ('Amplitude')
OUTPUT RESULTS : 25
Graph of Discrete Exponential Function

Plot of Discrete Unit Step Siganl


25

20

20

15

Amplitude
15
Amplitude

10

10

0
-3 -2 -1 0 1 2 3
0 Time
-3 -2 -1 0 1 2 3
Time

(a)Plot of Continuous Exponential Signal (b)Plot of Discrete Exponential Signal

Graph of Discrete Ramp Function


10

Graph of Continuous Ramp Function


10
9

9
8

8
7

7
6

Amplitude
6
5
Amplitude

5
4

4
3

3
2

2
1

(b)
1
0
0 1 2 3 4 5 6 7 8 9 10
Time
0
0 1 2 3 4 5 6 7 8 9 10
Time

(c)Plot of cont. ramp Signal (d)Plot of discrete.ramp Signal

RESULT: we have successfully generated Continuous and Discrete Exponential and Ramp
signals.

VIVA-QUESTIONS:
1. Define Ramp signal.

2. How can you obtain ramp signal from unit step signal?

3. What is an LTI system?


EXPERIMENT NO. 5
AIM: Perform basic operations on signals like adding, subtracting, shifting and scaling.

SOFTWARE: MATLAB (Version: 7.7.0 R2008b)

PROGRAM:
Code for plotting of Addition of two Continuous signals -

t=0:0.05:10
x= sin(t)
y= cos(t)
a= x+y
s= x-y
subplot(4,1,1)
plot(x)
Title ('Graph of Sin Function')
xlabel ('Time')
ylabel ('Amplitude')
subplot(4,1,2)
plot(y)
Title ('Graph of Cos Function')
xlabel ('Time')
ylabel ('Amplitude')
subplot(4,1,3)
plot(a)
Title ('Graph of Addition between Sin and Cos')
xlabel ('Time')
ylabel ('Amplitude')
subplot(4,1,4)
plot(s)
Title ('Graph of Subtraction between Sin and Cos')
xlabel ('Time')
ylabel ('Amplitude')

# Code for plotting of Addition of two Discrete signals - Just replace plot command with
Stem command in above program
OUTPUT RESULTS:

Graph of Sin Function


1
Amplitude

-1
0 50 100 150 200 250
Time
Graph of Cos Function
1
Amplitude

-1
0 50 100 150 200 250
Time
Graph of Addition between Sin and Cos
2
Amplitude

-2
0 50 100 150 200 250
Time
Graph of Subtraction between Sin and Cos
2
Amplitude

-2
0 50 100 150 200 250
Time

RESULT: We have successfully performed basic operations on signals like adding,


subtracting.

VIVA-QUESTIONS:

1. What is signal?

2. What is system?

3. Explain different types of signals.


EXPERIMENT NO. 6
AIM: To Plot Continuous and Discrete time Convolution of two signals.

SOFTWARE: MATLAB (Version: 7.7.0 R2008b)

PROGRAM:
Code for plotting of Continuous Convolution -

t=0:0.05:10
x= sin(t)
y= cos(t)
z= conv(x,y)
subplot(3,1,1)
plot(x)
Title ('Graph of Sin Function')
xlabel ('Time')
ylabel ('Amplitude')
subplot(3,1,2)
plot(y)
Title ('Graph of Cos Function')
xlabel ('Time')
ylabel ('Amplitude')
subplot(3,1,3)
plot(z)
Title ('Graph of Convolution between Sin and Cos')
xlabel ('Time')
ylabel ('Amplitude')

Code for plotting of Discrete Convolution -

t=0:0.05:10
x= sin(t)
y= cos(t)
z= conv(x,y)
subplot(3,1,1)
stem(x)
Title ('Graph of Sin Function')
xlabel ('Time')
ylabel ('Amplitude')
subplot(3,1,2)
stem(y)
Title ('Graph of Cos Function')
xlabel ('Time')
ylabel ('Amplitude')
subplot(3,1,3)
stem(z)
Title ('Graph of Convolution between Sin and Cos')
xlabel ('Time')
ylabel ('Amplitude')

OUTPUT RESULTS:

Graph of Sin Function


1

0.5
Amplitude

-0.5

-1
0 50 100 150 200 250
Time
Graph of Cos Function
1

0.5
Amplitude

-0.5

-1
0 50 100 150 200 250
Time
Graph of Convolution between Sin and Cos
100

50
Amplitude

-50

-100
0 50 100 150 200 250 300 350 400 450
Time

(a) Plot of Continuous Convolution


Graph of Sin Function
1

0.5
Amplitude

-0.5

-1
0 50 100 150 200 250
Time
Graph of Cos Function
1

0.5
Amplitude

-0.5

-1
0 50 100 150 200 250
Time
Graph of Convolution between Sin and Cos
100

50
Amplitude

-50

-100
0 50 100 150 200 250 300 350 400 450
Time

(b) Plot of Discrete Convolution

VIVA-QUESTIONS:

1. What is linear convolution?


2.What is the difference between linear and circular convolution?
3.How to calculate output length of the linear and circular convolution?
EXPERIMENT NO. 07
AIM: To generate uniform random numbers between (0, 1).

SOFTWARE: MATLAB (Version: 7.7.0 R2008b)

PROGRAM:
Code to generate uniform random numbers -

m= input(‘m=’)
n= input(‘n=’)
rand(m,n)

OUTPUT RESULT:

When code is RUN, on command window we will see-

m= 2 (press enter)

n= 2 (press enter)

ans =

0.8147 0.1270

0.9058 0.9134

A 2*2 Matrix containing random nos. between 0 and 1 will be displayed as output.

VIVA-QUESTIONS:
1. Explain different properties of system.
2.What do you mean by statement subplot (3,3,1).
3.What is the difference between linear and circular convolution?
EXPERIMENT NO. 8
AIM: To generate random sequences with arbitrary distributions, means and variances for
following :

(a) Rayleigh distribution


(b) Normal distributions: N(0,1).
(c) Gaussian distribution: N(μ,σ).
(d). random binary wave.

SOFTWARE: MATLAB (Version: 7.7.0 R2008b)

PROGRAM:

Code #
(A) B= input(‘B=’)

m= input(‘m=’)

n= input(‘n=’)

R = raylrnd(B,m,n)

(B) mu= input(‘mu=’)

sigma= input(‘sigma=’)

m= input(‘m=’)

n= input(‘n=’)

R = normrnd(mu,sigma,m,n)

(C) Repeat program (B) with mu=0 and sigma=1

(D) m= input(‘m=’)
n= input(‘n=’)
rand(m,n)

OUTPUT RESULT:
When code is RUN, on command window we will see-

B=? (After entering 100)

B=
100

m=? (After entering 5)

m= 5
n=? (After entering 5)

n=
5

R = (Rayleigh distributed Random sequences generated)

145.9626 121.8608 169.6138 200.5199 155.8028


131.8673 87.1104 82.7053 132.9416 88.7425
195.3473 123.7033 163.556292.9506 141.6105
41.9898 193.096746.7431 125.5840 78.5055
93.1316 160.7421 124.77483.0698 144.9276

mu=? (After entering mean=3)

mu =
0

sigma=? (After entering variance=10)

sigma =
1

m=? (After entering 5)

m=
5

n=? (After entering 5)

n=
5

R = (Normally distributed Random sequences generated)


-1.0115 0.1317 0.4542 0.3792 -0.7335
1.1460 0.2244 -0.0725 0.1238 0.6968
-0.1535 -0.2894 -0.6710 -0.0817 -0.4511
2.9034 0.1537 1.4552 -0.9469 -0.4695
-0.2212 -0.9354 -0.6542 0.5759 -1.5336
(d). When code is RUN, on command window we will see-

m= 2 (press enter)

n= 2 (press enter)

ans =

0.8147 0.1270
0.9058 0.9134

A 2*2 Matrix containing random nos. between 0 and 1.

RESULT: We have successfully generated random sequences with arbitrary distributions,


means and variances.

VIVA-QUESTIONS:

1. What is a probability distribution and a random variable?

2. Define expectation, variance and standard deviation.

3. What is sampling theorem?

4. What do you mean by process of reconstruction?

5. What are techniques of reconstructions?

6. What do you mean aliasing? What is the condition to avoid aliasing for sampling?
EXPERIMENT NO. 9
AIM : To develop program for computing discrete Fourier Transform (DFT) and inverse
discrete Fourier Transform (IDFT).

APPARATUS : PC having MATLAB software.

PROGRAM :
DFT :
%prog for computing discrete Fourier Transform
clc;clear all;close all;
x =input('Enter the sequence '); %x =[0 1 2 3 4 5 6 7]
n = input('Enter the length of Fourier Transform ') %n =8 has to be same as
%the length of sequence
x =fft(x,n);
stem(x);
ylabel('imaginary axis------>');
xlabel('(real axis------>');
title('Exponential sequence');
disp('DFT is');x

IDFT :
% prog for inverse discrete Fourier Transform (IDFT)
clc;clear all;close all;
x =input('Enter length of DFT '); % for best results in power of 2
t = 0:pi/x:pi;
num =[0.05 0.033 0.008];
den =[0.06 4 1];
trans = tf(num,den);
[freq,w] =freqz(num,den,x); grid on;
subplot(2,1,1);plot(abs(freq),'k');
disp(abs(freq));
ylabel('Magnitude');
xlabel('Frequency index');
title('magnitude response');

OUTPUT :
DFT :

Enter the sequence [0 1 2 3 4 5 6 7]


Enter the length of Fourier Transform 8
n= 8

DFT is x = 28.0000 -4.0000 + 9.6569i -4.0000 + 4.0000i -4.0000 + 1.6569i


-4.0000 -4.0000 - 1.6569i -4.0000 - 4.0000i -4.0000 - 9.6569i

IDFT :

Enter length of DFT 4 = 0.0180


0.0166
0.0130
0.0093

GRAPH:
DFT :
Discrete Fourier Transform
10

6
Im a gina ry ax is ------>

-2

-4

-6

-8

-10
1 2 3 4 5 6 7 8
Real axis------>

IDFT:
Magnitude Response
0.02
M a g n it u d e

0.015

0.01

0.005
1 1.5 2 2.5 3 3.5 4
Frequency index

RESULT: We have successfully computed discrete Fourier Transform (DFT) and inverse
discrete Fourier Transform (IDFT).
EXPERIMENT NO. 10
AIM : To develop program for computing circular convolution.

APPARATUS : PC having MATLAB software.

PROGRAM :
%prog for computing circular convolution of sequence
% g =[1 -3 4 2 0 -2] and h =[3 0 1 -1 2 1]
clc;clear all;close all;
g =[1 -3 4 2 0 -2];
h =[3 0 1 -1 2 1];
for i = 1:6,
y(i) =0;
for k = 1:6,
z =mod(6-k+i,6)+1;
y(i)=y(i)+g(z)*h(k);
end
end
disp('The resultant Signal is ');y
stem(y);
ylabel('Amplitude------>');
xlabel('n------>');
title('Circular Convolution');
OUTPUT :
The resultant Signal is y = 6 -3 17 -2 7 -13

GRAPH:
Circular Convolution
20

15

10
A m p litu d e ------>

-5

-10

-15
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
n------>

RESULT: We have successfully programmed for computing circular convolution.


EXPERIMENT NO. 11
AIM: MATLAB code for implementing z-transform and inverse z-transform.

Apparatus : PC having MATLAB software.


Program :
% Program of Z transform and inverse z transform
clc ;
close all;
syms n;
a=2;
x=a^n;
X=ztrans(x); %finding z transform
disp('z tranform of a^n a>1');
disp(X);
syms n;
a=0.5;
x=a^n;
X1=ztrans(x);
disp('z tranform of a^n 0<a<1');
disp(X1);
syms n;
a=2;
x=1+n;
X2=ztrans(x);
disp('z tranform of 1+n');
disp(X2);
A=iztrans(X);
disp('inverse z tranform of a^n a>1');
disp(A);
B=iztrans(X1);
disp('inverse z tranform of a^n 0<a<1');
disp(B);
C=iztrans(X2);
disp('inverse z tranform of 1+n');
disp(C);
OUTPUT:
z tranform of a^n 0<a<1
z/(z - 1/2)

z tranform of 1+n
z/(z - 1) + z/(z - 1)^2

inverse z tranform of a^n a>1


2^n

inverse z tranform of a^n 0<a<1


(1/2)^n

inverse z tranform of 1+n


n+1

RESULT: We have successfully programed for computing z-transform and inverse z-


transform.
EXPERIMENT NO.12
Aim : To develop program for computing inverse Z-transform
Apparatus : PC having MATLAB software.
Program :
%prog for computing the inverse Z-transform by using residuez function
%let x(z) = 1/((1-0.9z-1)^2(1+0.9z-1)) |z|>0.9
b =1;
a = poly([0.9,0.9,-0.9]) % denominator of the polynomial calculated by % poly function
[R,p,C] =residuez(b,a)
[delta,n]= impseq(0,0,7) %call impseq
x = filter(b,a,delta)

Output :

a = 1.0000 -0.9000 -0.8100 0.7290

R = 0.2500
0.5000
0.2500
p = 0.9000
0.9000
-0.9000
C = []

delta = 1 0 0 0 0 0 0 0

n= 0 1 2 3 4 5 6 7

x= 1.0000 0.9000 1.6200 1.4580 1.9683 1.7715 2.1258 1.9132

RESULT: We have successfully programmed for computing inverse Z-transform.


EXPERIMENT NO.13
AIM : To develop program for designing FIR filter.

APPARATUS : PC having MATLAB software.

PROGRAM :
%prog for designing of FIR low pass
% filters using rectangular window
clc;clear all;close all;
rp =input('Enter the pass band ripple ');
rs =input('Enter the stop band ripple ');
fp =input('Enter the pass band freq ');
fs =input('Enter the stop band freq ');
f =input('Enter the sampling freq ');
wp = 2*fp/f;
ws = 2*fs/f;
num = -20*log10(sqrt(rp*rs))-13;
dem = 14.6*(fs-fp)/f;
n = ceil(num/dem);
n1 = n+1;
if (rem(n,2)~=0)
n1 =n;
n = n-1;
end
y = boxcar(n1);
% low pass filter
b = fir1(n,wp,y);
[h,o] = freqz(b,1,256);
m = 20*log(abs(h));
subplot(2,2,1);plot(o/pi,m);
ylabel('Gain in dB ------>');
xlabel('(a) Normalised freq ---->');

OUTPUT :
Enter the pass band ripple 0.05
Enter the stop band ripple 0.04
Enter the pass band freq 1500
Enter the stop band freq 2000
Enter the sampling freq 9000
GRAPH:
G a in in d B ------>
100

-100

-200
0 0.5 1
(a) Normalised freq ---->

RESULT: We have successfully programmed for designing FIR filter.


EXPERIMENT NO. 14
AIM : To develop program for for designing IIR filter.

APPARATUS : PC having MATLAB software.

PROGRAM :

%prog for designing of IIR low pass


% filters using rectangular window
clc;clear all;close all;
rp =input('Enter the pass band ripple ');
rs =input('Enter the stop band ripple ');
wp =input('Enter the pass band freq ');
ws =input('Enter the stop band freq ');
fs =input('Enter the sampling freq ');
w1 =2*wp/fs; w2 = 2*ws/fs;
[n,wn] = buttord(w1,w2,rp,rs);
[b,a] = butter(n,wn);
w =0:0.01:pi;
[h,om] = freqz(b,a,w);
m = 20*log(abs(h));
an = angle(h);
subplot(2,2,1);plot(om/pi,m);
ylabel('Gain in dB ------>');
xlabel('(a) Normalised freq ---->');
title('Low Pass Filter');
subplot(2,1,2);plot(om/pi,an);
ylabel('Phase in Radians ------>');
xlabel('(b) Normalised freq ---->');

OUTPUT :
Enter the pass band ripple 0.5
Enter the stop band ripple 50
Enter the pass band freq 1200
Enter the stop band freq 2400
Enter the sampling freq 10000
GRAPH:

Low Pass Filter


500
Gain in dB ------>

-500

-1000
0 0.5 1
(a) Normalised freq ---->

4
Phase in Radians ------>

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalised freq ---->

RESULT: We have successfully programmed for designing IIR filter.

You might also like