0% found this document useful (0 votes)
3 views40 pages

DSP Lab Manual

The document is a MATLAB tutorial for students at the Indore Institute of Science & Technology, focusing on signal generation, operations, convolution, Z-transform, discrete Fourier transform, and filter design. It includes various experiments with specific aims, along with an introduction to MATLAB's capabilities, commands, and programming structures. The tutorial emphasizes hands-on practice and understanding of MATLAB functions, arrays, plotting, and loops.

Uploaded by

parthsaini818
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views40 pages

DSP Lab Manual

The document is a MATLAB tutorial for students at the Indore Institute of Science & Technology, focusing on signal generation, operations, convolution, Z-transform, discrete Fourier transform, and filter design. It includes various experiments with specific aims, along with an introduction to MATLAB's capabilities, commands, and programming structures. The tutorial emphasizes hands-on practice and understanding of MATLAB functions, arrays, plotting, and loops.

Uploaded by

parthsaini818
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 40

INDORE INSTITUTE OF SCIENCE & TECHNOLOGY

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

Contents
A. Introduction........................................................................................................................................................2
B. Introduction to MATLAB tutorial.....................................................................................................................3

Experiment No: - 01 Signal Generation.....................................................................................................................10


AIM: - (a) To write a MATLAB program for the generation of ‘unit impulse’ signal...........................................12
AIM: - (b) To write a MATLAB program for the generation of ‘Unit step’ sequence [u(n)-u(n-N)].....................12
AIM: - (c) To write a MATLAB program for the generation of ‘Ramp’ sequence................................................13
AIM: - (d) To write a MATLAB program for the generation of ‘Exponential’ sequence.....................................14
AIM: - (e) To write a MATLAB program for the generation of ‘sine’ wave..........................................................15
AIM: - (f) To write a MATLAB program for the generation of ‘cosine’ wave......................................................16

Experiment No: - 02 Signal Operation........................................................................................................................20


AIM: - To write a MATLAB program for Signal Operation like Shifitng, Scaling and Folding............................21

Experiment No: - 03 Convolution................................................................................................................................22


