0% found this document useful (0 votes)
273 views81 pages

Uet Signals Lab Manual PDF

This document is the lab manual for the Signals and Systems course at the University of Engineering & Technology, Taxila, Pakistan. It contains 8 labs that introduce key concepts in signals and systems including MATLAB, properties of signals and systems, Fourier series, convolution, Laplace transforms, z-transforms, Fourier transforms, and applications to sound and images. The instructors thank the Ghulam Ishaq Khan Institute of Engineering Sciences and Technology for providing this lab manual.

Uploaded by

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

Uet Signals Lab Manual PDF

This document is the lab manual for the Signals and Systems course at the University of Engineering & Technology, Taxila, Pakistan. It contains 8 labs that introduce key concepts in signals and systems including MATLAB, properties of signals and systems, Fourier series, convolution, Laplace transforms, z-transforms, Fourier transforms, and applications to sound and images. The instructors thank the Ghulam Ishaq Khan Institute of Engineering Sciences and Technology for providing this lab manual.

Uploaded by

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

Signals and Systems Lab

Department of Electrical Engineering


University of Engineering & Technology, Taxila, Pakistan

Signals and Systems Page 1


The instructors would like to thank the
Faculty of Electronics Engineering, Ghulam
Ishaq Khan Institute of Engineering Sciences
and Technology, Topi for providing this lab
manual.

Signals and Systems Page 2


Table of Contents
Lab - 1: Introduction to MATLAB ........................................................................................... 7
1.1 MATLAB Help ............................................................................................................................. 7
1.2 Defining variables ..................................................................................................................... 7
1.3 M-files ............................................................................................................................................ 9
1.4 Generating the Plots.............................................................................................................. 10
1.5 Defining Matrices ................................................................................................................... 10
1.6 General Information.............................................................................................................. 14
1.7 Complex Variables and Expressions ............................................................................... 14
1.8 Loops........................................................................................................................................... 15
1.9 Symbolic Calculations Using MATLAB ........................................................................... 15
1.10 Substitutions ............................................................................................................................ 16
1.11 Exercises .................................................................................................................................... 16
1.12 Assessment Sheet................................................................................................................... 17
Lab - 2: Properties of Signals and Systems ....................................................................... 19
2.1 Objectives .................................................................................................................................. 19
2.2 Signals......................................................................................................................................... 19
2.3 Size of a Signal ......................................................................................................................... 19
2.4 Transformation of a Signal ................................................................................................. 19
2.5 Systems ...................................................................................................................................... 22
2.6 Properties of Systems ........................................................................................................... 22
2.7 Exercises .................................................................................................................................... 25
2.8 Assessment Sheet................................................................................................................... 26
Lab - 3: Signals, Periodicity and Harmonics..................................................................... 27
3.1 Objectives .................................................................................................................................. 27
3.2 Unit Step Function ................................................................................................................. 27
3.3 Unit Impulse function ........................................................................................................... 27
3.4 Even and Odd Signals ........................................................................................................... 28
3.5 Periodic Signals....................................................................................................................... 29
3.6 Harmonics ................................................................................................................................. 29
3.7 Exponential and Sinusoidal Signals ................................................................................ 30
3.8 Exercise ...................................................................................................................................... 32
3.9 Assessment Sheet................................................................................................................... 33
Lab - 4: Fourier Series .............................................................................................................. 35
4.1 Objectives .................................................................................................................................. 35
4.2 Fourier Series .......................................................................................................................... 35
4.3 Exercise ...................................................................................................................................... 37
4.4 Assessment Sheet................................................................................................................... 39
Lab - 5: Convolution and Laplace Transform .................................................................. 41
5.1 Objectives .................................................................................................................................. 41
5.2 Linear Time Invariant Systems ......................................................................................... 41
5.3 Impulse Response and Convolution ............................................................................... 41
5.4 Laplace Transform................................................................................................................. 42
5.5 Exercise ...................................................................................................................................... 45
5.6 Assessment Sheet................................................................................................................... 46
Lab - 6: z-Transform and Transfer Functions ................................................................. 47
6.1 Objectives .................................................................................................................................. 47
6.2 z-Transform ............................................................................................................................. 47

Signals and Systems Page 3


6.3 Transfer Function................................................................................................................... 48
6.4 Poles and Zeros ....................................................................................................................... 49
6.5 Partial Fraction Expansions ............................................................................................... 50
6.6 Exercise ...................................................................................................................................... 52
6.7 Assessment Sheet ................................................................................................................... 53
Lab - 7: Fourier Transform ....................................................................................................55
7.1 Objectives .................................................................................................................................. 55
7.2 Fourier Transform ................................................................................................................. 55
7.3 Discrete Fourier Transform (DFT) .................................................................................. 56
7.4 Discrete Time Fourier Transform (DTFT) .................................................................... 57
7.5 Exercises .................................................................................................................................... 58
7.6 Assessment Sheet ................................................................................................................... 59
Lab - 8: Sound and Images ......................................................................................................61
8.1 Objectives .................................................................................................................................. 61
8.2 Sound Signals ........................................................................................................................... 61
8.3 Useful Operations on Sound Signals ............................................................................... 62
8.4 Images in MATLAB ................................................................................................................ 63
8.5 Exercises .................................................................................................................................... 65
8.6 Assessment Sheet ................................................................................................................... 66
Lab - 9: Graphical User Interface ......................................................................................... 67
9.1 Objectives .................................................................................................................................. 67
9.2 Graphical User Interface (GUI) .......................................................................................... 67
9.3 Examples.................................................................................................................................... 68
9.4 Exercise ...................................................................................................................................... 69
9.5 Assessment Sheet ................................................................................................................... 70
Lab - 10: Sampling and Aliasing .............................................................................................. 71
10.1 Objectives .................................................................................................................................. 71
10.2 Introduction ............................................................................................................................. 71
10.3 Sampling .................................................................................................................................... 71
10.4 Nyquist Criteria ....................................................................................................................... 72
10.5 Learning Tasks ........................................................................................................................ 72
10.6 Exercise ...................................................................................................................................... 74
10.7 Assessment Sheet ................................................................................................................... 75
Lab - 11: Simulink ........................................................................................................................ 77
11.1 Objectives .................................................................................................................................. 77
11.2 Simulink ..................................................................................................................................... 77
11.3 Exercise ...................................................................................................................................... 79
11.4 Assessment Sheet ................................................................................................................... 80

Signals and Systems Page 4


Instructions for Students
1. Attendance is mandatory for students in all the labs. If a student is absent from a
lab due to any reason, he/she will have to get written permission of the Dean to
perform that lab. The Dean may allow students to perform lab if he finds that the
student has a genuine excuse.
2. Students should bring their text books to the lab, so that they can refer to theory
and diagrams whenever required.
3. Labs will be graded in double entry fashion; one entry in the assessment sheet
given at the end of every lab and another entry in the instructor’s record. This
system of keeping records will keep students aware of their performance
throughout the lab.
4. The assessment sheet at the end of every lab looks like this:

Name: __________________________
Reg. No. : _______________________
Date of Lab: ____________________

1 – …..
Problem
2 – …..
Number
3 – …..

Working
Lab
Performance Viva

Total Score in Lab – 1

Instructor’s Verification

5. The tentative marks distribution for final grade is as follows:


 Lab Performance – 60 %
 Mid Exam – 10%
 Project – 10%
 Lab Final – 20 %

Signals and Systems Page 5


Signals and Systems Page 6
Lab - 1: Introduction to MATLAB

Figure 1.1: MATLAB Layout

1.1 MATLAB HELP


MATLAB provides extensive help for using MATLAB commands and features, as well
as introduction to several theoretical concepts. In order to access this help, try one of
the following commands:
 help
 help pi
 help sin
 doc

1.2 DEFINING VARIABLES


Variables are assigned numerical values by typing the expression directly in the
command window, for example typing:
>> a=1+2
a=
3
>>
The answer will not be displayed when a semicolon is put at the end of an expression:
>> a=1+2;
>>
MATLAB allows the following arithmetic operators:

Signals and Systems Page 7


+ Addition
- Subtraction
* Multiplication
/ Division
^ Power operator
’ Transpose
A variable can be assigned a formula that utilizes these operators with numbers or
previously defined variables. An example of using above operations on the value of a
previously defined quantity is given below:
>> b = 2*a;
>> b
b=
6
If your expression does not fit on one line, use an ellipsis (three or more periods at the
end of the line) and continue on the next line.
>> c=1+2+3+4+...
5+6+7;
>> c
c=
28
There are several predefined variables which can be used at any time, in the same
manner as user-defined variables:
i sqrt(-1)
j sqrt(-1)
pi 3.1416…

For example,
>> y=2*(1+4*j)
y=
2.0000 + 8.0000i
There are also a number of predefined functions that can be used when defining a
variable. Some common functions that are used in this text are:
abs Magnitude of a number
angle Angle of a complex number in radians
cos Cosine function, assumes argument is in radians
sin Sine function, assumes argument is in radians
exp Exponential function
For example, with y defined as above,
>> c=angle(y)
c=
1.3258
>> c=abs(y)
c=
8.2462
>> c=angle(y)
c=
1.3258
>> c=cos(a)
c=
-0.9900
>> c=exp(a)

Signals and Systems Page 8


c=
20.0855
>> c=exp(y) % Note: ‘exp’ can be used on complex numbers
c=
-1.0751 + 7.3104i