AIM: - (a) Program for linear convolution of the sequence x=[1,2] and h=[1,2,4...................................................23
AIM: - (b) To write a MATLAB program for computing ‘Circular Convolution’.................................................24

Experiment No: - 4 Z Transform.................................................................................................................................26


AIM: - Program for Computation and plot of Z-transform......................................................................................27

Experiment No: - 05 Discrete Fourier Transform........................................................................................................29


AIM: - (a) To write a MATLAB program for computing ‘DFT’ of input sequence...............................................30
AIM: - (b) To write a MATLAB program for compute the IDFT of input sequence.............................................31

Experiment No: - 6 Fast Fourier Transform................................................................................................................34


AIM: - MATLAB program for computing 8-point DIT-FFT of any input sequence..............................................34

Experiment No: - 7 First order low pass filter.............................................................................................................35


AIM: - To plot the magnitude & phase response of first order low pass filter........................................................36

Experiment No: - 8 FIR filter design using window techniques.................................................................................38


AIM: - Design the digital FIR Low pass, High pass, Band pass, and Bandstop filters using Rectangular window.
...................................................................................................................................................................................38

1
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
A. Introduction

MATLAB stands for MATrix LABoratory. It is a matrix processing language that is used for scientific
and engineering data processing. It handles both numeric and symbolic variables and can be used either
interactively (in the Command Window) or through input (‘m’) files. It is sold by MathWorks, Inc.

If you are familiar with MATLAB: this lab will be a review. Take this opportunity to refresh your
memory, fill in any gaps you missed the first time, and improve your knowledge by helping those
students who have not had experience with MATLAB before.

For those new to MATLAB: this lab presents some of the basic capabilities of MATLAB, but it is not a
program that you learn in one lab. I expect you will continue to practice and learn more about MATLAB
throughout other courses. As you work, you can find help in many textbooks, User’s Guides, the
MathWorks web site, by accessing the help window, or type help command or just help. If your lab
partner is familiar with MATLAB already they can assist you, but make sure you understand and do the
exercises yourself.

Before the lab:


Go to the MathWorks web site (www.mathworks.com) Go to Academia, Interactive Tutorials, MATLAB
tutorial. There are about two hours of tutorials here. How much time you spend is up to you, depending
on your previous experience. Those who have been introduced to MATLAB before will probably not
need this at all, but take a look just to see what is there and use it as a reference if needed. For those
brand new to MATLAB, I suggest you check out the MATLAB Fundamentals tutorial under MATLAB
On-Ramp, then come back to other tutorials later as needed.

In addition, look through the tutorial that follows below. This provides a summary of commands that
should be useful as you work through the exercises that follow. Look it over quickly before the lab, then
refer to it as needed in the lab – its not going to make a lot of sense until you try it!

2
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
B. Introduction to MATLAB tutorial
Using interactive mode
In the Command Window, type in an equation and hit enter, just like using a calculator. The
order of operation is: exponentiation (^) first, then multiplication and division (* /), then addition and
subtraction (+ -). You can always use parentheses. For example, typing 2 + 3 * 5 – 4 * 2 + 2^3 gives the
same as 2 + (3*5) – (4*2) + 23 = 17 (try it!)

Variable Names
Names must start with a letter, then you can use any letters, numbers, or underscore ( _ ) up to 31
characters long. Variables are case sensitive and cannot contain any punctuation marks. Avoid using
reserved names (sin, pi, i, j, etc.) to avoid confusion. The command clear will clear the memory of any
previous assignments.
Some special symbols:
% comments – anything on the same line after this is not an operation
… Continue on next line
; suppresses printing to the screen (when used at the end of a line), or starts a new line in an array
: creates an array (a:b:c creates an array from a to c in steps of b)

Built-in functions
There are many built in functions. Most are obvious, such as sin(x), cos(x), etc. Some other useful
ones are: sqrt(x), exp(x) and mean(x). Sometimes they are not so obvious, such as log(x) = natural log,
log10(x) = common log (base 10). There are many more! A useful command is lookfor. For example,
typing look for plot will return all the functions associated with plots. Then you can use help to get the
exact syntax.

Arrays
Variables can be scalars, vectors or matrices without any declaration. Vectors and matrices are entered in
square brackets []. Some examples:
A = 2 (scalar),
B = [1 2 3] (row vector),
C = [1 2 3]’ or C = [1; 2; 3] (column vector),
D = [1 2 3; 4 5 6; 7 8 9] (3x3 matrix)
Arrays can be created with the colon ( : ) operator or with the linspace or logspace command. For
example, x = 0:0.1:1 (from 0 to 1 in 0.1 steps) or linspace(0,1,11) (from 0 to 1 with 11 elements) both
create x = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1].
MATLAB’s strongest feature is its ability to manipulate vectors and matrices. Here are some useful
matrix operations:
* multiplication – scalar, vector or matrix, depending on the variable type
3
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
‘ transpose
det(A) determinant
inv(A) inverse
length(A) length of vector A
size(A) gives (m,n) for an m x n matrix
“. “Element-by-element operation For example,.* causes each element of a matrix to be multiplied by the
corresponding element of another matrix, rather than performing matrix multiplication.
A typical problem is to solve for a vector X in the equation AX = B. This can be done one of two ways:
X = inv (A)*B or X = A\B. In most cases, either operation is fine. In the case of an ill-conditioned
matrix, the second method will be more efficient and accurate.
Some special matrices that may come in handy are zeros (n), ones (n), [], rand (n) and eye (n).
To address a matrix element a ij, the notation is A(i,j). The colon symbol ( : ) indicates all of a row or
column. Saying a: b indicates rows or columns from a to b. For example, A(:,1:2) addresses all rows,
columns 1 – 2, as shown:
» A = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]
A=
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
» A(:,1:2)

ans =
1 2
5 6
9 10
13 14
M-Files (scripts & functions)
Usually you will want to save programs in a file to debug and to use again. Choose New from
File menu to open the Editor Window. Type all commands in the editor and save the file as filename.m.
Run the file from the Debug menu, or use the Run button on the toolbar, or type filename in the
Command Window.
Ordinary script files are simply a self-contained list of commands, while functions are used to
pass variables in and out. The first line of the function file must have the format:
function output = filename(inputs) or function [outputs] = filename(inputs)
Run the file by typing filename(input values)

4
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
The MathWorks tutorials “Automating Analysis with Scripts” and “Writing Functions” have more
information.
Polynomials
Polynomials are represented by a vector of coefficients. For example, the polynomial
x2 + 2x + 3 would be represented by p = [1 2 3]. Some useful polynomial commands:
polyval(p,x) - evaluate the polynomial at the given value of x
roots(p) - find the roots of the polynomial
p = poly(r) - construct the polynomial from roots r = [r1, r2, …]
conv, deconv - multiply or divide polynomials

Input and Output


Besides using functions, another option to get data into a program is to prompt the user for input.
The line:
x = input(‘enter number’)
will cause the instruction “enter number” to appear on the screen, then assign the number entered by the
user to the variable x.
There are many options for displaying outputs. The result of any command without ; at the end will show
on the screen. Some other examples are given here.
disp(x) - display output without variable name
num2str(x) - convert output to string. Example:
result = [‘The number is ‘ num2str(x)]
disp(result)
fprintf - display formatted output.
\n - start a new line
%x.yz - formats a number with x = field width, y = precision and z = notation
(e for exponential, f for floating point, i for integer)
Example: fprintf(‘The answer is %x.yz’,variable)
This command has many options, type help fprintf to see more.