1.3 M-FILES
M files are macros of MATLAB commands that are stored as ordinary text files with the
extension ''.m'', that is ‘filename.m’. An M-file can be either a function with input and
output variables or a list of commands. MATLAB requires that the M-file must be
stored either in the working directory or in a directory that is specified in MATLAB
path list. For example consider using MATLAB on a PC with a user-defined M-file
stored in a directory called ''\MATLAB\MFILES''. In order to access that M-file, either
change the working directory by typing ‘cd\MATLAB\mfiles’ within MATLAB
command window or add the directory to the path. Permanent addition to the path is
accomplished by editing the ‘\MATLAB\MATLABrc.m’ file, while temporary
modification to the path is accomplished by typing ‘path(path,’\MATLAB\mfiles');’
within MATLAB. Or, this can easily be achieved through the path browser. As an
example, create a file in your working directory named ‘yplusx.m’ that contains the
following commands:
function z = yplusx(y,x)
z=y+x;
The following commands typed within MATLAB demonstrate how this M-file is used:
>> x=2;
>> y=3;
>> yplusx(y,x)
ans =
5
MATLAB M-files can either be ‘scripts’ or ‘functions’. Scripts are simply files
containing a sequence of MATLAB statements. Functions make use of their own local
variables and accept input arguments. Variables, which are used in a script m-file are
all global variables. The name of a function, as defined in the first line of the M-file,
should be the same as the name of the file without the .m extension. Function M-files
start with the command function. MATLAB M-files are most efficient when written in a
way that utilizes matrix or vector operations. Loops and if statements are available but
should be used sparingly since they are computationally inefficient. For example:
>> for k=1:10;
x(k)=cos(k);
end
This creates a 1x10 vector x containing the cosine of the positive integers from l to 10.
This operation is performed more efficiently with the commands
>> k=1:10;
>> x=cos(k);
Which utilizes a function of a vector instead of a for loop. An if statement can be used
to define conditional statements. The allowed comparisons between expressions are
>= Greater than and equal
<= Less than and equal
> Greater than
< Less than
== Is Equal
~= Not Equal

Signals and Systems Page 9


1.4 GENERATING THE PLOTS
A list of useful commands is given below:
 plot, stem, subplot, hold
 xlabel, ylabel, title, grid, axis, axes
The command most often used is plot, which creates linear plots of vectors and
matrices. There are options on the line type and the color of the plot which are
obtained using plot(t,y,’option’). The line type options are '-' solid line (default), ‘--’
dashed line, '-.' dot dash line, ':' dotted line. The points in y can be left unconnected and
delineated by a variety of symbols: + . * o x. The following colors are available: r, g, b, k,
y, m etc. For example, p1ot(t,y,'--') uses a dashed line, plot(t,y,’*’) uses * at all the
points defined in t and y without connecting the points, and plot(t,y,’g’) makes a solid
green line. The options can also be used together, for example, plot(t,y,’g:’) plots a
dotted green line. To plot two or more graphs on same set of axes, use the command:
plot(t1,y1,t2,y2), which plots y1 versus t1 and y2 versus t2. To label your axes and
give the plot a title:
≫xlabel('time(sec)')
≫ylabel('stepresponse')
≫title('myplot')
Add a grid to your plot to make it easier to read by using the command grid. The
problem that you will encounter most often when plotting functions is that MATLAB
will scale the axes in a way that is different from how you want them to appear. You
can easily override the auto scaling of the axes by using the axis command after the
plotting command axis([xmin xmax ymin ymax]), where xmin, xmas, ymin, and
ymax numbers corresponding to the limits you desire for the axes. To return to the
automatic scaling, simply type axis. For discrete-time signals, use the command stem
which plots each point with a small open circle and a straight line. To plot y(k) versus
k, type stem(k,y). You can use stem(k,y,'filled') to get circles that are filled in. To plot
more than one graph on the screen, use the command subplot(m,n,p) which partitions
the screen into an m x n grid where p determines the position of the particular graph
counting the upper left corner as p=1.

1.5 DEFINING MATRICES


MATLAB is based on matrix and vector algebra. Even scalars are treated as 1x1
matrices. Vectors can be defined in two ways. The first method is used for arbitrary
elements, exemplified below:
>> v=[1 3 5 7];
>> v(5)=8
v=
1 3 5 7 8
Note that commas could have been used in place of spaces to separate the elements.
Previously defined vectors can be used to define a new vector. For example, with ‘v’
>> a=[9 10];
>> b=[v a];
>> b
b=
1 3 5 7 8 9 10
The second method is used for creating vectors with equally spaced elements:
>> t=0:0.1:10;
>> k=0:10;
Creates a 1x101 vector with the elements 0, .1, .2, .3,..., 10. Note that the first number is
Signals and Systems Page 10
the start point, middle number defines the step, and the last number is the stop point.
[start:step:stop]. Matrices are defined by entering the elements row by row:
>> M=[1 2 4;3 6 8]
M=
1 2 4
3 6 8
>> M=zeros(2,2) % All zero matrix with dimensions (rows,cols)
M=
0 0
0 0
>> M=ones(2,2) % All ones matrix with dimensions (rows,cols)
M=
1 1
1 1
>> M=eye(2,2) % Identity matrix with dimensions (rows,cols)
M=
1 0
0 1
>> M(1,2)=5 % Places 5 in first row second column of M.
M=
1 5
0 1
Functions are applied element by element. For example,
>> t=0:10;
>> x=cos(2*t);
Creates a vector x with elements equal to cos(2t) for t = 0, 1, 2, ..., 10. Operations that
need to be performed element-by-element can be accomplished by preceding the
operator by a “.”. For example to obtain a vector x that contains the elements of
at specific points in time, you cannot simply multiply the vector t with
the vector . Instead you multiply their elements together:
>> t=0:10;
>> x= t.*cos(2*t);
Informally, the terms matrix and array are often used interchangeably. More precisely,
a matrix is a 2-dimensional rectangular array of real or complex numbers that
represents a linear transformation. The linear algebraic operations defined on
matrices have found applications in a wide variety of technical fields. MATLAB has
dozens of functions that create different kinds of matrices. Two of them can be used to
create a pair of 3-by-3 example matrices for use throughout this chapter. The first
example is symmetric.
>> A=pascal(3)
A=
1 1 1
1 2 3
1 3 6
The second example is not symmetric.
>> B=magic(3)
B=
8 1 6
3 5 7
4 9 2

Signals and Systems Page 11


Another example is a 3-by-2 rectangular matrix of random integers.
>> C=fix(10*rand(3,2))
C=
8 9
9 6
1 0
A column vector is an m-by-l matrix, a row vector is a l-by-n matrix and a scalar j is a
1x1 matrix. The following statements produce a column vector, row vector, and a
scalar respectively.
>> u=[3 1 4] % Row Vector
u=
3 1 4
>> v = [ 2 ; 0 ; 1 ] % Column Vector
v=
2
0
1
>> s=[7] % Scalar
s=
7
1.5.1 Matrix Addition and Subtraction
Addition and subtraction of matrices is defined just as it is for arrays, element-by-
element. Adding A to B and then subtracting A from the result recovers B.
>> X=A+B
X=
9 2 7
4 7 10
5 12 8
>> Y=X-A
Y=
8 1 6
3 5 7
4 9 2
Addition and subtraction require both matrices to have the same dimension, or one of
them is a scalar. If the dimensions are incompatible, an error occurs.
1.5.2 Vector Products and Transpose
A row vector and a column vector of the same length can be multiplied in either order.
The result is a scalar, the inner (scalar) product, a matrix, or the outer product. For
real matrices, the transpose operation interchanges aij and aji. MATLAB uses the
apostrophe (or single quote) to denote transpose. Our example matrix A is symmetric,
so A' is equal to A. But B is not symmetric.
>> X = B'
X=
8 3 4
1 5 9
6 7 2
If x and y are both real column vectors, the product x*y is not defined, but the two
products x’*y and y’*x are the same scalar. This quantity is used so frequently, it has
three different names i.e. inner product, scalar product, or dot product. For a complex
vector or matrix, z, the quantity z' denotes the complex conjugate transpose. The
Signals and Systems Page 12
unconjugated complex transpose is denoted by z.’
>> z=[1+2i 3+4i]
z=
1.0000 + 2.0000i 3.0000 + 4.0000i
>> z.'
ans =
1.0000 + 2.0000i
3.0000 + 4.0000i
>> z'
ans =
1.0000 - 2.0000i
3.0000 - 4.0000i
For complex vectors, the two scalar products x'*y and y’*x are complex conjugates of
each other and the scalar product x’*x of a complex vector with itself is real.
1.5.3 Matrix Multiplication
Multiplication of matrices is defined in a way that reflects composition of the
underlying linear transformations and allows compact representation of systems of
simultaneous linear equations. The matrix product is defined when the
column dimension of A is equal to the row dimension of B, or when one of them is a
scalar. lf A is m x p and B is p x n, their product C is m-by-n. The product can actually be
defined using MATLAB'S for loops, colon notation, and vector dot products. The next
example illustrates the fact that matrix multiplication is not commutative; .
>> X=A*B
X=
15 15 15
26 38 26
41 70 39
>> X=B*A
X=
15 28 47
15 34 60
15 28 43
A matrix can be multiplied on the right by a column vector and on the left by a row
vector. Rectangular matrix multiplications must satisfy the dimension compatibility
conditions.
1.5.4 Matrix Powers
If A is a square matrix and p is a positive integer, then A^p multiplies A by itself p
times.
>> X=A^2
X=
3 6 10
6 14 25
10 25 46
>> Y=B^-3
Y=
0.0053 -0.0068 0.0018
-0.0034 0.0001 0.0036
-0.0016 0.0070 -0.0051
If A is square and nonsingular, then A^(-p) multiplies inv(A) by itself p times.
Fractional powers, like A^(2/3), are also permitted; the results depend upon the
distribution of the eigen values of the matrix. Element-by-element powers are

Signals and Systems Page 13


obtained with ‘^’. For example

>> X=A.^2
X=
1 1 1
1 4 9
1 9 36
1.5.5 Matrix Manipulation
 Cat -Concatenate arrays
 diag -Diagonal matrices and diagonals of a matrix
 fliplr -Flip matrices left-right .
 flipud -Flip matrices up-down
 repmat -Replicate and tile an array
 reshape -Reshape array
 rot90 -Rotate matrix 90 degrees
 tril -Lower triangular part of a matrix
 triu -Upper triangular part of a matrix
 : (colon) -Index into array, rearrange array
1.5.6 Accessing Vectors and Matrices
 f(25) – Accesses the 25th element of f.
 f(3:10) – Accesses elements 3 to 10.
 f(1:2:50) – Accesses the odd-numbered elements between 1 and 50.
 f(1:3,4:8) – Defines a matrix that is equivalent to a section of the matrix f
containing the first, second and third rows, and the fourth to eight columns.

1.6 GENERAL INFORMATION


 MATLAB is case sensitive so ''a'' and ''A'' are two different names
 Comment statements are preceded by a “%”
 You can make a keyword search by using the help command
 The number of digits displayed is not related to the accuracy. To change the format
of the display, type format short e for scientific notation with 5 decimal places,
format long e for scientific notation with 15 significant decimal places and format
bank for placing two significant digits to the right of the decimal.
 The commands who and whos give the names of the variables that have been
defined in the workspace.
 The command length(x) returns the length of a vector x and size(x) returns the
dimension of the matrix x.
 When using MATLAB, you may wish to leave the program but save the vectors and
matrices you have defined. To save or retrieve a file to the working directory, use
the save and load commands.

1.7 COMPLEX VARIABLES AND EXPRESSIONS


Consider the following two expressions that we are to write in MATLAB

In MATLAB these expression shall be written as:

>> a = j*exp(j*11*pi/4)
a=
-0.7071-0.7071i

Signals and Systems Page 14


>>b = (1 – j)^10
b=
1
1.7.1 Plotting Complex Valued Functions
Plots in MATLAB are generated using the plot function. Since the complex values have
two components corresponding to , MATLAB provides the real and imaginary
functions to separate the real and imaginary parts of an imaginary number. Consider
the following example:
>> z = 3 + 4j;
>> zr = real(z);
>> zi = imag(z);
>> plot(zr,zi,’*’)
1.7.2 Generating Complex Functions
Generating complex functions can be explained from the following example. Suppose
we are to generate the values for a complex function:

For a range 0 → 1 with 0.001 increments we would use the following piece of code:
>> t = 0:0.001:1;
>> f = 3* exp(j*3*pi*t)

1.8 LOOPS
From other computer programming experiences, you should be familiar with the idea
of creating a loop to repeat the same task for different values. Here's an example of
how to do that using MATLAB. Suppose we want to generate an output vector where
each element is the sum of the current element and the element from 10 places back in
an input vector. The task to be repeated is the sum of two elements; we need to repeat
this for each element in the vector past 10. The elements of the vector x define the
input ramp function to be integrated, y will hold the result, and k is the loop index:
>> x=3*(0:0.01:5)+2;
>> y=zeros(size(x) );
>> for k=11:length(x)
y(k)=x(k-10)+x(k);
end
As mentioned previously that loops are inefficient in MATLAB so we can rewrite this
problem to use vector addition by creating two new vectors. One which is x offset by
10 and the other which is x padded with 10 zeros (since we can only add vectors of
similar lengths)

>> x=3*(0:0.1:5)+2;
>> x1=[zeros(1,10) x];
>> x2=[x zeros(1,10) ];
>> y=x1+x2;
>> y(1:10)=0;
>> y=y(1:51);
Check the above two approaches. Which one is better?

1.9 SYMBOLIC CALCULATIONS USING MATLAB


To define a symbolic variable, x, one can use one of the following commands:
>> syms x;
>> x = sym(‘x’);

Signals and Systems Page 15


The first command is shorter; the second command is somewhat more versatile. One
can define other symbols in terms of symbols that have already been defined. For
example:
>> x = sym(‘x’);
>> y = 1/(1 + x^2);
1.9.1 Plotting Symbolic Functions
MATLAB has a separate command for plotting symbolic functions, ezplot. The
simplest way to use ezplot is to use the command ezplot(y). MATLAB then plots the
function over a default interval. Generate the plot for above mentioned function y!

1.10 SUBSTITUTIONS
MATLAB provides a command that allows us to substitute values, symbolic or
otherwise, for symbolic values. The ‘subs’ command performs the substitution. Use
MATLAB help to learn more about this command.

1.11 EXERCISES
1. Use the subplot command to provide following three plots in one figure:
 Plot 1: sin(t), sin(3t), sin(5t)
 Plot 2: cos(t), cos(3t), cos(5t)
 Plot 3: tan(t), tan(3t), tan(5t)
For . It is important to use different color schemes to differentiate the
harmonics; provide legend, xlabel, ylabel, and title for each plot.

2. Write a MATLAB function, which takes the following two inputs:


 A vector (of variable length) representing resistors in an electrical circuit
 A flag representing whether resistors are in parallel or series
The function should return equivalent resistance.

3. Define the symbolic variable x. Make use of this variable to define the symbolic
function sin(1/x). Then, plot the function from 0 to 2. What do you see? Why might
the plotting routine be having trouble plotting this function?

4. The natural response of a series RC circuit is given by

Write a MATLAB function that takes two inputs R and C, and plots the natural
response of this circuit for .

Signals and Systems Page 16


1.12 ASSESSMENT SHEET

Name: __________________________

Reg. No. : _______________________

Date of Lab: ____________________

Exercise – 1

Exercise – 2
Problem
Number
Exercise – 3

Exercise – 4

MATLAB Codes
Lab
Performance
Viva

Total Score in Lab – 1

Instructor’s Verification

Signals and Systems Page 17


Signals and Systems Page 18
Lab - 2: Properties of Signals and Systems

2.1 OBJECTIVES
 Classification of signals, signal energy and power
 Useful signal transformations
 Systems and their properties

2.2 SIGNALS
A signal is a set of information, message, or data, for example speech, video, pictures,
and television etc. Signals are mathematically expressed as a function of one or more
independent variable. For example a speech signal can be represented mathematically
by acoustic pressure as a function of time. Signals are classified in a variety of ways.
Here we shall discuss the following main classifications only:
1. Continuous-time and Discrete-time Signals: Continuous-time signals are defined
for a continuum of values of time. Discrete time signals are defined only at discrete
values of time. This classification qualifies the nature of a signal along the
horizontal axis representing the independent variable, time.
2. Analog and Digital Signals: A signal whose amplitude can take any value in a
continuous range is an analog signal. A digital signal, on the other hand, is one
whose amplitude can take only a finite number of values. This classification
qualifies the nature of a signal along vertical axis representing signal’s amplitude.

2.3 SIZE OF A SIGNAL


Since the amplitude of a signal varies with time, any number representing the size of
signal should consider not only its magnitude, but also the time duration. Below we
describe two conventional quantities used for measuring signals.
2.3.1 Signal Energy
The area under a signal could be a meaningful measure of its size, since it takes
amplitude and time into account. But this measure is defective (Why?), so we use area
under instead. This quantity is called signal energy E:
Continuous Time Discrete Time

2.3.2 Signal Power


If the signal amplitude doesn’t converge, its energy would be infinite and won’t serve
as a meaningful measure of signal size. In this case the time average of energy, which is
average power P, is a better measure of signal size:
Continuous Time Discrete Time

2.4 TRANSFORMATION OF A SIGNAL


2.4.1 Time Shift
Time shift, as the name indicates, means shifting a signal w.r.t time. There are 2 types
of time shift; time delay and time advance. Consider the following discrete time signals

Signals and Systems Page 19


which are identical in shape but are displaced in time relative to each other:
Original Signal Time Delayed Signal Time Advanced Signal
3 3 3
x[n] x[n - 3] x[n + 3]

2 2 2

1 1 1

0 0 0
0 2 4 6 8 2 4 6 8 10 -4 -2 0 2 4 6
Figure 2.1
 Original Signal:
 Time Delayed Signal:
 Time Advanced Signal:
Similar is the case with continuous time signals. The following program can be used to
implement time shift in MATLAB:
>> t=[1 2 3 4 5 6 7];
>> x=[0 1 2 3 2 1 0];
>> a=t+3; % Advance the Signal
>> b=t-3; % Delay the Signal
>> subplot(1,3,1)
>> stem(t,x) % Plots the Original Signal
>> subplot(1,3,2)
>> stem(a,x) % Plots the Time Advanced Signal
>> subplot(1,3,3)
>> stem(b,x) %Plots the Time Delayed Signal
Applications of time shift are found in radar and seismic signal processing, in which
several receivers at different locations observe a signal being transmitted through a
medium (water, rock, air etc). The difference in propagation time from the point of
origin of the transmitted signal to any 2 receivers results in a time shift between the
signals at the 2 receivers.
2.4.2 Time Scaling
The compression or expansion of a signal in time is known as time scaling. Consider
the following continuous time signals:
Original Signal x(t) Expanded Signal x(t/2) Compressed Signal x(2t)
1.5 1.5 1.5

1.4 1.4 1.4

1.3 1.3 1.3

1.2 1.2 1.2

1.1 1.1 1.1

1 1 1
-2 -1 0 1 2 -4 -2 0 2 4 -4 -2 -1 0 1 2 4

Figure 2.2
 Original Signal:
 Expanded Signal:
 Compressed Signal:
 Example: Let represent an audio tape recording. Then represents the
same audio tape being compressed in time, so it plays at twice the speed. On the
other hand, represents the same audio tape being expanded in time, so it is
slowed down and plays at half the speed.

Signals and Systems Page 20


A simple MATLAB program to demonstrate time scaling is given below:
>> t=[-2 -1.5 -1 -0.5 0 0.5 1 1.5 2];
>> x=[1 1 1 1.5 1.5 1.5 1 1 1];
>> t1 = 2*t;
>> t2 = t/2;
>> subplot(1,3,1)
>> plot(t,x) % Plots Original Signal
>> subplot(1,3,2)
>> plot(t1,x) % Plots Expanded Signal
>> subplot(1,3,3)
>> plot(t2,x) % Plots Compressed Signal
2.4.3 Time Reversal
Time inversion/reversal can be considered a special case of time scaling with .
The time reversed version of is obtained by reflecting the signal about . The
time reversed/folded signal so produced is represented by This can be
achieved using the ‘fliplr’ command in MATLAB. Consider the following discrete time
signal:
Original Signal x[n] Reversed Signal x[-n]
6 6

4 4

2 2

0 0

-2 -2
-4 -2 0 2 4 -4 -2 0 2 4
Figure 2.3
>> t=[-3 -2 -1 0 1 2 3];
>> x=[ -1 1 2 2 3 4 5];
>> x1 = fliplr(x);
>> subplot(1,2,1)
>> stem(t,x) % Plots Original Signal
>> subplot(1,2,2)
>> stem(t,x1) % Plots Time Reversed Signal
2.4.4 Amplitude Scaling
So far operations were performed on the horizontal (time) axis. Here we scale the
vertical (amplitude) axis of a signal. Following figure illustrates a signal , it’s
amplitude scaled versions , and :

x(t) 2 * x(t) (1/2) * x(t)


2 2 2

1 1 1

0 0 0

-1 -1 -1

-2 -2 -2
5 10 15 20 5 10 15 20 5 10 15 20

Figure 2.4

Signals and Systems Page 21


A simple MATLAB program to demonstrate amplitude scaling is given below:
>> t=1:0.1:100;
>> x=sin(t);
>> x1=2*x;
>> x2=x/2;
>> subplot(1,3,1)
>> plot(t,x) % Original Signal
>> subplot(1,3,2)
>> plot(t,x1) % Amplitude scaled by a factor of 2
>> subplot(1,3,3)
>> plot(t,x2) % Amplitude scaled by a factor of half
Note: If we perform all of the above on a signal the shape of the signal remains the
same. If we encounter reflecting and time shifting together then first reflect the
signal and then perform time shifting.

2.5 SYSTEMS
A system is defined as an entity that transforms/processes a set of signals (inputs)
and yields another set of signals (outputs). A system may consist of physical
components such as electrical or mechanical systems, or it may be an algorithm that
takes some inputs, does some processing and yields outputs.

2.6 PROPERTIES OF SYSTEMS


2.6.1 Memory
Memory less systems: A system is said to be memory less if its output for each value
of the independent variable at a given time is dependant only on the input at that same
time. A few examples are listed below:

1) The following system is memoryless, as vales of depend only on the present


value of .
2

2) A resistor is a memory less system. Let be the input current and be the
output voltage, then input and output relation is given by:

3) Identity system in which the output is identical to the input, i.e.


Systems with memory: Memory in a system corresponds to the presence of a
mechanism in the system that retains or stores information about input values at
times other than the current time. A few examples are given below:

1) Accumulator or summer is a discrete time system with memory

Thus an accumulator remembers the past inputs and calculates the running sum of
all the inputs up to the current time.
2) A delay system:
3) A capacitor (capacitance given by C), where the current is taken as input and
the output voltage is given as follows:

Signals and Systems Page 22


2.6.2 Inverse systems
A system is said to be invertible if distinct inputs lead to distinct outputs. For a discrete
time case, if a system is invertible then inverse of that system exists. Some examples
are given for the sake of understanding:
1) An example of an invertible system is:

Because its inverse also exists

Figure 2.5
2) A system that produces zero output sequence for any input sequence or a system in
which we cannot determine the sign of the input from the knowledge of the output
is a noninvertible system e.g.:

2.6.3 Causality
A system is said to be causal if the output at any time depends only on the values of the
input at the present time and in the past, not on the future values. A Few examples are
given below:

1) All memoryless systems are casual since the output responds only to the current
values of the input.
2) A delay system is causal:

3) Following two are non-causal systems.

2.6.4 Stability
A system is known as stable if it’s output stays bounded for a bounded input (i.e. if its
magnitude does not grow without bound), and therefore cannot diverge. Consider
following examples to understand:

1) An accumulator sums all of the past values of the input rather than just a finite set of
values, and the system is unstable since the sum can grow continually even if is
bounded.
2) A model for a bank account balance is an example of an unstable system. If an initial
deposit is made and there are no subsequent withdrawals then that deposit will grow
each month without bound because of compounding effect of interest payments.
2.6.5 Time Invariance
A system is said to be time invariant if a time shift in the input signal results in an
identical time shift in the output signal. Let be the input of a discrete time
invariant system and be the output of a discrete time invariant system. Then for a
time invariant system, is the output when is applied.

Signals and Systems Page 23