Plots
The command plot(x,y) (where x and y are arrays) creates a 2-dimensional plot of y versus x.
The arrays need to be the same size.
The commands to add a plot title, axes labels and legend are title, xlabel, ylabel and legend.
They all use the format command(‘…’), for example, title(‘My Plot’). These, as well as other
additions like text boxes and arrows, can also be added in the graphics window after the plot is
drawn.
5
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
There are many other plotting features, more than will be listed in this tutorial. A few useful ones
are given here. Type help plot for more information.
plot multiple lines on one graph: plot(x1, y1, x2, y2, …)
use different line styles, colors and data point symbols: plot(x,y,‘…’)
turn grid on or off: grid on or grid off
keep the plot window open to add another plot: hold on (hold off)
change axes range: axis([xmin xmax ymin ymax])
make multiple plots on one page: subplot(a,b,c), plot(x,y) makes a rows and b columns of
subplots, and puts this plot in position c
3-d plots include surf, mesh and contour
Try this example:
x = [1 2 3]
y1 = [4 6 10]
y2 = [5 7 11]
plot(x, y1, ‘r’, x, y2, ‘k--’)

The MathWorks tutorial “Visualizing Data” has more information.

LOOPS – For, While, If


The format of a for loop is given below. This loop will run through the given values of t (from
start to stop using the given step size) then end.
for t = start:stepsize:stop
:
commands
:
end
The format of a while loop is given below. This loop will run as long as the given logical
condition is true, and will end when the logical condition becomes false.
while logical condition
:
commands
:
end
The format of logical operators is:
<= less than or equal to (e.g., while x <= y)

6
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
>= greater than or equal to
~= not equal to
== equal to
The format of an if loop is given below. The commands in the if loop will only be executed if the
condition is true, otherwise they will be ignored.
if logical conditions
:
commands
:
end
Some variations: if logical conditions
:
commands
:
else
:
other commands
:
end

This process can be continued with elseif. The command break jumps to the next statement after the
loop.

Procedure:
I. This first section consists of exercises to try on your own for practice, as much as you need depending
on your experience. Take your time and make sure you understand everything in this section before
going on.

1. Try a few commands in interactive mode. Example: x = 1:10


y = x.^2
What happens if you don’t use the dot command? What happens if you end the line with ; ?

2. Enter matrices, multiply, find the inverse and determinant.


Example: A = [1 2 3; 4 5 6; 7 8 9]
B = [1 3 5; 2 4 6; 0 0 1]
A*B
det(A)

7
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
inv(B)
What does A.*B do?
3. Write for, while and if loops. Examples:
a) for k = 1:10
y = 2^k
end
b) k=0
while k<=10
y = 2^k
k = k+1
end
c) k=1
if k < 10
y = 2^k
else
disp(‘ERROR!’)
end
Be careful of “endless” while loops! For example, what would happen in b) if you did not increment k to
k+1?

4. Practice polynomial functions. Example: p = [1 2 3 4]


roots(p)
x = 1:10
polyval(p,x)

5. Make a plot. Example: x = 1:.01:10;


y1 = exp(x);
y2 = exp(2*x);
plot(x,y1,x,y2)

Draw the two lines in different line styles and colors (see help plot.) Add axes labels, a title and a legend
to your plot.

8
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
6. Write, save and run an m-file. Use one of the above examples, or make up your own.

7. Explore the help window and the help command.

9
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 01 Signal Generation

Syntax used in programs:


 clc Clear command window.
clc clears the command window and homes the cursor.

 clear Clear variables and functions from memory.


 clear removes all variables from the workspace. clear VARIABLES does the same thing.
 clear GLOBAL removes all global variables.
 clear FUNCTIONS removes all compiled M- and MEX-functions.
 clear ALL removes all variables, globals, functions and MEX links.
 clear ALL at the command prompt also removes the Java packages import list.
 clear IMPORT removes the Java packages import list at the command prompt. It cannot be used
in a function.

 close Close figure.


 close(H) closes the window with handle H.
 CLOSE, by itself, closes the current figure window.
 close('name') closes the named window.
 close ALL closes all the open figure windows.
 close ALL HIDDEN closes hidden windows as well.
 STATUS = close(...) returns 1 if the specified windows were closed and 0 otherwise.

 subplot Create axes in tiled positions.

H = subplot(m,n,p) or subplot(mnp), breaks the Figure window into an m-by-n matrix of small axes, selects
the p-th axes for the current plot, and returns the axis handle. The axes are counted along the top row of the
Figure window, then the second row, etc. For example,
subplot(2,1,1), PLOT(income)
subplot(2,1,2), PLOT(outgo)
Plots income on the top half of the window and outgo on the bottom half.

 stem Discrete sequence or "stem" plot.


stem(Y) plots the data sequence Y as stems from the x axis terminated with circles for the data value.
stem(X,Y) plots the data sequence Y at the values specified in X.
H = stem(...) returns a vector of line handles.

 xlabel X-axis label.