2.6.6 Linearity
A linear system, in continuous time or discrete time is a system that possesses the
important property of superposition. In other words a system is said to be linear if it
satisfies the additive and scaling properties.
Let be the response of a continuous time signal to an input and let be
the response to another input , then a system is said to be linear if it satisfies
following:

 Additive property i.e.

 Scaling/homogeneity property i.e.

Signals and Systems Page 24


2.7 EXERCISES
1) If a signal represents voltage level what should be the units for its energy E
and power P?
2) Given the following signal:

Sketch the following in MATLAB:


a)
b)
c)
d)

3) Analyze each of the following continuous-time systems in terms of the six basic
system properties. In addition, summarize your conclusions in the table below.

(a)
(b)
(c)

Time
Syste Memor Causalit Invertibilit Stabilit Linearit
Invarianc
m y y y y y
e
S1
S2
S3

4) a) What is the difference between digital and discrete signal?


b) Are the signals in MATLAB discrete time or continuous time, digital or analog?

5) Record your own sound saying the sentence, “The quick brown fox jumps over the
lazy dog”. Play this recording in MATLAB with and without time reversal, also
comment on the observations.

6) Play the sound recording of the previous question after and before expansion and
compression. What is the expansion and compression factor? (i.e. upsampling and
downsampling factor)

Signals and Systems Page 25


2.8 ASSESSMENT SHEET

Name: __________________________

Reg. No. : _______________________

Date of Lab: ____________________

Exercise – 1

Exercise – 2

Exercise – 3
Problem
Number
Exercise – 4

Exercise – 5

Exercise – 6

MATLAB Codes
Lab
Performance
Viva

Total Score in Lab – 2

Instructor’s Verification

Signals and Systems Page 26


Lab - 3: Signals, Periodicity and Harmonics

3.1 OBJECTIVES
 Useful functions: unit step and unit impulse
 Even and odd signals; even and odd components of a signal
 Periodic signals; harmonics
 Exponential and sinusoidal signals

3.2 UNIT STEP FUNCTION


A discrete time unit step function is defined as:

The continuous time unit step function is defined in a similar manner, except for the
fact that it is discontinuous at :

u [n]  [n]
1 1

0.5 0.5

0 0
-10 -5 0 5 10 -10 -5 0 5 10
u (t)  (t)
1 1

0.5 0.5

0 0
-10 -5 0 5 10 -10 -5 0 5 10

Figure 3.1: Left Column: DT and CT Unit Step Function


Right Column: DT and CT Unit Impulse Function

3.3 UNIT IMPULSE FUNCTION


The discrete-time unit impulse is defined as:

A continuous time unit impulse is defined in the following limiting form:

Where is a short pulse of width and unit area.

Signals and Systems Page 27


3.4 EVEN AND ODD SIGNALS
Another way to classify signals is to analyze their symmetry under time reversal. A
signal or is referred to as an even signal if it is identical to its time reversed
counterpart i.e. its reflection about the origin.

Even Signal Odd Signal

Even Function Odd Function


100 1000

80
500

60
0
40

-500
20

0 -1000
-10 -5 0 5 10 -10 -5 0 5 10

Figure 3.2: Even function and Odd function

An interesting fact is that any signal can be broken into a sum of two signals, one of
which is even and one of which is odd.

Even Part Of A Signal Odd Part Of A Signal

1
Original Signal 1 Even Part

0.8
0.5
0.6

0 0.4
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1
0.5
Odd Part 1
Check = Even + Odd

0 0.5

-0.5 0
-1 -0.5 0 0.5 1 -1 -0.5 0 0.5 1

Figure 3.3

Signals and Systems Page 28


3.5 PERIODIC SIGNALS
Signals are also classified on the basis of their periodicity. A continuous-time signal
is periodic if there exists a positive value of ‘ ’ for which

In other words, a periodic signal has the property that it is unchanged by a time shift of
‘ ’. In this case we say that is periodic with time . A very common example of a
periodic signal is a sine wave.
CT Periodic Signal DT Periodic Signal
1 3

2
0.5
1

0 0
2
-1
-0.5
-2

-1 -3
-5 0 5 5 10 15 20

Figure 3.4

The above figure shows that the sine signal repeats itself after a time period
A periodic signal in discrete time is defined analogously. A discrete time signal
is periodic with period , where is a positive integer, if the signal is unchanged
by a time shift of ‘ ’ i.e.

A signal which is not periodic is called Aperiodic Signal.


3.5.1 Fundamental Period
The fundamental period is the smallest positive value of ‘ ’ (continuous) or ‘ ’
(discrete) for which the equations of periodicity holds. Consider the above example of
a sine function. In this case the signal is periodic at 2π, 4π, 6π and so on, but the
fundamental time period of the signal is 2π. Similarly in case of discrete time signal the
signal is periodic at N = 7, 14, 21 and so on but the fundamental period of the signal is
7.

3.6 HARMONICS
Harmonics are integral multiples of a signal. Consider the signal . Its
harmonics will be and so on. Similar is the case with discrete
time signals where for the harmonics can be and
so on. The fundamental harmonic is the first harmonic of the signal i.e. when or
. In the above examples and are fundamental harmonics.
1
sin (t)
sin (2t)
0.5 sin (3t)

-0.5

-1
0 10 20 30 40 50 60

Figure 3.5

Signals and Systems Page 29


3.6.1 Even and Odd Harmonics
If the harmonic of a signal/function has an odd co-efficient it is called as an odd
harmonic. If the coefficient is even, it's called an even harmonic. Even, odd harmonics
play an important role in signal construction. Different waveforms can be obtained by
adding one type of harmonic to another e.g. adding (infinite) odd harmonics of sine/
cosine waves generates a square wave. Both the waves will have a 90 degree phase
shift from each other. Practically it's not possible to add up all the (infinite) number of
harmonics to obtain a perfect square wave but we can see as the number of harmonics
is increased from 10 onwards, we can obtain a decent enough square wave. For a
square wave to be generated (as shown in figure) from the odd harmonics of sine
function we use the following expression:

2
4 Harmonics of cosine 2
4 Harmonics of sine

1 1

0 0

-1 -1

-2 -2
0 50 100 150 0 50 100 150
Figure 3.6

For a wave generation by odd harmonics of a cosine function we use:

3.7 EXPONENTIAL AND SINUSOIDAL SIGNALS


An exponential signal can be expressed and interpreted in two ways: real
exponential and periodic complex exponential.
150 An Exponential Signal

100

50

0
0 2 4 6 8 10

Figure 3.7
 If ‘a’ is real, we have real exponential signal.
 If ‘a’ has an imaginary part, we have a complex signal:

Signals and Systems Page 30


Using Euler's equation we get:

 For the real and imaginary parts of a complex exponential are sinusoidal.
 For they correspond to growing exponential sinusoidal signals.
 For they correspond to decreasing exponential sinusoidal signals.

Decreasing Sinusoidal Increasing Sinusoidal


20 20

10 10

0 0

-10 -10

-20 -20

0 500 1000 0 500 1000


Figure 3.8

Signals and Systems Page 31


3.8 EXERCISE

1. Determine the relationship between step and impulse function.

2. Use MATLAB to plot a unit step function.


Hint: Use syms command and create a signum function first.

3. Decompose the following signal into its even and odd parts

4. Use MATLAB to produce a plot of a discrete-time sinusoid with amplitude 2.0 and a
period of T = 7.

5. Write MATLAB function to produce a plot of an exponentially-decaying sinusoid


with the decay rate, amplitude, and period selected by you (function inputs).

6. Add up first 10 harmonics of ‘sin’ and plot the waveform. What is it like?

7. Add up first 10 harmonics of ‘cos’ and plot the waveform. What is it like?

Signals and Systems Page 32


3.9 ASSESSMENT SHEET

Name: __________________________

Reg. No. : _______________________

Date of Lab: ____________________

Exercise – 1

Exercise – 2

Exercise – 3

Problem
Exercise – 4
Number

Exercise – 5

Exercise – 6

Exercise – 7

MATLAB Codes
Lab
Performance
Viva

Total Score in Lab – 3

Instructor’s Verification

Signals and Systems Page 33


Signals and Systems Page 34
Lab - 4: Fourier Series

4.1 OBJECTIVES
 Fourier series representations
 Discrete Fourier Series
 Fourier Series in MATLAB

4.2 FOURIER SERIES


The representation of a periodic signal (with period as a linear combination of
harmonically related oscillating functions (sines and cosines) or complex exponentials
is called “Fourier series” representation. Generalized definitions for continuous time
domain are summarized below:

Trigonometric Fourier Series Exponential Fourier Series

4.2.1 Fourier Series in this Lab


In this lab we will study Fourier series in following two perspectives:
1. The discrete Fourier series coefficients of finite signals.
2. The Fourier series coefficients of finite segments of time-varying signals, creating
what is known as a spectrogram.
4.2.2 Discrete Fourier Series
A finite discrete-time signal with N samples has discrete-time Fourier series
expansion:

Where ω0 = 2π/N.
4.2.3 Fourier Series in MATLAB
MATLAB does not have any built-in function that directly computes the discrete
Fourier series coefficients. The following program taken from [1] is used to find the
Fourier Series Coefficients. It returns the magnitude and phase of each sinusoidal
component in the Fourier series expansion for one cycle of a periodic signal. It is

Signals and Systems Page 35


assumed to have an even number of samples . The first returned value is an array
containing the amplitudes of the sinusoidal components in the Fourier series
expansion, with frequencies . The second returned value is an
array of phases for the sinusoidal components. Both returned values are arrays with
length .

function [magnitude, phase] = fourierSeries(x)


% FOURIERSERIES - Return the magnitude and phase of each
% sinusoidal component in the Fourier series expansion for
% the argument, which is interpreted as one cycle of a
% periodic signal. The argument is assumed to have an
% even number N of samples. The first returned value is an
% array containing the amplitudes of the sinusoidal
% components in the Fourier series expansion, with
% frequencies 0, 1/N, 2/N, ... 1/2. The second returned
% value is an array of phases for the sinusoidal
% components. Both returned values are arrays with length
% (N/2)+1.
N = length(x);
f = fft(x)/N;
magnitude(1) = abs(f(1));
upper = N/2;
magnitude(2:upper) = 2*abs(f(2:upper));
magnitude(upper+1) = abs(f(upper+1));
phase(1) = angle(f(1));
phase(2:upper) = angle(f(2:upper));
phase(upper+1) = angle(f(upper+1));

Consider an array x with even length,


returns the DFS coefficients in a pair of vectors. To plot the
magnitudes of the Fourier series coefficients versus the sampling frequency (in
samples/second) set by you:

≫N=length(x)
≫frequencies=[0:fs/N:fs/2];
≫plot(frequencies, magnitude);
≫xlabel('frequency in Hertz')
≫ylabel('amplitude')

The line bears further examination. It produces a


vector of length , where N is the length of the x vector. The elements of the
vector are the frequencies in Hertz of each Fourier series component.

Signals and Systems Page 36


4.3 EXERCISE
1. Derive Fourier series coefficients for the periodic square wave

2. After derivation, draw a rough sketch of frequency spectrum.

3. Understand the working of function fourierSeries, and relate the particular form of
Fourier series expansion used in this function to the trigonometric Fourier
coefficients.

4. Consider the signal generated by


>> t = [0:1/8000:1-1/8000];
>> x=sin(2*pi*800*t);
This is 8,000 samples of an 800-Hz sinusoid sampled at 8,000 samples/second.
Listen to it. Use the fourierSeries function as described above to plot the
magnitude of its discrete Fourier series coefficients. Explain the plot.
5. With the same t defined above, consider a more interesting waveform generated
by:

This is called a chirp signal. Listen to it. Plot its Fourier series coefficients using
the fourierSeries function as described. This chirp is 8-kHz samples of the
continuous-time waveform.

The instantaneous frequency of this waveform is defined to be the derivative of the


argument of the sine function:

For the given values t used to compute samples y, what is the range of
instantaneous frequencies? Explain how this corresponds with the plot of the
Fourier series coefficients, and how it corresponds with what you hear.
6. The Fourier series coefficients computed in part 3 describe the range of
instantaneous frequencies of the chirp pretty well, but they do not describe the
dynamics very well. Plot the Fourier series coefficients for the waveform given by

Listen to this sound. Does it sound the same as y? Does its Fourier series plot look
the same or is it different? Why?
7. The chirp signal has a dynamically varying frequency-domain structure. More
precisely, there are certain properties of the signal that change slowly enough that
our ears detect them as a change in the frequency structure of the signal rather
than as part of the frequency structure (the timbre or tonal content). Recall that
our ears do not hear sounds below about 30 Hz. Instead, the human brain hears
changes below 30 Hz as variations in the nature of the sound rather than as
frequency domain content. The preceding Fourier series methods fail to reflect this
psychoacoustic phenomenon.

A simple fix is the short-time Fourier series. The preceding chirp signals have
8,000 samples, lasting one second. But since we don’t hear variations below 30 Hz
as frequency content, it probably makes sense to reanalyze the chirp signal for
frequency content 30 times in the one second. This can be done using the
Waterfall Spectrogram function. Spectrogram are color based visualizations of
the evolution of power spectrum of speech signal as the signal is swept through

Signals and Systems Page 37


time or in other words spectrogram is a 3D plot of the energy of the frequency
content of a signal as it changes over time.

function waterfallSpectrogram(s, fs, sizeofspectra, numofspectra)


% WATERFALLSPECTROGRAM - Display a 3-D plot of a spectrogram
% of the signal s.
%
% Arguments:
% s - The signal.
% fs - The sampling frequency (in samples per second).
% sizeofspectra - The number of samples to use to calculate each
% spectrum.
% numofspectra - The number of spectra to calculate.
frequencies = [0:fs/sizeofspectra:fs/2];
offset = floor((length(s)-sizeofspectra)/numofspectra);
for i=0:(numofspectra-1)
start = i*offset;
[A, phi] = fourierSeries(s((1+start):(start+sizeofspectra)));
magnitude(:,(i+1)) = A';
end
waterfall(frequencies, 0:(numofspectra-1), magnitude');
xlabel('Frequency');
ylabel('Time');
zlabel('Magnitude');

Where is the signal, is the sampling frequency, sizeofspectra is the number of


samples used to calculate each spectrum and numofspectra are the number of
spectra to calculate. Invoke this function on the chirp, and save the plot for
evaluation. Interpret the plot!
 – chirp signal
 – 8000Hz
 sizeofspectra – 400
 numofspectra – 30

8. An alternative visualization of the frequency content of such signals is the


spectrogram. A spectrogram is a plot like the one obtained in previous part, but
looking straight down from above the plot. The height of each point is depicted by a
color (or intensity, in a gray-scale image) rather than by height. Use the following
command to generate a spectrogram of the chirp signal

Create a similar image for the reverse chirp, z, of part 4.

Signals and Systems Page 38


4.4 ASSESSMENT SHEET

Name: __________________________

Reg. No. : _______________________

Date of Lab: ____________________

Exercise – 1

Exercise – 2

Exercise – 3

Exercise – 4
Problem
Number
Exercise – 5

Exercise – 6

Exercise – 7

Exercise – 8

MATLAB Codes
Lab
Performance
Viva

Total Score in Lab – 4

Instructor’s Verification

Signals and Systems Page 39


Signals and Systems Page 40
Lab - 5: Convolution and Laplace Transform

5.1 OBJECTIVES
 LTI Systems
 Impulse Response and Convolution
 Laplace Transform

5.2 LINEAR TIME INVARIANT SYSTEMS


Systems that are both linear and time-invariant (Lab 1) are called linear time invariant
(LTI) systems. LTI systems are very important because they can be used to model
many physical processes, and they provide a set of properties and powerful tools that
form the core of signals and systems.

The fundamental result in LTI system theory is that any LTI system can be
characterized entirely by a single function called the system's impulse response. The
output of the system is simply the convolution of the input to the system with the
system's impulse response.

LTI System

Figure 5.1

5.3 IMPULSE RESPONSE AND CONVOLUTION


Impulse response is output of an LTI system when presented with a unit impulse
function as input.
LTI System

Figure 5.2
MATLAB provides function ‘impulse’ to find the impulse response of an LTI system.
Impulse response is an important feature because it enables us to measure the output
of an LTI system in response to any input signal, by simply performing convolution.
Continuous Time Discrete Time
Convolution Integral Convolution Sum

5.3.1 Convolution Sum


To perform discrete time convolution in MATLAB, define the two vectors and with
elements in the sequences and . Then use the command. This
command assumes that the first element in and the first element in corresponds
to , so that the first element in the resulting output vector corresponds
to . If this is not the case, then the output vector will be computed correctly, but
the index will have to be adjusted. For further details about this function, use MATLAB
help. Consider the following example:

Signals and Systems Page 41


>> x=[1 1 1 1 1 1];
>> h=[0 1 2 3];
>> y=conv(x,h)
y=
0 1 3 6 6 6 6 5 3
In this example, and are indexed as described above, so . In
general, total up the index of the first element in and the index of the first element in
, this is the index of the first element in . For example, if the first element in
corresponds to and the first element in corresponds to then the
first element in corresponds to .
5.3.2 Convolution Integral
As the convolution sum is used for the convolution of discrete time signals, the
convolution integral is used for convolution of continuous time signal. Evaluation of
the convolution integral with a computer requires use of either numerical integration
or symbolic calculation techniques. Let us consider the convolution of with
itself [2]. That is, let us calculate:

>> syms t tau


>> z=int( (1/(1+tau^2) )*( 1/(1+(t-tau)^2) ),tau,-Inf,Inf)
z=
2*i*pi*(-1/2*i/(t^2-2*i*t)+1/(2*(i+t)*(1+t^2-2*t*(i+t)+(i+t)^2)+2*i*(1+(i+t)^2)))
>> simplify(z)
ans =
2*i*pi/(t-2*i)/(-2+i*t)
The above answer from MATLAB can further be simplified as follows:

5.4 LAPLACE TRANSFORM


Laplace transform ( is a linear operator on a function with real argument ,
which transforms it to a function with a complex argument . In signals
and systems, the real argument usually represents time domain , and complex
argument represents frequency domain.

Laplace Transform Inverse Laplace

MATLAB uses the command “laplace” to find the Laplace transform of a function, and
“ilaplace” for the inverse Laplace. Consider the following example of single sided
Laplace transform:

Signals and Systems Page 42


>> syms t
>> f = exp(-3*t);
>> z = laplace(f)
z=
1/(s+3)
>> ilaplace(z)
ans =
exp(-3*t)
5.4.1 s-plane and Region of Convergence (ROC)
The s-plane is the graphical analysis tool for the complex plane on which Laplace
transforms are graphed. It is a mathematical domain where, instead of viewing
processes in the time domain, they are viewed in the frequency domain. It can be
thought of as a modified Cartesian plane, with the real part ( ) of the complex number
s is represented by a displacement along the x-axis, and the imaginary part ( by a
displacement along the y-axis (commonly known as axis). The range of values of s
for which the Laplace transform converges is known as its Region of Convergence
(ROC). ROC is helpful in determining system properties such as stability and causality.
5.4.2 Properties of Laplace Transform
Linearity

Time Shifting

Frequency Shifting

Scaling

Convolution

5.4.3 Convolution Multiplication


The last property in table states that convolution in time domain is multiplication in
frequency domain. Consider the convolution of with itself.
Time Domain Frequency Domain

Now take inverse Laplace


from Transform Table:

This convolution is performed in time domain in MATLAB as follows:


>> syms t tau
>> z = int(exp(-3*tau)*exp(-3*(t-tau)),tau,0,t)
z=
t*exp(-3*t)

Signals and Systems Page 43


This convolution can also be performed in frequency domain, using Laplace transform
as shown below:
>> syms t
>> f = exp(-3*t);
>> g = laplace(f)
g=
1/(s+3)
>> h = g*g;
>> ilaplace(h)
ans =
t*exp(-3*t)

Signals and Systems Page 44


5.5 EXERCISE
1. Plot the convolution of a unit pulse with itself;

Then “deconv” the signal to check if you get the original signal back or not.

2. Write a function that will perform convolution sum bit by bit rather than using the
‘conv’ command.

3. Assume an LTI system has an impulse response:

4. Determine the output of the system is the input of the system is:

5. Convolve the following signals if the input of a system be given by:

6. And the impulse response is given by:

7. Evaluate discrete time convolution sums given below:




8. Consider the following 2 systems having the impulse responses:

Use MATLAB to plot the first 20 values of the impulse response

9. Find the Laplace transform of following functions



 (t)



Signals and Systems Page 45


5.6 ASSESSMENT SHEET

Name: __________________________

Reg. No. : _______________________

Date of Lab: ____________________

Exercise – 1

Exercise – 2

Exercise – 3

Exercise – 4

Problem
Exercise – 5
Number

Exercise – 6

Exercise – 7

Exercise – 8

Exercise – 9

MATLAB Codes
Lab
Performance
Viva

Total Score in Lab – 5

Instructor’s Verification

Signals and Systems Page 46


Lab - 6: z-Transform and Transfer Functions

6.1 OBJECTIVES
 z-transform
 Transfer functions
 Poles and zeros

6.2 Z-TRANSFORM
z-transform is the discrete time counter part of the Laplace transform. The complex
variable ‘ ’ in Laplace domain is replaced by ‘ ’ in z-domain.
z-Transform Inverse z-Transform

6.2.1 Mapping from s-Plane to z-Plane

Figure 6.1 From inputs to outputs of LTI systems


When we work with continuous-time signals and systems in the transform domain, we
use the Laplace transform, which is a function of the complex variable , having a real
part ( ) and an imaginary part ( ). When we work with discrete-time signals, we use
the z-transform. This transform is a function of the complex variable , which also has
real and imaginary parts. The z-plane is a complex plane associated with the z-
transform, just like the s-plane is a complex plane associated with the Laplace
transform. The complex variable is defined in terms of complex variable according
to the following expressions:

Where and is the sampling period. It can be easily seen that


the magnitude of the complex variable is related to the real part of , and the phase
of is related to the imaginary part of .
 When the real part of s is negative, the magnitude of z is less than 1. Therefore, the
left-half of s-plane maps into the interior of a circle centered at the origin with
radius = 1, called unit circle.
 When the real part of s is positive, the magnitude of z is greater than 1. Therefore,
the right-half of the s-plane maps into the exterior of unit circle.
 When the real part of s is equal to zero ( axis), the magnitude of z equals 1.
Therefore, the axis maps onto the boundary of the unit circle.
 Thus, the definition of z in terms of s gives us a complex plane where the unit circle
is of importance, and issues such as stability and frequency response will be dealt
with in terms of the unit circle rather than the axis.
Signals and Systems Page 47
6.2.2 Z-transform in MATLAB
MATLAB uses the following command to find the z-transform of a function (say f):

In order to find the inverse z-transform MATLAB uses the following command:

Suppose we want to find the z-transform of the following signal:

This can be accomplished by the following piece of MATLAB code:


>> syms k Ts z
>> x=ztrans(k*Ts)
x=
Ts*z/(z-1)^2
In order to plot the z-transform the following command can be used:

This function plots the zeros specified in column vector z and the poles specified in
column vector p. The symbol 'o' represents a zero and the symbol 'x' represents a pole.
The plot includes the unit circle for reference. For example:
>> z = [-.707 +.707];
>> p = [-1 +1];
>> zplane(z',p')

1
Imaginary Part

0.5

-0.5

-1
-1 -0.5 0 0.5 1
Real Part
Figure 6.2 Z-plane of the above example

6.3 TRANSFER FUNCTION


A transfer function is a mathematical representation of relationship between input and
output of an LTI system in the transform domain. (Refer to figure 6.1)
Continuous Time Discrete Time
Transfer Function Transfer Function

Transfer functions are defined in MATLAB by storing the coefficients of the numerator
and the denominator in vectors. Given a continuous-time transfer function:

Where Y and
Store the coefficients of Y and X in the vectors in order of descending powers
of s. In this text, the names of the vectors are generally chosen to be num and den, but

Signals and Systems Page 48


any other name could be used. For example, consider the following transfer function:

This transfer function is defined in MATLAB as follows:


>> num = [2 3];
>> den = [1 4 0 5];
Note that all coefficients must be included in the vector, even zero coefficients. The
commands create a transfer function from these polynomials, and plots the step and
impulse responses:
>> H=tf(num,den) % creates a LTI object H representing
% the Transfer Function.
Transfer function:
2s+3
---------------
s^3 + 4 s^2 + 5
>> step(num,den) % Plots the step response
>> impulse(num,den) % Plots the impulse response

6.4 POLES AND ZEROS


Poles are the roots of the denominator of a transfer function and zeros are the roots of
the numerator of a transfer function. The command finds the roots of a
polynomial described by the vector A, and thus maybe used to determine the zeros
and poles of a Laplace Transform expressed as a ratio of polynomials in s. The
elements of a vector A correspond to descending powers of s. For example consider
the following Laplace Transform:

We may find the poles and zeros of this equation using the following commands:
>> z=roots([4,0,6])
z=
0 + 1.2247i
0 - 1.2247i
>> p=roots([1,1,0,-2])
p=
-1.0000 + 1.0000i
-1.0000 - 1.0000i
1.0000
Hence we identify a pair of complex conjugate zeros at , a pole at
and a pair of complex conjugate poles at . The command poly(r) uses the
poles and zeros specified in the vector to determine the coefficients of the
corresponding polynomial. To find the zeros, poles and gain of a transfer function from
the vectors num and den which contain the coefficients of the numerator and
denominator polynomials, type:
>> num = [4,0,6];
>> den = [1,1,0,-2];
>> [z,p,k]=tf2zp(num,den)
z=
0 + 1.2247i
0 - 1.2247i
p=
-1.0000 + 1.0000i

Signals and Systems Page 49


-1.0000 - 1.0000i
1.0000
k=
4
The zeros are stored in z, the poles are stored in p, and the gain is stored in k. To find
the numerator and denominator polynomials from z, p, and k, type:
>> [num,den]=zp2tf(z,p,k)
num =
0 4.0000 0 6.0000
den =
1.0000 1.0000 0.0000 -2.0000

Or
>> H=zpk(z,p,k)
Zero/pole/gain:
4 (s^2 + 1.5)
--------------------
(s-1) (s^2 + 2s + 2)

6.4.1 Plotting the Poles and Zeros


The command ‘pzmap’ is used to plot the poles and zeros of the transfer function in
the s-plane. Learn the syntax by using MATLAB help.

Pole-Zero Map
1.5

1
Imaginary Axis

0.5

-0.5

-1

-1.5
-1.5 -1 -0.5 0 0.5 1
Real Axis
Figure 6.3

6.5 PARTIAL FRACTION EXPANSIONS


The ‘residue’ command finds the partial fraction expansion for a ratio of two
polynomials. The syntax is:

Where b is the numerator polynomial, a is the denominator polynomial, r is the partial
fraction expansion coefficients or residues, p is the poles, and k is a vector describing
any terms in power of s. If the order of the numerator is lesser than the order of the
denominator (also known as ‘proper form’), then k is an empty matrix.

Consider a system having zeros at , poles at


, and gain . We may determine the transfer function representation

Signals and Systems Page 50


for this system, plot the pole and zero representations in the s-plane and plot the
system’s magnitude response using the MATLAB commands:
>> z=[0,j*10,-j*10];
>> p=[-0.5+j*5,-0.5-j*5,-3,-4];
>> k=2;
>> syszpk=zpk(z,p,k)
Zero/pole/gain:
2 s (s^2 + 100)
-----------------------------
(s+4) (s+3) (s^2 + s + 25.25)
>> systf=tf(syszpk)
Transfer function:
2 s^3 + 200 s
---------------------------------------
s^4 + 8 s^3 + 44.25 s^2 + 188.8 s + 303
>> pzmap(systf)
The command ‘pzmap’ is used to plot the poles and zeros of the transfer function in
the s-plane. The following figure depicts the pole-zero plot from above code:

Pole-Zero Map
15

10
Imaginary Axis

-5

-10

-15
-4 -3 -2 -1 0
Real Axis
Figure 6.4 Pole and Zero locations in the s-plane

Signals and Systems Page 51


6.6 EXERCISE
1. Calculate the z-transform of the following signals and plot them:
a)
b)
c)
d)