xlabel('text') adds text beside the X-axis on the current axis.
xlabel('text','Property1',PropertyValue1,'Property2',PropertyValue2,...) sets the values of the specified
properties of the xlabel.
H = xlabel(...) returns the handle to the text object used as the label.

 ylabel Y-axis label.


10
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
ylabel('text') adds text beside the Y-axis on the current axis.
ylabel('text','Property1',PropertyValue1,'Property2',PropertyValue2,...) sets the values of the specified properties
of the ylabel.
H = ylabel(...) returns the handle to the text object used as the label.

 zeros Zeros array.


zeros(N) is an N-by-N matrix of zeros. zeros(M,N) or zeros([M,N]) is an M-by-N matrix of zeros.
zeros(M,N,P,...) or zeros([M N P ...]) is an M-by-N-by-P-by-... array of zeros.

 ones Ones array.


ones(N) is an N-by-N matrix of ones. ones(M,N) or ones([M,N]) is an M-by-N matrix of ones.ones(M,N,P,...)
or ones([M N P ...]) is an M-by-N-by-P-by-... array of ones.

 input Prompt for user input.


R = input('How many apples') gives the user the prompt in the text string and then waits for input from the
keyboard. The input can be any MATLAB expression, which is evaluated, using the variables in the current
workspace, and the result returned in R. If the user presses the return key without entering anything, input
returns an empty matrix.

 exp Exponential.
exp(X) is the exponential of the elements of X, e to the X. For complex Z=X+i*Y, exp(Z) = exp(X)*(COS(Y)
+i*SIN(Y)).

 cos Cosine.
cos(X) is the cosine of the elements of X.

 sin Sine.
sin(X) is the sine of the elements of X.

 plot Linear plot.