2. The transfer functions for two causal LTI systems are given below,

a) Plot the pole-zero diagram of H1(z) and H2(z) using ‘zplane’. From the locations
of the poles and zeros, determine if the systems are stable or unstable and
explain your answer.
b) Plot the magnitude and phase of the frequency responses of the two systems in
the range 0 ≤ ≤ 2π. Use the function subplot for this section. Note: The
frequency response function of a system is obtained by substituting in
the transfer function.
c) Use the inverse z-transform to obtain the impulse responses of the two
systems, h1(n) and h2(n). Plot the impulse responses for 0 ≤ n ≤ 25. Do the
impulse responses verify your answer regarding system stability in part (a)?
How?

3. Determine the poles and zeros of the following systems and plot them in the s-
plane:

4. Find the partial fraction expansion for the Laplace Transform (also show working):

Signals and Systems Page 52


6.7 ASSESSMENT SHEET

Name: __________________________

Reg. No. : _______________________

Date of Lab: ____________________

Exercise – 1

Exercise – 2
Problem
Number
Exercise – 3

Exercise – 4

MATLAB Codes
Lab
Performance
Viva

Total Score in Lab – 6

Instructor’s Verification

Signals and Systems Page 53


Signals and Systems Page 54
Lab - 7: Fourier Transform

7.1 OBJECTIVES
 Fourier Transform (FT)
 Discrete Fourier transform (DFT)
 Discrete Time Fourier transform (DTFT)

7.2 FOURIER TRANSFORM


Fourier transform is an operator that transforms a signal from time domain to
frequency domain. Fourier transform finds a wide range of applications in signals and
systems, for example in this course we’re usually interesting in exploring the
frequency contents of a signal. The Fourier transform of a continuous time signal is
defined as:
Fourier Transform Inverse Fourier Transform

There are two important results that one should remember i.e.
 Fourier transform of a periodic signal has discrete values
 Fourier transform of an aperiodic signal has continuous values
7.2.1 Fourier Transform in MATLAB
MATLAB has a built in function fourier() and ifourier() for calculating the Fourier
transform and inverse Fourier transform respectively. Consider the following signal:

Then the Fourier Transform of the signal can be found by performing the integration,
using the following MATLAB commands:
>> syms a t f
>> sig=t/abs(t);
>> ut=(1+sig)/2;
>> pulse=subs(ut,t+a/2)-subs(ut,t-a/2)
pulse =
1/2*(t+1/2*a)/abs(t+1/2*a)-1/2*(t-1/2*a)/abs(-t+1/2*a)
>> pretty(pulse)
t + 1/2 a t - 1/2 a
1/2 ------------- - 1/2 --------------
| t + 1/2 a | | -t + 1/2 a |
>> Xjw=int( exp(-j*2*pi*f*t)*subs(pulse,a,1),t,-inf,inf)
Xjw =
-1/2*i*(exp(i*pi*f)-exp(-i*pi*f))/pi/f
>> pretty(simple(Xjw))
sin(pi f)
---------
pi f
The simple() command looks for a simple form of the function . The ezplot
command won’t give optimal results (check!). Plot the Fourier transform for above
example!!

Signals and Systems Page 55


7.3 DISCRETE FOURIER TRANSFORM (DFT)
Discrete Fourier transform is for discrete time i.e. sampled signals in MATLAB. It is
defined as follows:

Discrete Fourier Transform Inverse Discrete Fourier Transform

The most important thing while taking the DFT of a signal is the ‘number of points' or
‘N’. It indicates the number of points we are taking (from the signal) for the transform.
There are three cases with regards to N
 N < Length of signal: Results in a frequency response which doesn't show all the
frequency components present in the signal
 N = Length of signal: Results in a frequency response that gives all the frequency
components in the signal at their exact frequency value
 N > Length of signal: The DFT of the sampled signal becomes close to the transform
of the original signal i.e. DTFT.
7.3.1 Discrete Fourier Transform in MATLAB
When we sample a signal and want to get its Fourier transform we perform what is
called a Discrete Fourier Transform (DFT). An algorithm to do a DFT quickly is called
the Fast Fourier Transform (FFT). The algorithm is fast if the number of points is a
power of 2 (radix-2 FFT). The Discrete Fourier Transform of a sampled pulse will be a
scaled version of the Fourier transform of a pulse in continuous time. MATLAB uses
the following command to find the DFT of a signal

The fast Fourier transform (FFT) is an efficient algorithm for computing the DFT of a
sequence; it is not a separate transform. It is particularly useful in areas such as signal
and image processing, where its uses range from filtering, convolution, and frequency
analysis to power spectrum estimation. To find the inverse DFT:

To represent the equation in MATLAB avoiding loops we transform the summation
into its equivalent matrix operations by:

>> N = 40;
>> k=0:N-1;
>> n=0:N-1;
>> z=N-length(x);
>> x=[x zeros(1,z) ];
>> w=2*pi*k/N;
>> X=x* exp(-j*n'*w);

Explain when and why do we use the above piece of code which includes zero
padding??

Signals and Systems Page 56


7.4 DISCRETE TIME FOURIER TRANSFORM (DTFT)
The output of DTFT of a signal is the same as FT of the signal. DTFT can be visualized
as a DFT of a signal such that the number of points is very large. In such a case the
frequency spectrum of a sampled signal becomes very close to the frequency spectrum
of the original signal.

Discrete Time Fourier Transform Inverse Discrete Time Fourier Transform

7.4.1 Discrete Time Fourier Transform in MATLAB


Consider the following signal:

The DTFT of the signal in MATLAB can be found by:


>> syms f n
>> X=symsum(1*exp(-j*2*pi*f*n),n,-2,2)
X=
1+exp(4*i*pi*f)+exp(2*i*pi*f)+exp(-2*i*pi*f)+exp(-4*i*pi*f)
>> pretty(simple(X))
2 cos(2 pi f) + 2 cos(4 pi f) + 1

Signals and Systems Page 57


7.5 EXERCISES

1) Find and plot the Fourier Transform of the following signals:



2) Find and plot the Discrete Fourier Transform of the following signals:

3) Find and plot the Discrete Time Fourier Transform of the following signal:

4) Write a program to calculate the inverse Fourier transform of a signal and apply it
on part 1 to recover the original signals given.

5) Write a program to calculate the inverse discrete Fourier transform of a signal and
apply it on part 2 to recover the original signal given.

6) Write a program to calculate the inverse discrete time Fourier transform of a signal
and apply it on part 3 to recover the original signals given.

Signals and Systems Page 58


7.6 ASSESSMENT SHEET

Name: __________________________

Reg. No. : _______________________

Date of Lab: ____________________

Exercise – 1

Exercise – 2

Exercise – 3
Problem
Number
Exercise – 4

Exercise – 5

Exercise – 6

MATLAB Codes
Lab
Performance
Viva

Total Score in Lab – 7

Instructor’s Verification

Signals and Systems Page 59


Signals and Systems Page 60
Lab - 8: Sound and Images

8.1 OBJECTIVES
 Transforming sound signals
 Explore images and colormaps

8.2 SOUND SIGNALS


Use MATLAB help to explore the following useful MATLAB commands for this section:
 sound
 soundsc
 wavplay
8.2.1 Learning Tasks
Consider the sine wave given by:

1. Sample the function at 8 kHz, and plot the samples for the entire interval
. How many samples are there?

2. Change the frequency of the sine wave from the previous section to 440Hz and plot
the signal for the interval . Why is the plot hard to read? Plot the samples
that lie in the interval [0, 0.01] instead.

3. The MATLAB function sends the one-


dimensional array or vector sampled_signal to the audio card in your PC. The
second argument specifies the sampling frequency in Hertz. The values in
sampled_signal are assumed to be real numbers in the range [−1.0, 1.0]. Values
outside this range are clipped to −1.0 or 1.0. Use this function to listen to the
signals you created above. Describe what you hear.

Signals and Systems Page 61


4. Listen to both:

Where sampled_signal is the signal you created in part 2 above. Explain in what
way these are different from what you heard in the previous part.

5. Listen to

Explain how these are different.

8.3 USEFUL OPERATIONS ON SOUND SIGNALS


An analog signal input to the sound card is sampled and digitized by sound software
such as the ‘sound recorder’ (start/program/accessories/entertainment) as per its
default sampling parameters. The signal is saved as a .wav file. This file can then be
retrieved in MATLAB and played back using the ‘wavread’ command. To play a .wav
file or to play a vector in MATLAB we use the ‘sound’ command. This command can be
used with a user defined sampling frequency so as to see the effect of sampling
frequency on the sampled signal. Before playing a sound file you have to load the file in
the MATLAB environment using the load commands e.g. the above mentioned
‘wavread’ command is used to load a .wav file into the MATLAB environment. After
that the file can be played as per the specified sampling rate.
8.3.1 Mono/stereo
MATLAB understands mono and stereo sounds as single column and two column
vectors respectively. In our lab we shall take only mono signals as they are easier to
manipulate. In this lab we shall consider, only telephone or radio signals which are
mono. The type of these signals, which are saved as the .wav file, should be carefully
selected.
8.3.2 Manipulation
We know that MALTAB treats all the inputs and output as matrices/vectors. Therefore,
the manipulation of an audio signal is no different than altering the component of a
matrix and in our case a row vector (mono signal). Only a couple of simple cases of
MATLAB signal manipulation are discussed in this lab. Avoid using ‘loops’ in
manipulating a signal.
8.3.3 Double
This function creates a longer vector by adding an additional element between
neighboring elements in the original vector. Each new element should be equal to the
average of its neighboring elements.
8.3.4 Half
This function removes every other element from an arbitrary vector, creating a shorter
vector made of only the odd numbered elements of the original vector.
Signals and Systems Page 62
8.3.5 Echo
Consider the following diagram:
Input Output
Signal Signal

Attenuation Delay

Figure 8.1 Echo generator


In the echo generator, the original signal is attenuated, delayed and then added to the
original signal. This is the signal that we hear and experience an echo effect in.

8.4 IMAGES IN MATLAB


Figure 9.1 shows a grayscale image where the intensity of the image varies
sinusoidally in the vertical direction. The top row of pixels in the image is white.

Figure 8.2 An image where the intensity varies


Sinusoidally in the vertical direction [1]
As you move down the image, it gradually changes to black, and then back to white,
completing one cycle. The image is 200 × 200 pixels so the vertical frequency is 1/200
cycles per pixel. The image rendered on the page is about 10 × 10 centimeters, so the
vertical frequency is 0.1 cycles per centimeter. The image is constant horizontally (it
has a horizontal frequency of 0 cycles per pixel).

We begin this section by constructing the MATLAB commands that generate this
image. To do this, you need to know a little about how MATLAB represents images. In
fact, MATLAB is quite versatile with images, and we will only explore a portion of what
it can do.

An image in MATLAB can be represented as an array with two dimensions (a matrix)


where each element of the matrix indexes a colormap. Consider, for example, the
image constructed by the image command:
>> v=[1:64];
>> image(v)
This should create an image which is 1 pixel high by 64 pixels wide (MATLAB, by
default, stretches the image to fit the standard rectangular graphic window, so the one
pixel vertically is rendered as a very tall pixel). You could use the ‘repmat’ MATLAB
function to make an image taller than 1 pixel by just repeating this row some number

Signals and Systems Page 63


of times. The pixels each have value ranging from 1 to 64. These index the default
colormap, which has length 64 and colors ranging from blue to red through the
rainbow. To see the default colormap numerically, type
>> map=colormap
>> size(map)
ans =
64 3
Notice that it has 64 rows and three columns. Each row is one entry in the colormap.
The three columns give the amounts of red, green, and blue, respectively, in the
colormap. These amounts range from 0 (none of the color present) to 1.0 (the
maximum amount of the color possible). Examine the colormap to convince yourself
that it begins with blue and ends with red. Change the colormap using the colormap
command as follows:
>> map=gray(256);
>> colormap(map)
>> image([1:256] );
Examine the map variable to understand the resulting image. This is called a
Grayscale Colormap.

Signals and Systems Page 64


8.5 EXERCISES
1. Use MATLAB to plot the following continuous-time function

The first of these is a familiar sinusoidal signal. The second is a sinusoidal signal
with a decaying exponential envelope. The third is a sinusoidal signal with a
growing exponential envelope. Choose a sampling period so that the plots closely
resemble the continuous-time functions. Explain your choice of the sampling
period. Use subplot to plot all three functions in a single figure.
2. Use MATLAB to listen to a one-second sinusoidal waveform scaled by a decaying
exponential given by

Use a sample rate of 8,000 samples/second. Describe how this sound is different
from sinusoidal sounds that you heard before in the lab tasks.
3. Construct a sound signal that consists of a sequence of half-second sinusoids with
exponentially decaying envelopes, as in the previous part, but with a sequence of
frequencies: 494, 440, 392, 440, 494, 494, and 494. Listen to the sound. Can you
identify the tune?

4. Copy a .wav file into the work directory of MATLAB. Use the ‘wavread’ command
to read it into your MATLAB. Convert it into a mono sound if it’s a stereo.
Manipulate it to create a double function, a half function and an echo function
described above.

5. What is the representation in a MATLAB colormap for the color white? What about
black?

6. Create a 200 × 200 pixel image like that shown in figure 9.2. Set the colormap to
gray(256), as indicated above. Note that when you display this image using the
image command, it probably will not be a square. This is because of the (somewhat
annoying) stretching that MATLAB insists on doing to make the image fit the
default graphics window. To disable the stretching and get a square image, use the
axis command. As usual with MATLAB, a brute-force way to create matrices is to
use for loops, but there is almost always a more elegant (and faster) way that
exploits MATLAB’s ability to operate on arrays all at once. Try to avoid using for
loops to solve this and subsequent problems.

7. Change your image so that the sinusoidal variations are horizontal rather than
vertical. Vary the frequency so that you get four cycles of the sinusoid instead of
one. What is the frequency of this image?

8. An image can have both vertical and horizontal frequency content at the same time.
Change your image so that the intensity at any point is the product of a vertical and
horizontal sinusoid. Be careful to stay within the numerical range that indexes the
colormap.

Signals and Systems Page 65


8.6 ASSESSMENT SHEET

Name: __________________________

Reg. No. : _______________________

Date of Lab: ____________________

Learning Tasks

Exercise – 1

Exercise – 2

Exercise – 3

Problem
Exercise – 4
Number

Exercise – 5

Exercise – 6

Exercise – 7

Exercise – 8

MATLAB Codes
Lab
Performance
Viva

Total Score in Lab – 8

Instructor’s Verification

Signals and Systems Page 66


Lab - 9: Graphical User Interface

9.1 OBJECTIVES
Building Graphical User Interface (GUI) in MATLAB.

9.2 GRAPHICAL USER INTERFACE (GUI)


The GUI (Graphical User Interface) is a feature of MATLAB that gives a presentable
look and easy access to the program/code written by the user. GUI acts as an interface
between the actual code and the user.
9.2.1 Launching GUI
To launch GUI we can either select the ‘guide’ from the ‘launch- pad' or type ‘guide’ in
the main command window. It will open a popup menu, from which one can choose
different kinds of GUI. By selecting ‘Blank GUI (Default)’, the following window is
launched:

Figure 9.1 GUI Window


9.2.2 Using GUI
From the choices on the left hand side we can create buttons, multiple choices, scroll
select menus and much more. First we select what we want to create. Then we drag
the mouse in the grid portion to make a box. After we leave the mouse click, the option
is displayed in that area of the box e.g. in figure 10.2 we have created a push button, a
popup menu, a check box and a list to select from.

These boxes can be placed anywhere in the checked screen, by clicking on them and
dragging them with the mouse. Once we are sure that we have made all the changes
and that this is the kind of outlook we want, we can save the file with a name in the
current work directory. The file is saved as a ‘.fig' file and can be accessed in the
MATLAB command window by just typing its name. When the file is saved, a ‘.m' file is

Signals and Systems Page 67


automatically created by the same name. In this file we add any links that we want to
associate with these buttons/menus.

Figure 9.2 Creating boxes in GUI

9.2.3 Properties of Objects Created


The properties of the boxes/menus created can be accessed by right clicking the box
and selecting ‘property inspector'. When the property Inspector is selected, a menu
pops up in front of us, where we can select the color, the font size/style, type, title and
tag of the button. The title of the button is the name written on it and the tag is the
name with which it is referred to as, in the .m file created.
9.2.4 Linking Files/ Actions
To link a file to the button/menu, first of all, we have to open the .m file of the GUI file.
After that we find the tag of the button we want to associate the file with. In the .m file
we see tags of different buttons as shown in figure 8.3.
We type the file name to be opened under the tag name and then save the file. Now,
when we run the GUI file and press the button, the code in the associated file is run.