plot(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the
rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, length(Y)
disconnected points are plotted.

Experiment No: - 01(a)

11
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
AIM: - (a) To write a MATLAB program for the generation of ‘unit impulse’ signal.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window
PROGRAM:-
>> clear all
>> t = -2:1:2;
>> y = [zeros(1,2),ones(1,1),zeros(1,2)];
>> subplot(2,2,1);
>> stem(t,y);
>> ylabel('Amplitude -->');
>> xlabel('(a) n -->');

RESULTS:-
Thus the MATLAB program for unit-impulse signal was performed and the output was
verified.
OUTPUT:

Experiment No: - 01(b)

AIM: - (b) To write a MATLAB program for the generation of ‘Unit step’ sequence [u(n)-u(n-
N)].

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

12
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

PROGRAM:-
>> clear all
>> n = input('enter the N values');
enter the N values 7
>> t = 0:1:n-1;
>> y1 = ones(1,n);
>> subplot(2,2,2);
>> stem(t,y1);
>> ylabel('Amplitude -->');
>> xlabel('(b) n -->');

RESULTS: - Thus the MATLAB program for unit step sequence was performed and the output was
verified.

OUTPUT:

Experiment No: - 01(c)

AIM: - (c) To write a MATLAB program for the generation of ‘Ramp’ sequence

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window
PROGRAM:-
>> clear all
>> n1 = input('enter the length of ramp sequence');
enter the length of ramp sequence 7
>> t = 0:n1;
>> subplot(2,2,3);
>> stem(t,t);
>> ylabel('Amplitude -->');
>> xlabel('(c) n -->');
13
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

RESULTS:-
Thus the MATLAB program for ramp sequence was performed and the output was verified.

OUTPUT:

Experiment No: - 01(d)

AIM: - (d) To write a MATLAB program for the generation of ‘Exponential’ sequence

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window
PROGRAM:-
>> clear all
>> n2 = input('enter the length of exponential sequence');
enter the length of exponential sequence 7
>> t = 0:n2;
>> a = input('enter the a value');
enter the a value -2
>> y2 = exp(a*t);
>> subplot(2,2,4);
>> stem(t,y2);
>> ylabel('Amplitude -->');
>> xlabel('(d) n -->');

RESULTS:-
Thus the MATLAB program for exponential sequence was performed and the output was
verified.
OUTPUT:
14
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

Experiment No: - 01(e)

AIM: - (e) To write a MATLAB program for the generation of ‘sine’ wave.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-

>> clear all


>> t = 0:0.01:pi;
15
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
>> y = sin(2*pi*t);
>> figure(2);
>> subplot(2,1,1);
>> plot(t,y);
>> ylabel('Amplitude -->');
>> xlabel('(a) n -->');

RESULTS:-
Thus the MATLAB program for sine wave was performed and the output was verified.

OUTPUT:

Experiment No: - 01(f)

AIM: - (f) To write a MATLAB program for the generation of ‘cosine’ wave.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window
PROGRAM:-
>> clear all
>> t = 0:0.01:pi;
>> y = cos(2*pi*t);
>> subplot(2,1,2);
>> plot(t,y);
>> ylabel('Amplitude -->');
>> xlabel('(b) n -->');

RESULTS:-
Thus the MATLAB program for cosine wave was performed and the output was verified.

OUTPUT:
16
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

PROGRAM:-

clear all
a=input('Enter the range of the cycle or Enter X-Axis Range for the Waveform \n a = ');

17
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
i='y';
while(i=='y')
b=input('Press ....\n 1.Sine Waveform \n 2.Cosine Waveform \n 3.Exp. Waveform \n 4.Unit Step
Signal \n 5.Ramp Signal \n 6.Exit \n Enter Your Choice.......');
t=-a*pi:0.1:a*pi;
t1=0:1:a-1;

switch(b)

case 1
f=sin(t);
a1=stem(t,f)
xlabel('Time')
ylabel('sin(t)')
grid
title('Sine Waveform')

case 2
f=cos(t);
a2=stem(t,f)
xlabel('Time')
ylabel('cos(t)')
grid
title('Cosine Waveform')

case 3
b=input('enter the value of b for e^bt \n b = ');
f=exp(b*t);
a3=stem(t,f)
xlabel('Time')
ylabel('exp(b*t)')
grid
title('Exp. Waveform')

case 4
f=ones(1,a);
a4=stem(t1,f)
xlabel('Time')
ylabel('u(t)')
grid
title('Unit step signal')

case 5
a5=stem(t1,t1)
xlabel('Time')
ylabel('r(t)')
grid
title('Ramp Signal')
18
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

case 6
break;

otherwise
display('Wrong Choice')
end
i=input('Do you want to cont...... ? \n Press (y/n)', 's');
end

OUTPUT:

Enter the range of the cycle or Enter X-Axis Range for the Waveform
a= 2

Press....

1. Sine Waveform
2. Cosine Waveform
3. Exp. Waveform
4. Unit step Signal
5. Ramp Signal
6. Exit

Enter Your Choice.......2

Experiment No: - 02 Signal Operation

Syntax used in programs:

 INPUT Prompt for user input.


19
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
R = INPUT('How many apples') gives the user the prompt in the text string and then waits
for input from the keyboard.
The input can be any MATLAB expression, which is evaluated, using the variables in the
current workspace, and the result returned in R. If the user presses the return key without
entering anything, INPUT returns an empty matrix.

R = INPUT('What is your name','s') gives the prompt in the text string and waits for
character string input. The typed input is not evaluated; the characters are simply
returned as a MATLAB string.

The text string for the prompt may contain one or more '\n'. The '\n' means skip to the
beginning of the next line. This allows the prompt string to span several lines. To output
just a '\' use '\\'.

 DISP Display array.


DISP(X) displays the array, without printing the array name. In all other ways it's
the same as leaving the semicolon off an expression except that empty arrays don't
display. If X is a string, the text is displayed.

Experiment No: - 02

AIM: - To write a MATLAB program for Signal Operation like Shifitng, Scaling and Folding

20
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-

a=input ('Enter the Length of sequence');


n1=input ('Enter the amount to be delayed');
n2=input ('Enter the amount to be advanced');
n=-a:1:a;
x = input('Enter the input Sequences');

subplot (3,1,1);
stem(n,x);
title('Signal x(n)');
m=n+n1;
y=x;
subplot(3,1,2);
stem(m,y);
title('Delayed signal x(n-n1)');
t=n-n2;
z=x;
subplot(3,1,3);
stem(t,z);
title('Advanced signal x(n+n2)');

OUTPUT

Experiment No: - 03 Convolution


Syntax used in program:
 length Length of vector.
21
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
length(X) returns the length of vector X. It is equivalent to MAX(SIZE(X)) for non-empty arrays and
0 for empty ones.

 max Largest component.

For vectors, max(X) is the largest element in X. For matrices, max(X) is a row vector containing the
maximum element from each column. For N-D arrays, max(X) operates along the first non-singleton
dimension.
max(X,Y) returns an array the same size as X and Y with the largest elements taken from X or Y. Either one
can be a scalar.
Example: If X = [2 8 4 then max(X,[],1) is [7 8 9],7 3 9]
max(X,[],2) is [8 and max(X,5) is [5 8 59],7 5 9].
 for Repeat statements a specific number of times.
The general form of a for statement is:
for variable = expr, statement, ..., statement END
The columns of the expression are stored one at a time in the variable and then the following
statements, up to theEND, are executed. The expression is often of the form X:Y, in which case its
columns are simply scalars. Some examples (assume N has already been assigned a value).
for I = 1:N,
for J = 1:N,
A(I,J) = 1/(I+J-1);
END
END
for S = 1.0: -0.1: 0.0, END steps S with increments of -0.1
for E = EYE(N), ... END sets E to the unit N-vectors.

Long loops are more memory efficient when the colon expression appears in the for statement since the
index vector is never created. The BREAK statement can be used to terminate the loop prematurely.
 ' Complex conjugate transpose.
X' is the complex conjugate transpose of X.
B = ctranspose(A) is called for the syntax A' (complex conjugate transpose) when A is an object.

Experiment No: - 03(a)

AIM: - (a) Program for linear convolution of the sequence x=[1,2] and h=[1,2,4].

22
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-
>> clear all;
>> x = input('enter the 1st sequence');
enter the 1st sequence [1 2]
>> h = input('enter the 2nd sequence');
enter the 2nd sequence [1 2 4]
>> y = conv(x,h);
>> figure;
>> subplot(3,1,1);
>> stem(x);
>> ylabel('Amplitude -->');
>> xlabel('(a) n-->');
>> subplot(3,1,2);
>> stem(h);
>> ylabel('Amplitude -->');
>> xlabel('(b) n -->');
>> subplot(3,1,3);
>> stem(y);
>> ylabel('Amplitude -->');
>> xlabel('(c) n -->');
>> disp('The resultant signal is');
The resultant signal is
>> y
y=
1 4 8 8

RESULTS:-
Thus the MATLAB program for computing the linear convolution of two sequences was
performed and the output was verified.

OUTPUT:
Figure below shows the discrete input signals x(n) and h(n) and the convolved output y(n).

23
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

Experiment No: - 03(b)

AIM: - (b) To write a MATLAB program for computing ‘Circular Convolution’.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window
PROGRAM:-
>> clear;
>> a = input('enter the sequence x(n) =');
enter the sequence x(n) = [1 2 4]
>> b = input('enter the sequence h(n) =');
enter the sequence h(n) = [1 2]
>> n1 = length(a);
>> n2 = length(b);
>> N = max(n1,n2);
>> x = [a zeros(1,(N-n1))];
>> for i = 1:N
k = i;
for j =1:n2
H(i,j) = x(k)*b(j);
k = k-1;

24
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
if(k == 0)
k = N;
end
end
end
>> y = zeros(1,N);
>> M = H';
>> for j = 1:N
for i = 1:n2
y(j) = M(i,j)+y(j);
end
end
>> disp('The output sequence is y(n)=');
The output sequence is y(n)=
>> disp(y);
9 4 8
>> stem(y);
>> title('Circular Convolution');
>> xlabel('n');
>> ylabel('y(n)');

RESULTS:- Thus the MATLAB program for computing the circular convolution of two sequences was
performed and the output was verified.

OUTPUT:

25
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 4 Z Transform

Syntax used in program:

 tf2zp Transfer function to zero-pole conversion

[Z,P,K] = tf2zp(NUM,DEN) finds the zeros, poles, and gains:

from a SIMO transfer function in polynomial form:

Vector DEN specifies the coefficients of the denominator in descending powers of s. Matrix NUM indicates
the numerator coefficients with as many rows as there are outputs. The zero locations are returned in the
columns of matrix Z, with as many columns as there are rows in NUM. The pole locations are returned in
column vector P, and the gains for each numerator transfer function in vector K.
 zplane Z-plane zero-pole plot.

zplane(Z,P) plots the zeros Z and poles P (in column vectors) with the unit circle for reference. Each zero is
represented with a 'o' and each pole with a 'x' on the plot. Multiple zeros and poles are indicated by the
multiplicity number shown to the upper right of the zero or pole. zplane(Z,P) where Z and/or P is a matrix,
plots the zeros or poles in different columns using the colors specified by the axes ColorOrder property.

 tf Creation of transfer functions or conversion to transfer function.

Creation:
SYS = tf(NUM,DEN) creates a continuous-time transfer function SYS with numerator(s) NUM and
denominator(s) DEN. The output SYS is a tf object.
SYS = tf(NUM,DEN,TS) creates a discrete-time transfer function with sample time TS (set TS=-1 if the
sample time is undetermined).

26
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 4

AIM: - Program for Computation and plot of Z-transform.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-
>> clear all;
>> num = input('enter the numerator polynomial:');
enter the numerator polynomial:[2 3 1]
>> den = input('enter the denominator polynomial:');
enter the denominator polynomial:[1 2 0 2 3 4]
>> trans = tf(num,den);
>> [zeros poles gain] = tf2zp(num,den);
>> disp('Poles of transfer function are:');
Poles of transfer function are:
>> disp(poles);
-2.2797
0.7957 + 1.0242i
0.7957 - 1.0242i
-0.6559 + 0.7829i
-0.6559 - 0.7829i
>> disp('zeros of transfer function are:');
zeros of transfer function are:
>> disp(zeros);
-1.0000
-0.5000
>> disp('gain of transfer function is:');
gain of transfer function is:
>> disp(gain);
2
>> zplane(num,den);

RESULTS:-
Thus the MATLAB program for Z-transform (Computation and plot) was performed and the
output was verified.

OUTPUT:
The gain responses of low-pass, high-pass, bandpass and bandstop filters using Rectangular window are shown in
figure.

27
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

28
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 05 Discrete Fourier Transform

Syntax used in program:

 fft Discrete Fourier transform.


fft(X) is the discrete Fourier transform (DFT) of vector X. For matrices, the fft operation is applied to
each column. For N-D arrays, the fft operation operates on the first non-singleton dimension.

fft(X,N) is the N-point FFT, padded with zeros if X has less than N points and truncated if it has
more.

fft(X,[],DIM) or fft(X,N,DIM) applies the fft operation across the dimension DIM.

For length N input vector x, the DFT is a length N vector X, with elements N

X(k) = sum x(n)*exp(-j*2*pi*(k-1)*(n-1)/N), 1 <= k <= N. n=1

The inverse DFT (computed by IFFT) is given by N

x(n) = (1/N) sum X(k)*exp( j*2*pi*(k-1)*(n-1)/N), 1 <= n <= N. k=1

 .* Array multiply.

X.*Y denotes element-by-element multiplication. X and Y must have the same dimensions unless
one is a scalar.A scalar can be multiplied into anything.
C = times(A,B) is called for the syntax 'A .* B' when A or B is an object.

29
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 05(a)

AIM: - (a) To write a MATLAB program for computing ‘DFT’ of input sequence.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window
PROGRAM:-
close all;
clear all;
N=input('How many point DFT do you want?');
x2=input('Enter the sequence=');
n2=length(x2);

x2=[x2 zeros(1,N-n2)];
for k=1:N
for n=1:N
w=exp((-2*pi*i*(k-1)*(n-1))/N);
%prev.step=>evaluating w-matrix
x(n)=w;
end
c(k,:)=x
end
r=[c]*[x2']
%plotting magnitude and angle
subplot(211)
stem(abs(r));
title('DFT-absolute value');
subplot(212)
stem(angle(r));
title('DFT-angle');

RESULTS:-
Thus the MATLAB program for computing the DFT of input sequence was performed and the
output was verified.

OUTPUT:
How many point DFT do you want?10

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


r=
33.0000
-12.5172 + 6.2941i
30
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
-3.5451 - 4.0287i
2.0172 - 2.5757i
2.0451 + 0.1388i
1.0000 + 0.0000i
2.0451 - 0.1388i
2.0172 + 2.5757i
-3.5451 + 4.0287i
-12.5172 - 6.2941i

Experiment No: - 5(b)

AIM: - (b) To write a MATLAB program for compute the IDFT of input sequence.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-

close all;
clear all;
N=input('How many point IDFT do you want?');
x2=input('Enter the sequence=');
n2=length(x2);

x2=[x2 zeros(1,N-n2)];
31
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
for k=1:N
for n=1:N
w=exp((2*pi*i*(k-1)*(n-1))/N);
%prev.step=>evaluating w-matrix
x(n)=w;
end
c(k,:)=x;
end
r=[c]*[x2']
r=r/n2;
%plotting magnitude and angle
subplot(211)
stem(abs(r));
title('IDFT-absolute value');
subplot(212)
stem(angle(r));
title('IDFT-angle');

RESULTS:-
Thus the MATLAB program for computing the IDFT of input sequence was performed and the
output was verified.

OUTPUT:

How many point IDFT do you want?10

Enter the sequence=[33.0000 -12.5172 + 6.2941i -3.5451 - 4.0287i 2.0172 - 2.5757i 2.0451 + 0.1388i 1.0000 +
0.0000i 2.0451 - 0.1388i 2.0172 + 2.5757i -3.5451 + 4.0287i -12.5172 - 6.2941i]

r=

10.0000
0.0000 + 0.0000i
40.0001 + 0.0000i
70.0000 - 0.0000i
59.9997 - 0.0000i
50.0000 - 0.0000i
40.0002 - 0.0000i
29.9999 - 0.0000i
20.0001 + 0.0000i
10.0000 + 0.0000i

32
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

33
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 6 Fast Fourier Transform

AIM: - MATLAB program for computing 8-point DIT-FFT of any input sequence.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-
>> clear all
>> x = input('enter the sequence');
enter the sequence [0 1 2 3 4 5 6 7]
>> n = input('enter the length of fft');
enter the length of fft 8
>> k = 0:n-1;
>> X = fft(x,n);
>> stem(X);
>> ylabel('Imaginary axis -->');
>> xlabel('Real axis -->');
>> X
X=
Columns 1 through 6
28.0000 -4.0000 + 9.6569i -4.0000 + 4.0000i -4.0000 + 1.6569i -4.0000 -4.0000 - 1.6569i
Columns 7 through 8
-4.0000 - 4.0000i -4.0000 - 9.6569i

RESULTS:-
Thus the MATLAB program for computing the FFT of input sequence was performed and the
output was verified.

OUTPUT:

Experiment No: - 7 First order low pass filter

34
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Syntax used in program:

 ceil Round towards plus infinity.

ceil(X) rounds the elements of X to the nearest integers towards infinity.

 boxcar Boxcar window.

W = boxcar(N) returns the N-point rectangular window.


 rem Remainder after division.

rem(x,y) is x - n.*y where n = fix(x./y) if y ~= 0. If y is not an integer and the quotient x./y is within roundoff
error of an integer, then n is that integer. By convention, rem(x,0) is NaN. The input x and y must be real
arrays of the same size, or real scalars.

 freqz Digital filter frequency response.

[H,W] = freqz(B,A,N) returns the N-point complex frequency response vector H and the N-point frequency
vector W in radians/sample of the filter. The frequency response is evaluated at N points equally spaced around
the upper half of the unit circle. If N isn't specified, it defaults to 512.

 fir1 FIR filter design using the window method.

B = fir1(N,Wn) designs an N'th order lowpass FIR digital filter and returns the filter coefficients in length N+1
vector B. The cut-off frequency Wn must be between 0 < Wn < 1.0, with 1.0 corresponding to half the sample
rate. The filter B is real and has linear phase. The normalized gain of the filter at Wn is -6 dB.

 abs Absolute value.

abs(X) is the absolute value of the elements of X. When X is complex, abs(X) is the complex modulus
(magnitude) of the elements of X.

Experiment No: - 7

35
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
AIM: - To plot the magnitude & phase response of first order low pass filter.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-

clear all;
b1= [0.2 0.2]
a1= [1 -0.6]
w= 0:0.01:pi;
h1=freqz(b1,a1,w)
subplot(2,2,1)
plot(w/pi, abs(h1))
xlabel('normalised frequency');
ylabel('Magnitude');
Hold on;
subplot(2,2,2)
plot(w/pi, 20*log10(abs(h1)))
xlabel('normalised frequency');
ylabel('Magnitude in db');
Hold on;
subplot (2,1, 2)
plot(w/pi, angle(h1))
xlabel('normalised frequency');
ylabel('phase');
Hold on;

RESULTS:-
Thus the MATLAB program for designing of First order low pass filter was performed and the
output was verified.

OUTPUT:

The Magnitude and phase responses of First Order low pass filter are shown in figure.

36
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

37
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
Experiment No: - 8 FIR filter design using window techniques

AIM: - Design the digital FIR Low pass, High pass, Band pass, and Bandstop filters using
Rectangular window.

PROCEDURE:-
 Open MATLAB
 Open new M-file
 Type the program
 Save in current directory
 Compile and Run the program
 For the output see command window\ Figure window

PROGRAM:-

>> clear all;


>> rp = input('enter the passband ripple');
enter the passband ripple 0.05
>> rs = input('enter the stopband ripple');
enter the stopband ripple 0.04
>> fp = input('enter the passband freq');
enter the passband freq 1500
>> fs = input('enter the stopband freq');
enter the stopband freq 2000
>> f = input ('enter the saampling freq');
enter the sampling freq 9000
>> 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*log10(abs(h));
>> subplot(2,2,1);
>> plot(o/pi,m);
>> ylabel('Gain in dB -->');
38
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING
>> xlabel('(a) Normalized frequency -->');

High pass filter:

>> b = fir1(n,wp,'high',y);
>> [h,o] = freqz(b,1,256);
>> m = 20*log10(abs(h));
>> subplot(2,2,2);
>> plot(o/pi,m);
>> ylabel('Gain in dB -->');
>> xlabel('(b) Normalized frequency -->');

Band-pass filter:

>> wn = [wp,ws];
>> b = fir1(n,wn,y);
>> [h,o] = freqz(b,1,256);
>> m = 20*log10(abs(h));
>> subplot(2,2,3);
>> plot(o/pi,m);
>> ylabel('Gain in dB -->');
>> xlabel('(c) Normalized frequency -->');

Band-stop filter:

>> b = fir1(n,wp,'stop',y);
>> [h,o] = freqz(b,1,256);
>> m = 20*log10(abs(h));
>> subplot(2,2,4);
>> plot(o/pi,m);
>> ylabel('Gain in dB -->');
>> xlabel('(d) Normalized frequency -->');

RESULTS:-
Thus the MATLAB program for designing of FIR Low pass, High pass, Band pass, and
Bandstop filters using Rectangular window was performed and the output was verified.

OUTPUT:

The gain responses of low-pass, high-pass, bandpass and bandstop filters using Rectangular window are shown in
figure.

39
Name of Student
Roll No.
INDORE INSTITUTE OF SCIENCE & TECHNOLOGY
DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

40
Name of Student
Roll No.

You might also like