9.3 EXAMPLES
MATLAB help provides elaborate examples for using different functions and toolboxes.
In order to see a sample GUI, type “doc” in command window. This will open HTML
documentation in help browser.
 Search for “Simple GUI"
 Read this example
 Open its m-file
 Play the file
 Study its callback functions

Signals and Systems Page 68


Figure 9.3 The .m file of GUI

9.4 EXERCISE
1. Make a model in GUI that will calculate the first 5 harmonics of a sine wave, also
display the results in GUI.

2. Make a model in GUI that will add up the harmonics of a sine wave and display a
square wave. Input the wave from GUI and display the output in GUI. The output
must near a perfect square wave when more and more odd harmonics are added.

3. Record a statement in your voice: “I am taking a course in signals and systems”.


Load this file in a GUI which plots the frequency spectrum of this speech signal.

Signals and Systems Page 69


9.5 ASSESSMENT SHEET

Name: __________________________

Reg. No. : _______________________

Date of Lab: ____________________

Exercise – 1

Problem
Exercise – 2
Number

Exercise – 3

MATLAB Codes
Lab
Performance
Viva

Total Score in Lab – 9

Instructor’s Verification

Signals and Systems Page 70


Lab - 10:Sampling and Aliasing

10.1 OBJECTIVES
 Sampling and Aliasing
 Nyquist criteria

10.2 INTRODUCTION
It is often desired to analyze and process continuous-time signals using a computer.
However, in order to process a continuous-time signal, it must first be digitized. This
means that the continuous-time signals must be sampled and quantized, forming a
digital signal that can be stored in a computer. Analog systems can be converted to
their discrete-time counterparts, and these digital systems then process discrete-time
signals
to produce discrete-time outputs. The digital output can then be converted back to an
analog signal, or reconstructed, through a digital-to-analog converter. Figure 10.1 is an
illustration containing the three general components described above: a sampling
system, a digital signal processor, and a reconstruction system. In this lab we will focus
on the process of sampling and reconstruction.

Figure 10.1

10.3 SAMPLING
Sampling is simply the process of measuring the value of a continuous-time signal at
certain instants of time. Typically, these measurements are uniformly separated by the
sampling period . If is the input signal, then sampled signal is as follows:

In the spectral domain, sampling produces a periodic spectrum, with images of the
original spectrum centered around multiples of the sampling frequency (aliases):

Where is the sampled signal spectrum, and is the original signal spectrum. If the
signal is sampled properly, it is possible to reconstruct it perfectly from the discrete
values. Sampling frequencies that are too low lead to aliasing – frequencies from the
aliases of the original spectrum will appear in the original band, and the nature of the
spectrum is changed. If the sampling frequency is too low, some harmonic components
can end up being aliased into the negative frequency range. These components fold
back around zero frequency and appear in the original band as low frequency
components.

Signals and Systems Page 71


10.4 NYQUIST CRITERIA
We know that the greater the number of samples the greater the accuracy, then why
don't we sample at a very high rate? Firstly, higher number of samples requires a lot of
manipulation on the behalf of the machine/software, which results in more time.
Secondly, most of the vital data that we need can easily be obtained from low sampling
rates. Therefore we need some criteria to define the rate at which the signal should be
sampled. This criterion is called as ‘Nyquist Criteria’. According to these criteria, the
sampling frequency must (at least) be twice the signal frequency.

10.5 LEARNING TASKS

1. Assume you sample a 2 Hz sinusoid, at a sampling rate = 8Hz starting at 0s. Is the
Nyquist criterion satisfied? Calculate values of the sampled signal during the first
second. (HINT: create an appropriate vector in MATLAB starting at 0 and ending at
1. Check help for the sine function.)

2. Now assume you sample a 10 Hz sinusoid at the same sampling rate. What about
the Nyquist criterion now? Calculate the values of the sampled signal during the
first second. Compare the results with the previous calculation. What happened?
Sketch both signals during the first second, and mark the sampling instants and the
samples on your sketch.

Signals and Systems Page 72


3. Consider the signal spectrum in the figure below. What is the Nyquist rate for this
signal? Sketch the spectrum of the sampled signal if it is ideally (impulse) sampled
at Nyquist rate. Mark the relevant frequencies. How would you reconstruct the
original signal?

Figure 10.2 Baseband signal spectrum (Hz)

4. The spectrum shown in Figure 11.4 is that of a band pass signal. What is its Nyquist
rate? Assume that it is ideally (impulse) sampled a) at = 500Hz and b) at =
200Hz. Is the Nyquist criterion satisfied in these two cases? Sketch the spectra for
both cases of sampled signals. Mark the relevant frequencies. Is there aliasing?
Could the original signal be reconstructed? If so, how (in the ideal case)?

Figure 10.3 Band pass signal spectrum (Hz)

Signals and Systems Page 73


10.6 EXERCISE
We will work with a particular chirp signal that has a convenient Fourier transform for
visualizing and hearing aliasing effects. For efficient computation using the FFT
algorithm, we will work with 8,192= 213 samples, giving slightly more than 1 second
of sound at an 8,000 samples/second sample rate. Let D stand for duration, the chirp
signal we wish to create is given by:

Here is time-varying amplitude given by:

1. Generate a chirp as explained above that lasts for 8,192 samples at an 8-kHz
sample rate and sweeps from a frequency of zero to 2,500 Hz. Listen to the
resulting sound. Are there any aliasing artifacts? Why or why not?
2. Use the FFT algorithm, to create a plot of the magnitude of the DFT of the chirp
signal from the previous part over the frequency range -4 kHz to 4 kHz. Make sure
the horizontal axis of the plot is labeled in Hertz. Does the plot look like a sensible
frequency-domain representation of this chirp?
3. Modify the chirp so that it sweeps from 0 to 5 kHz. Listen to it. Do you hear aliasing
artifacts? Plot the magnitude of the DFT over -4 kHz to 4 kHz. Can you see the
aliasing artifacts in this plot? Explain why the plot has the shape that it does.
4. Return to the chirp that you generated in part 1, which sweeps from 0 to 2,500 Hz.
Create a new signal with sample rate 4,000 samples/second by downsampling
that chirp. That is, create a vector in MATLAB that has half the length by selecting
every second sample from the original chirp. For example, if y(n) is the original
chirp, define w(n) as . Now plot the magnitude DFT of this signal.
Since the sampling rate is lower by a factor of 2, you should plot over the frequency
interval -2 kHz to 2 kHz. Is there aliasing distortion? Why?
5. Return again to the chirp that you generated in part 1, which sweeps from 0 to
2,500 Hz. Create a new signal with sample rate 16,000 samples/second by
upsampling that chirp. That is, create a vector in MATLAB that has twice the
length by inserting zero-valued samples between each pair of samples from the
original chirp. For example, if y(n) is the original chirp, define z by

6. Now plot the magnitude DFT of this signal. Since the sampling rate is higher by a
factor of 2, you should plot over the frequency interval -8 kHz to 8kHz. Explain this
plot. Listen to the sound by giving a sampling frequency argument to soundsc as
follows:

7. How does the sound relate to the plot? Note that this technique is used in most
compact disc players today. The signal on the CD is sampled at 44,100
samples/second. The CD player first upsamples it by a factor of 4 or 8 to get a
sample rate of 176,400 samples/second or 352,800 samples/second. The
upsampling is accomplished by inserting zero-valued samples. The resulting signal
is then digitally filtered to get a high sample rate and accurate rendition of the
audio. The higher sample rate signal is then converted to a continuous-time signal
by a digital to analog converter that operates at the higher sample rate. This
technique shifts most of the difficulty of rendering a high-quality audio signal to
the discrete time domain, where it can be done with digital circuits or
microprocessors (such as programmable DSPs) rather than with analog circuits.

Signals and Systems Page 74


10.7 ASSESSMENT SHEET

Name: __________________________

Reg. No. : _______________________

Date of Lab: ____________________

Learning Tasks

Exercise – 1

Exercise – 2

Exercise – 3
Problem
Number
Exercise – 4

Exercise – 5

Exercise – 6

Exercise – 7

MATLAB Codes
Lab
Performance
Viva

Total Score in Lab – 10

Instructor’s Verification

Signals and Systems Page 75


Signals and Systems Page 76
Lab - 11: Simulink

11.1 OBJECTIVES
Introduction to Simulink

11.2 SIMULINK
MATLAB and Simulink are two very different pieces of software with radically
different approaches to modeling of signals and systems. MATLAB is an imperative
programming language, whereas Simulink is a block diagram language. Simulink is
used for a variety of purposes, but mainly for the simulation of real time systems. The
function of Simulink is very similar to that of electronic work bench or circuit designer.

There are certain components already defined in Simulink, like clocks, muxes,
input/output switches, signal generators, scopes and many more. By connecting these
components we can generate a simulation of the actual circuit and visualize its
response to different inputs. The in-built functional blocks can be modified to a certain
extent, but if we want to create a custom block or macro, we have to use s-functions.

Each block that is created has a .m file behind it or a C-code that executes whenever
the block is activated. By writing an s-function we mean that we create an m-file or a
C-code by our own in which the function of the block is explained with its different
inputs.
11.2.1 How to Launch Simulink
The Simulink can be launched by typing ‘Simulink’ in the MATLAB command window.
When we do so, a window pops up:

Figure 11.1
In the Simulink library browser shown in above figure is a list of toolboxes on the left
and a list of components on the right. Whenever a particular toolbox is selected the list

Signals and Systems Page 77


of components in that toolbox appears on the right hand side.
11.2.2 Using Simulink
To create a simulation in Simulink, a new file is created first. In this file, objects from
the Simulink library browser are inserted. If we are not sure in which tool box the
object would lie, we can use the search command.
After the object has been found right click on the object and select insert. The object is
automatically inserted in the simulation file e.g.

Figure 11.2: Simulation files in Simulink


11.2.3 Making Simulations
To make a simulation, add the components in a simulink file, and then make the
connections required by dragging the connectors of different blocks. Once the
connections are made, save the file and then click the play button at the top of the
window.

Figure 11.3 Simulation in Simulink


11.2.4 Properties of Blocks
The properties of the blocks inside the simulation can be altered by right clicking on
the block and then selecting ‘block properties’. Different features like: name, number
of variables, inputs/outputs, nature of signal generated etc can be adjusted.

Signals and Systems Page 78


11.3 EXERCISE

1. Create a model that adds up 4 sinusoids to generate a square wave, stores the
result in the Workspace, and displays the result on the scope.

2. Create a model to differentiate and integrate a simple sine wave.

3. Create a model that will calculate the z-transform of an input signal given by you.

4. Create a model that will calculate the Fourier Transform of an input signal
provided by a user, and show its frequency contents using ‘spectrum analyzer’.

Signals and Systems Page 79


11.4 ASSESSMENT SHEET

Name: __________________________

Reg. No. : _______________________

Date of Lab: ____________________

Exercise – 1

Exercise – 2
Problem
Number
Exercise – 3

Exercise – 4

MATLAB Codes
Lab
Performance
Viva

Total Score in Lab – 11

Instructor’s Verification

Signals and Systems Page 80


References
[1]. Edward. A. Lee and Pravin Varaiya, University of Berkeley, “Signals and Systems
Laboratory Manual”
[2]. Shlomo Engelberg, “A MATLAB and Simulink based Signals and Systems
Laboratory”

Signals and Systems Page 81

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy