You are on page 1of 85

DEPARTMENT OF ELECTRICAL ENGINEERING

LAB MANUAL

SIGNAL & SYSTEMS

EE-501

UNIVERISTY COLLEGE OF ENGINEERING & TECHNOLOGY,


BAHAUDDIN ZAKARIYA UNIVERSITY, MULTAN
1
List Of Experiments

Lab # Title Page


#
1 Introduction to MATLAB 3

2 Introduction to Matrices and Arrays 9

3 Introduction to MATLAB
PART A:Dealing with polynomials & Partial fraction expansion
PART B:Plotting in MATLAB 14
PART C:Solving ordinary differential equation (ODE) symbolically

4 Generating Signals using MATLAB 22

5 Discrete time signals in time-domain 32

6 Convolution of Continuous time signals 41

7 Convolution of Discrete time signals 44

8 Impulse Response of a Discrete Time System 49

9 Frequency Response of a Discrete Time System 54

10 Properties of Linear Time-Invariant Discrete-Time 63


Systems

11 Generating Signals using Simulink

12 Simulating different types of Modulation using MATLAB 68

13 Laplace transforms using MATLAB 71

14 Fourier Series in MATLAB 73

15 Fourier Transform using MATLAB 78

16 Z- Transform using MATLAB 81

2
Experiment 1
Introduction to MATLAB

Exercise Objective:
PART A: Familiarization with MATLAB screen

PART B: A minimal MATLAB Session

Requirements:
➢ a computer
➢ MATLAB

Theory:
MATLAB is a high performance language for technical computing. It integrates computation,
visualization and programming in an easy-to-use environment where problems and solutions are
expressed in familiar mathematical notation. It is particularly convenient for modeling,
simulation, analysis and design of dynamic systems.

The purpose of this introductory lab is to give you a quick introduction to MATLAB enabling
you to use the software from the very beginning of the Signal & Systems course. To run
MATLAB, double-click on the MATLAB icon. Once the program is loaded you will see the
prompt”>>” in the command window. The command window is the main window in which we
communicate with the MATLAB interpreter. Anything typed after “%” sign is treated as a
comment and ignored by MATLAB. First we will familiarize with the MATLAB screen.

Procedure:

3
MATLAB has the following basic window components:
• Launch Pad Window
• to access all MATLAB services and toolboxes
• Command Window
- to execute commands in the MATLAB environment
• Current Directory Window
- to quickly access files on the MATLAB path
• Figure Window
- to display graphical output from MATLAB code
Basic Components of the MATLAB Environment
• Workspace Window
- to view variable definitions and variable memory allocations
• M-File Editor/Debugger Window
- to write M-files (includes color-coded syntax features)
- to debug M-files interactively (break points)
• MATLAB Path Window
- to add and delete folders to the MATLAB path
• Command History Window
- displays all commands issued in MATLAB since the last session (good for learning and
verification)
MATLAB Command Window
• The command window allows you to interact with MATLAB just as if you type things in a
calculator
• Cut and paste operations ease the repetition of tasks
• Use ‘up-arrow’ key to repeat commands (command history)
MATLAB Launch Pad Window
• The launch window allows you to quickly select among various MATLAB components and
toolboxes
MATLAB Current Directory Window
• Provides quick access to all files available in your Path
• Provides a brief description (when files are commented out) of each M-file

4
MATLAB Editor/Debuger Window
• Provides the same functionality found in most programming language development
environments
- Color codes MATLAB built-in functions (blue color)
- Easy access to cut, paste, print, and debug operations
- Checks balance in MATLAB function syntax

MATLAB Figure Window


• Displays the graphic contents of MATLAB code (either from Command Window, an M-file, or
output from MEX file)

5
MATLAB Workspace
As you develop and execute models in MATLAB theworkspace stores all variables names and
definitions for you. All variables are usually available to you unless the workspace is clear with
the ‘>>clear’ command

Getting Started:-
If you don’t know anything about MATLAB, then MATLAB help is the best way to learn about
something. In the command window of MATLAB simply write ‘help’;
>> help
It will display list of all toolboxes included in MATLAB. Then by investigating the name of
toolbox or the name of a function, which you would like to learn how to use, use the ‘help’
command:
>> help function name
This command displays a description of the function and generally also includes a list of related
functions. If you cannot remember the name of the function, use the ‘lookfor’ command and the
name of some keyword associated with the function:
>>look for keyword
This command will display a list of functions that include the keyword in their descriptions.
MATLAB also contains a variety of demos that can be with the ‘demo’ command.

MATLAB as a calucator

>>1+2*3 >>(1+2)*3
Ans = 7 ans = 9

Order of precedence is from left to right and from inner most parenthesis to outermost

Declaring and assigning a variable in MATLAB


Variable name=value(or expression)
6
Default variable is and
Let x=1;
Y=3*x
Y=3

.Suppressing output:
If you simply type a statement and press Return or Enter, MATLAB automatically displays the
results on screen. However, if you end the line with a semicolon, MATLAB performs the
computation but does not display any output. This is particularly useful when you generate large
matrices

Multiple statements per line with,and; operator

e.g>>x=1;y=5;z=9
ans
z=9

Complex Numbers:
MATLAB also supports complex numbers.The imaginary number is denoted with the symbol I
or j. There are different methods to declare a complex number which are given below

>>com=4+2i
com=4.0000 + 2.0000i
>> c=complex(1,-2)
Operations on Complex Numbers:
c=1.0000-2.0000i
Conjugate: Imaginary Part:

>> c=conj(com) >> i=imag(com)


c = 4.0000 – 2.0000I i=2
Real Part: Angle in Radian:
>> r=real(com) >>a_radian = angle(com)
r=4 a_radian = 0.4636
Magnitude: Angle in Degree:
>>mag=abs(com)
Math functions >>a_degree = angle(com)*180/pi
MATLAB comes mag
with =a 4.4721
large number of built-in functions that operate
a_ on matrices on an
element-by element basis. These include:

7
Built-in Mathematical functions in MATLAB
MATLAB comes with a large number of built-in functions that operate on matrices on an
element-by element basis. These include

sin sine
cos cosine
tan tangent
asin inverse sine
acos inverse cosine
atan inverse tangent
exp exponential
log natural logarithm
log10 common logarithm
sqrt square root
abs absolute value
signsignum
for further functions see help elfun
helpspecfun
Before quitting,Save .m files in current work (default) directory of MATLAB
To end a session
>>exit or quit

Conclusion:

8
Experiment 2
Introduction to Matrices and Arrays

Exercise Objective:
To become familiar with matrices and arrays and operations that can be performed on them

Requirements:
➢ Intel based computer
➢ MATLAB

Theory:
MATLAB stores variables in the form of matrices which are M ×N, where M is the numberof
rows and N the number of columns. A 1 × 1 matrix is a scalar; a 1 × N matrix is a row vector,
and M×1 matrix is a column vector. You can enter matrices into MATLAB in several different
ways:
• Enter an explicit list of elements.

• Generate matrices using built-in functions etc


Procedure:
To enter the matrix

Real scalar >> x = 5


Complex scalar >> x = 5+10j (or >> x = 5+10i)
Row vector >> x = [1 2 3] (or x = [1, 2, 3])
Column vector >> x = [1; 2; 3]
3 × 3matrix >> x = [1 2 3; 4 5 6; 7 8 9]

Generating Matrices using Function:


MATLAB software provides two major functions that generate basic matrices.
1-zeros All zeros
2-ones>>
Alla = ones(3,3) % Identity Matrix
ones
Here are some examples:
A=
>>a(1,3) = 3% Assigning a value
1 1 1
A=
1 1 1
0 0 3 0
1 1 1
9 0 0 0 0
>> a = Zeros(4,4); % Null/Empty/Zero
matrix 0 0 0 0
0 0 0 0
%Unit Matrix
The n × n identity matrix is a matrix of zeros except forhaving ones along its leading diagonal
(top left to bottom right). This is called eye (n) in MATLAB
>>a=eye(3)
A=
1 0 0
0 1 0
0 0 1
%Diagonal matrix
A diagonal matrix is similar to the identity matrix exceptthat its diagonal entries are not
necessarily equal to 1.
>>d=[1 4 7];
>>D=diag(d)
D=
1 0 0
0 4 0
0 0 7

Generating vectors
Vectors can be generated using the ‘:’ command. For example, to generate a vector x that takes
on the values 0 to 10 in increments of 0.5, type the following which generates a 1×21 matrix
>> x = [0:0.5:10];
Other ways to generate vectors include the commands: ‘linspace’ which generates a vector by
specifying the first and last number and the number of equally spaced entries between the first
and last number, and ‘logspace’ which is the same except that entries are spaced logarithmically
between the first and last entry

Accessing vector elements


Elements of a matrix are accessed by specifying the row and column. For example, in the matrix
specified by A = [1 2 3; 4 5 6; 7 8 9], the element in the first row and third column can be
accessed by writing
>> x = A(1,3) which yields 3
The entire second row can be accessed with
>> y = A(2,:) which yields [4 5 6]
where the ‘:’ here means “take all the entries in the column”. A submatrix of A consisting of
rows 1 and 2 and all three columns is specified by
>> z = A(1:2,1:3) which yields [1 2 3; 4 5 6]

Arithmetic matrix operations


The basic arithmetic operations on matrices (and of course scalars which are special cases
of matrices) are:
+ addition
- subtraction
* multiplication
10
/ right division
\ left division
^ exponentiation (power)
’ conjugate transpose

Arithmetic operations on matrices


Addition: Division:
>> d =a+b
>> h=a/b
d=6 8 10 12
h=0.4023
Subtraction:
Assigning an Element from a Matrix:
>> e =a-b
>> i=a(1,3) % will assign elements in row
e=-4 -4 -4 -4 2 and columns 3 of matrix “a “to variable
“i”.
Multiplication:
>> g =a*c g=70

Note :An error message occurs if the sizes of matrices are incompatible for the operation.
The difference between matrix multiplication and element-by-element multiplication is
seen in the following example
>>A = [1 2; 3 4]
A=
12
34
>>B=A*A
B=
7 10
15 22
>>C=A.*A
C=
14
9 16
The magic Function
MATLAB actually has a built-in function that creates magic squares of almost any size. Not
surprisingly, this function is named magic:
B = magic (4)
B=
16 2 3 13
5 11 10 8
9 7 6 12
11
4 14 15 1
Properties of MAGIC SQUARE:
You are probably already aware that the special properties of a magic square have to do with the
various ways of summing its elements. If you take the sum along any row or column, or along
either of the two main diagonals, you will always get the same number. Let us verify that using
MATLAB.
The first statement to try is

sum(A)
MATLAB replies with
ans =
34 34 34 34
A'
Produces sum of rows
ans =
16 5 9 4
3 10 6 15
2 11 7 14
13 8 12 1
and
sum(A')'
produces a column vector containing the row sums
ans =
34
34
34
34
The sum of the elements on the main diagonal is obtained with the sum and the diag functions:
diag(A)
produces
ans =
16
10
7
1
and
sum(diag(A))
produces
ans =
34

Linear algebra functions on Matrices


12
Matrices can sometimes be inverted:
>>inv(B)
Note:A matrix can be inverted if and only if its determinant is nonzero:If you try to compute the
inverse for a matrix with non-zero determinantyou will get a warning message:
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate.
>>det(B);

Arrays
When they are taken away from the world of linear algebra, matrices becometwo-dimensional
numeric arrays. Arithmetic operations on arrays aredone element by element. This means that
addition and subtraction arethe same for arrays and matrices, but that multiplicative operations
aredifferent. MATLAB uses a dot, or decimal point, as part of the notation formultiplicative
array operations.
The difference between matrix multiplication and element-by-element multiplication is
seen in the following example
>>A = [1 2; 3 4]
A=
12
34
>>B=A*A
B=
7 10
15 22
>>C=A.*A
C=
14
9 16

Other query commands


We can get the size (dimensions) of a matrix with thecommand size:
Size(B)
Length(B) etc

Conclusion:

13
Experiment 3
Introduction to MATLAB

Exercise Objective:
PART A: Dealing with Polynomials& Partial Fraction Expansion
PART B: Plotting in MATLAB
PART C: Solving ordinary differential equations (ODE) symbolically

Requirements:
➢ Intel based computer
➢ MATLAB

Theory:
MATLAB provides a full programming language that enables you to write a series of MATLAB
statements into a file and then executing them into a single document.
Polynomials are used for the analysis of transfer function because in case of transfer function we
want to see output and input in the form of polynomial. So it is important to study the
polynomials in MATLAB.
When trying to find the inverse Laplace transform (or Z transform) it is helpful to be able to
break a complicated ratio of two polynomials into forms that are on the Laplace transform or Z
transform table. We will illustrate here using Laplace transforms. This can be done using the
method of Partial fraction expansion (PFE) which is the reverse of finding a common
denominator and combining fractions. It is possible to do PFE by hand also. We will illustrate
hand computation only for the simplest case when there are no repeated roots and the order of
the numerator polynomial is strictly less than the order of denominator polynomial.
The primary tool we will use for plotting in MATLAB is plot().The MATLAB environment
provides a wide variety of techniques to displaydata graphically.
The type of graph you choose to create depends on the nature of your dataand what you want to
reveal about the data. You can choose from manypredefined graph types, such as line, bar,
histogram, and pie graphs as wellas 3-D graphs, such as surfaces, slice planes, and streamlines.
After you create a graph, you can extract specific information about the data. You can also edit
graph components as well as annotate graphs. Annotations are the text, arrows, callouts, and
other labels added to graphsto help viewers see what is important about the data.lastly you can
print your graph on any printer connected to your computer

14
Though MATLAB is primarily a numeric package, it can certainly solve straightforward
differential equations symbolically as well using Math symbolic toolbox as demonstrated in this
lab.

Procedure:
PART A: Dealing with Polynomials
Polynomials
Polynomials arise frequently in systems theory. MATLAB represents polynomials as row vectors
of polynomial coefficients. For example, the polynomial s2 +4s−5 is represented in MATLAB
by the polynomial >> p = [1 4 -5]. The following is a list of the more important commands for
manipulating polynomials.
roots(p) Express the roots of polynomial p as a column vector
polyval(p,x) Evaluate the polynomial p at the values contained in the vector x
conv(p1,p2) Computer the product of the polynomials p1 and p2
deconv(p1,p2) Compute the quotient of p1 divided by p2
poly2str(p,’s’) Display the polynomial as an equation ins
Declaring a Polynomial:

>> pol1= [1 2 4];


>> pol2= [1 4 8];

Roots of Polynomial: Division of two Polynomials

>> rt_pol1=roots (pol1) >>num=[2 5 4 6 4];

rt_pol1 = >>den=[6 66 35 2];

>> [q r]=deconv(num,den)
-1.0000 + 1.7321i
q=
-1.0000 - 1.7321i
0.3333 -2.833
Determining Coefficients from given Roots:
r=
>> c=poly(rt_1)
0 0.0000 179.3333 104.5000 9.6667
>> c=poly(rt_pol1)
Integration of Polynomial Function
c = 1.0000 2.0000 4.0000
>> pol1=[1 2 4];
Finding value of Polynomial at a given point:
>> pol2=[1 4 8];
e=polyval(pol1,2)
Multiplication of two Polynomials:
>> k=polyint(pol1)
e =12
>> g=conv(pol1,pol2) k = 0.3333 1.0000 4.0000 0
Derivative of Polynomial function:
g=
15 >> m=polyint(pol1,pol2)
>> pol1=[1 2 4];
1 6 20 32 32
m = 0.3333 1.0000 4.0000 1.0000 4.0000
>> pol2=[1 4 8]; 8.0000

>> h=polyder(pol1) j = 4 18 40 32
Additional Exercise
Determine roots of the following functions Determine value of polynomial at given instant
Exercise
1-p1=x^4 + 7x^3 = 15x^2 – 25x + 8 1-p1=x^5+2x^4-3x^3+7x^2-5x+7 at x=2

2-p2=x^2 -18x +25 2=p2=x^3-2x^2-5x+17 at x=2

Dealing with Partial Fraction expansion:


[R,P,K] = RESIDUE(B,A) finds the residues, poles and direct term of a partial fractionexpansion
of the ratio of two polynomials B(s)/A(s).
[B,A] = RESIDUE(R,P,K), with 3 input arguments and 2 output arguments, converts the partial
fraction expansion back to the polynomials with coefficients in B and A.
Example:% given a ratio of polynomials G(s) = (3s + 7)/(s^3 + 6s^2 + 11s + 6),determine the
corresponding PFE
% this is done by first defining the numerator and denominator polynomials
>> num1=[3 7];
>> den1=[1 6 11 6];
>> [r ,p, k]=residue(num1,den1) % r is the vector of PFE coefficients is the vector of roots of
den1 and k=0 if the degree of num1 < degree of den1
r=
-1.0000
-1.0000
2.0000
p=
-3.0000
-2.0000
-1.0000
k=
[]
16
Additional Exercise
Solve the following functions using PFE method
Excercise
1-f1=3/(s^3 + 3s +2)

2-f2=s + 3/s^3 + 5s + 4

PART B: Plotting in MATLAB


The primary tool we will use for plotting in MATLAB is plot().The MATLAB environment
provides a wide variety of techniques to displaydata graphically.
The type of graph you choose to create depends on the nature of your dataand what you want to
reveal about the data. You can choose from manypredefined graph types, such as line,stairs,stem,
bar, histogram, and pie graphs as wellas 3-D graphs, such as surfaces, slice planes, and
streamlines. After you create a graph, you can extract specific information about the data. You
can also edit graph components as well as annotate graphs. Annotations are the text, arrows,
callouts, and other labels added to graphsto help viewers see what is important about the
data.lastly you can print your graph on any printer connected to your computer.Annotations can
be added from the Insert menu like labels,titles,legend,line,arrows,text arrow,double arrow,text
box,rectangle,ellipse,axes,light etc.
Using Plotting Tools and MATLAB Code
Plot a Sine Wave in Continuous Time: Plot a Sine Wave in Stairs Form:

>> t = 0:0.1:20; >> t = 0:0.1:20;

>> y = sin(t); >> y = sin(t);

>>plot(t,y) >>stairs(t,y)

>>xlabel(‘t’) >>xlabel(‘t’)

>>ylabel(‘sin(t)’) >>ylabel(‘sin(t)’)

>>grid on >>grid on

>>title(‘plotting a sine wave’) >>title(‘plotting a sine wave’)

>>axis([0 20 -2 2]) >>axis([0 20 -2 2])

17
—Customization of plots
There are many commands used to customize plots by annotations, titles, axes labels, etc.
A few of the most frequently used commands are
xlabel Labels x-axis
ylabel Labels y-axis
title Puts a title on the plot
grid Adds a grid to the plot
gtext Allows positioning of text with the mouse
text Allows placing text at specified coordinates of the plot
axis Allows changing the x and y axes
figure Create a figure for plotting
figure(n) Make figure number nthe current figure
hold on Allows multiple plots to be superimposed on the same axes
hold off Release hold on current plot
close(n) Close figure number n
subplot(a,b,c) Create an a × b matrix of plots with c the current figure
orient Specify orientation of a figure

Procedure:
Titles & Labels:-
To put a title and label the axes, we use
>>title (’text’)
>>xlabel (’text’)
>>ylabel (’text’)
The strings enclosed in single quotes, can be anything of ourChoosing
Grids:-
A dotted grid may be added by
>>grid
Line Styles &Colors:-
Various line types, plot symbols, and colous may be obtained with plot(x,y,s) where s is a
character string made from one element from any or all the following 3 columns:

b blue . point - solid

c cyan o circle : dotted

g green x x-mark -. dashdot

k black + plus -- dashed

m magenta * star

r red s square

w white d diamond
18
y yellow v triangle (down)

^ triangle (up)

< triangle (left)

➢ triangle (right)

p pentagram

h hexagram

For example, plot (X,Y, ‘g:’) plots a green dotted line and plot(X,Y,’rd’) plots red diamond at
each data point. You may also edit colors and line styles directly from the menus which appear at
the top of the figure windowThe default is to plot solid lines. A solid white line isproduced by
>>plot (x, y, ’w-’)
The third argument is a string whose first character specifies the colour (optional) and the second
the line style.

Multi–plots:-
Several graphs can be drawn on the same figure as:
>>plot (x, y, ’w-’, x, cos (2*pi*x), ’g--’)
A descriptive legend may be included with
>>legend (’Sin curve’, ’Cos curve’)
Which will give a list of line–styles, as they appeared in the plot command, followed by a brief
description.MATLABfitsthe legend in a suitable position, so as not to conceal the graphs
whenever possible. For further information do help plot etc. The result of the commands
>>plot (x, y, ’w-’, x, cos (2*pi*x), ’g--’)
>>legend (’Sin curve’, ’Cos curve’)
>>title (’Multi-plot ’)
>>xlabel (’x axis’), ylabel (’y axis’)
>>grid
Hold:-
A call to plot clears the graphics window before plotting the current graph. This is not
convenient if we wish to addfurther graphics to the figure at some later stage. To stop the
window being cleared:
>>plot (x, y, ’w-’), hold
>>plot (x, y, ’gx’), hold off
“hold on” holds the current picture; “hold off” releases it (but does not clear the window, which
can be done with clf). “hold” on its own toggles the hold state.

Subplot:-

19
The graphics window may be split into an m × n array of smaller windows into which we may
plot one or more graphs. The windows are counted 1 to mn row–wise, starting from the top left.
Both hold and grid work on the current subplot.
>>subplot (221), plot (x,y)
>>xlabel (’x’), ylabel (’sin 3 pi x’)
>>subplot (222), plot (x, cos (3*pi*x))
>>xlabel (’x’), ylabel (’cos 3 pi x’)
>>subplot (223), plot (x, sin (6*pi*x))
>>xlabel (’x’), ylabel (’sin 6 pi x’)
>>subplot (224), plot (x, cos (6*pi*x))
>>xlabel (’x’), ylabel (’cos 6 pi x’)
subplot(221) (or subplot(2,2,1)) specifies that the window should be split into a 2 × 2 array and
we select the first subwindow.

Controlling Axes:-
If it is desired to plot a curve in a region specified by r = [x-min x-max y-min y-max]. Enter the
command axis(r). This command sets the scaling to the prescribed limits. Find-out more about
the command “axis” by typing:

help axis

If you wish to plot cos(t) of exercise 5 from time 0 to 10 seconds, and if you wish that the y-axis
should be from –2 to 2, then enter the following command:

axis([0 10 -2 2])Once a plot has been created in the graphics window you may wish to change
the range of x and y values shown on the picture
Property Editor
20
Figure properties can be changed interactively using thefollowing commands:
• PlotEdit
- allows interactive changes to plots (add legend, lines, arrows, etc.)
• PropEdit
- Allows changes to all Handle Graphic properties in a MATLAB plot

Examples in Plotting
Example: Draw graphs of the functions
i. y = sin(x)/x
ii. u= (1/(x-1)2)+x
iii. v= (x2+1)/(x2-4)
iv. ((10-x)1/3-1)/(4 - x2)1/2

PART C: Solving ordinary differential equations (ODE) symbolically


MATLAB has a command dsolve that solves ordinary differential equations (ODEs)
symbolically.One form of the dsolve command is
dsolve(‘ODE’,’initial conditions’)
In the ODE string,D is used to represent the first derivative and Dn represents the nth derivative.
Example
To solve the differential equation y’(t) = ay(t) subject to the initial conditions y(0)=c and assign
the solution to y,one give the commands
Additional Exercise
>>syms a c Solve the following ODE symbolically
Exercise
>> y=dsolve('Dy=a*y','y(0)=c') 1-x”(t)+9x(t)=0 at x(0)=3 & x’(0) = 0

y= 2-y”(t) =-9y(t) at y(0) =1 & y’(0) = 0

c*exp(a*t) Y”(t) = -2y’(t) – y(t) at y(0) = 1 & y’(0) = 0

Conclusion:

21
Experiment 4
Generating Signals using MATLAB
Exercise Objective:
To generate signals using MATLAB and visualize the characteristics of signals by changing
parameters

Requirements:
➢ Intel based computer
➢ MATLAB

Theory:

The MATLAB signal processing toolbox has a large variety of functions for generating
signals, most of which require that we begin with a vector representation of time t to n. To
generate a vector t of time values with a sampling interval t of 1 ms on the interval from 0 to
1s, for example, we use the command:
T = 0: .001:1;

Procedure:
PERIODIC SIGNALS
It is an easy matter to generate periodic signals such as square waves and triangular waves using
MATLAB. Consider first the generation of a square wave of amplitude A, fundamental frequency w0
{measured in radians per second), and duty cycle rho. That is, rho is the fraction of each period for
which the signal is positive. To generate such a signal, we use the basic command:

A*square (w0*t + rho);

22
In the second command, pi is a built-in MATLAB function that returns the floating-point number closest
to . The last command is used to view the square wave. The command p lot draws lines connecting the
successive values of the signal and thus gives the appearance of a continuous-time signal.

Consider next the generation of a triangular wave of amplitude A, fundamental frequency wо (measured
in radians per second), and width w. Let the period of the triangular wave be T, with the first maximum
value occurring at t = W T. The basic command for generating this second periodic signal is

A*sawtooth (w0*t + W);

Thus to generate the symmetric triangular wave shown in Fig. above, we used the following commands:

Figure: The triangular wave

The toolbox provides functions for generating widely used periodic waveforms:
•sawtooth generates a sawtooth wave with peaks at ±1 and a period of 2p. An optional width
parameter specifies a fractional multiple of 2p at which the signal’s maximum occurs.
•square generates a square wave with a period of 2p. An optional parameter specifies duty cycle,
the percent of the period for which the signal is positive.
To generate 1.5 seconds of a 50 Hz sawtooth wave with a sample rate of 10 kHz and plot 0.2
seconds of the generated waveform, use
Fs = 10000;
t = 0:1/Fs:1.5;
x = sawtooth(2*pi*50*t);
plot(t,x), axis([0 0.2 –1 1])
DISCRETE PERIODIC SIGNALS

As mentioned previously, a signal generated on MATLAB is inherently of a discrete- time nature. To


visualize a discrete-time signal, we may use the stem command. Specifically, stem (n, x) depicts the data
contained in vector x as a discrete-time signal at the time values defined by n. The vectors n arid x must,
of course, have compatible dimensions.

Consider, for example, the discrete-time square wave shown in Fig. above

23
Figure: The discrete-time square wave

EXPONENTIAL SIGNALS

Moving on to exponential signals, we have decaying exponentials and growing exponentials. The
MATLAB command for generating a decaying exponential is

8*exp(-a * t);

To generate a growing exponential, we use the command

8*exp(a* t);

In both cases, the exponential parameter a is positive.

Figure: The decaying exponential signal

DISCRETE EXPONENTIAL SIGNALS

24
Consider next the discrete-time exponential sequence. The growing form of this exponential is
shown in Fig below

Figure: The discrete growing exponential signal

SINUSOIDAL SIGNALS
MATLAB also contains trigonometric functions that can be used to generate sinusoidal signals. A cosine
signal of amplitude A, frequency w0 (measured in radians per second), and phase angle p h i (in radians)
is obtained by using the command

A*cos(w0*t + phi);

Alternatively, we may use the sine function to generate a sinusoidal signal by using the command

A*sin (w0*t + phi);

These two commands were used as the basis of generating the sinusoidal signals.

25
Figure 2: The cosine signal

DISCRETE SINUSOIDAL SIGNALS


Consider next the discrete-time sinusoidal signal. This periodic signal is plotted in Fig below

Figure : The discrete-time sinusoidal signal

Elementary signals
Unit impulse, unit step and ramp functions
Most of the theory presented in the Signals & Systems course examines the behavior of
continuous-time signals and systems. MATLAB can use special, so-called symbolic variables to
represent and manipulate continuous signals and systems (another software package called
Mathematica has much more developed symbolic capabilities). When doing non-symbolic
manipulations however MATLAB is limited to use discretized versions on signals. Using the
vector notation and the plotting commands we introduced it is now easy to create and visualize
signals. In fact we have already done that when we created sines and cosines for our plotting
examples. Now we will write two simple functions to generate the unit step and ramp signals.
The unit step function is defined as:
us[t] =
26
_
1; t _ 0
0; t < 0
function y = us(t)
%US Unit step
% y = us(t)
% t: time index
% y: signal
y = (t >= 0);
And the unit ramp function is defined as:
ur[t] =
_
t; t _ 0
0; t < 0
Since MATLAB is a programming language, an endless variety of different signals is possible.
Here are some statements that generate several commonly used sequences, including the unit
impulse, unit step, and unit ramp functions:
t = (0:0.001:1)';
y = [1; zeros(99,1)]; % impulse
y = ones(100,1); % step (filter assumes 0 initial cond.)
y = t; % ramp
y = t.^2;
y = square(4*t);
All of these sequences are column vectors – the last three inherit their shapes from t.
Now it is easy to create other signals using the functions we just wrote. For example:
>> t = -5:0.001:5;
>> y = us(-t+2) .* ur(t);
>>plot(t,y)
>>grid on
>>axis([-5 5 -.5 2.5])
>>set(gcf,'paperunits','centimeters');
>> exportfig(gcf,'elem1.eps','bounds','tight','width',8.5,'linestylemap','bw');

Conclusion:
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………

27
Experiment 5
Generating Signals using Simulink
Exercise Objective:
To generate signals using MATLAB simulink.

Requirement:

• Intel based computer


• MATLAB
Theory:

Simulink is a software package that enables you to model, simulate, and analyze system whose outputs
change over time. Such systems are often referred to as dynamic systems. Simulink can be used to
explore the behavior of a wide range of real-world dynamic systems, including electrical circuits, shock
absorbers, braking systems, and many other electrical, mechanical, and thermodynamic systems

Procedure:
Starting simulink:

To start Simulink, you must first start MATLAB. Consult your MATLAB documentation for more
information. You can then start Simulink in two ways: Click the Simulink icon on the MATLAB toolbar.
Enter the simulink command at the MATLAB prompt. On Microsoft Windows platforms, starting
Simulink displays the Simulink Library Browser.

28
Figure 5.1: The Simulink library browser

Using the simulink toolbar to enter commands:

Model windows in the Windows version of Simulink optionally display a toolbar beneath the Simulink
menu bar. To display the toolbar, select the Toolbar option on the Simulink View menu.

Figure 5.2 : Model window

The toolbar contains buttons corresponding to frequently used Simulink commands, such as those for
opening, running, and closing models. You can run such commands by clicking the corresponding button.
For example, to open a Simulink model, click the button containing the open folder icon. You can
determine which command a button executes by moving the mouse pointer over the button. A small
window appears containing text that describes the button. The window is called a tooltip. Each button on
the toolbar displays a tooltip when the mouse pointer hovers over it. You can hide the toolbar by clearing
the Toolbar option on the Simulink View menu.

29
Generating a Sine Wave

To create this model, you need to copy blocks into the model from the following Simulink block
libraries.

• Sources library (the Sine Wave block)


• Sinks library (the Scope block)
Now drag the Sine Wave block from the browser and drop it in the model window. Simulink creates a
copy of the Sine Wave block at the point where you dropped the node icon.

Figure 5.3 : Sine wave model window

On the dialog box that appears, notice that the Stop time is set to 10.0 (its default value), changes it’s into
inf.

5.4: Simulation parameters

30
First, set the simulation parameters by choosing Simulation Parameters from the Simulation menu. Set
simulation stop time to INF. Now, open the Scope block to view the simulation output. Keeping the
Scope window open, set up Simulink to run the simulation for infinite seconds

Figure 5.5: Simulink scope graph

Conclusion:
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………

31
Experiment 6
Discrete time signals in time-domain
Exercise Objective:
To study generation of basic discrete time signals.
Time shifting, reversal and scaling processes on the signals.

Requirement:

• Intel based computer


• MATLAB
Theory:

Generation of Sequences:-
The purpose of this section is to familiarize you with the basic commands in MATLAB for
signal generation and for plotting the generated signal. MATLAB has been designed to operate
on data stored as vectors or matrices. For our purposes, sequences will be stored as vectors.
Therefore, all signals are limited to being causal and of finite length. The steps to follow to
execute the programs listed in this book depend on the platform being used to run the MATLAB

Unit Sample and Unit Step Sequences:-


Two basic discrete-time sequences are the unit sample sequence and the unit step sequence
denoted by the followingequations.

A unit sample sequence u[n] of length N can be generated using the following MATLAB
command
u = [1 zeros(1, N -1)];
A unit sample sequence ud[n] of length N and delayed by M samples, where M < N, can be
generated using the MATLAB command
ud=[zeros(1,M) 1 zeros(1,N-M-1) ];

Likewise, a unit step sequence s[n] of length N can be generated using the MATLAB command
s = [ones(1, N)];
A delayed unit step sequence can be generated in a manner similar to that used in the generation
of a delayed unit sample sequence.

Program P1_1 can be used to generate and plot a unit samplesequence.


32
% Generation of a Unit Sample Sequence
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit sample sequence
u = [zeros(1,10) 1 zeros(1,20)];
% Plot the unit sample sequence
stem(n, u);
xlabel(' Time index n ');
ylabel(' Amplitude ');
title(' Unit Sample Sequence ');
axis([-10 20 0 1.2]);

Exponential Signals:-
Another basic discrete-time sequence is the exponential sequence. Such a sequence can be
generated using the MATLAB operators (. ^ and exp).
Program P1_2 given below can be employed to generate a complex-valued exponential
sequence.
% Program P1_2
% Generation of a complex exponential sequence
clf; (clear figure)
c = -(1/12)+(pi/6)*i;
K = 2;
n = 0:40;
x = K*exp(c*n);
subplot(2,1,1);
stem(n, real(x));
xlabel('Time index n');
ylabel ('Amplitude');
title('Real part');
subplot (2,1,2);
stem(n, imag(x));
xlabel('Time index n');
ylabel('Amplitude');
title('Imaginary part');
Program P1_3 given below can be employed to generate a
real-valued exponential sequence.
% Program P1_3
% Program P1_3
% Generation of a real exponential sequence

clf;

n = 0:35; a = 1.2; K = 0.2;


x = K*a.^+n;
stem(n, x);
33
xlabel('Time index n');
ylabel('Amplitude');

Sinusoidal Sequences:-
Another very useful class of discrete-time signals is the real sinusoidal sequence. The real
sinusoidal sequence with constant amplitude is of the form,

where A, ωo, and φ are real numbers. The parameters A, ωo, and φ are called, respectively, the
amplitude, the angular frequency, and the initial phase of the sinusoidal sequence
x[n]. fo = ωo/2π is the frequency.
Such sinusoidal sequences can be generated in MATLAB using the trigonometric operators (cos
and sin).
Program P1_4 is a simple example that generates a sinusoidal signal.
% Program P1_4
% Generation of a sinusoidal sequence
n = 0:40;
f = 0.1;
phase = 0;
A = 1.5;

arg = 2*pi*f*n - phase;

x = A*cos(arg);

clf; % Clear old graph


stem(n,x); % Plot the generated sequence
axis([0 40 -2 2]);
grid;
title('Sinusoidal Sequence');
xlabel('Time index n');
ylabel('Amplitude');
axis;

Random Signals:-
A random signal of length N with samples uniformly distributed in the interval (0, 1) can be
generated by using the MATLAB command
x = rand (1, N);
Likewise, a random signal x[n] of length N with samples normally distributed with zero mean
and unity variance can be generated by using the following MATLAB command
x = randn (1, N);

34
Exercise 1: Consider the following discrete time sinusoid:

y[n] = sin(0.1n)
Where n is an integer.

a. Plot this signal for 0n22 seconds. Estimate the time period of the signal.

b. Repeat (a) for z[n] = sin(0.3n).

What is the difference between y[n] and z[n]?


SOLUTION (A):

n = 0:1/3:22;
y = sin(0.1*pi* n);
stem(n,y)
Ylabel('y = sin(0.1*pi*n)');
Xlabel('n');
z = sin(0.3*pi*n);
figure(2)
stem(n,z)
Ylabel('z= sin(0.3*pi*n)');
Xlabel('n');
figure(3)
plot(n,y,n,z)
Xlabel('y = blue signal & z = Green signal')

35
Exercise 2: A discrete time signal x[n] is defined as:
x[n]= [1 1 1 1 1/2 1/2]
Sketch the following:
a. x[n]
n = -1:1:4;
x = [1 1 1 1 1/2 1/2];
subplot(1,2,1)
plot(n,x)
36
axis([-2 5 -2 2])
subplot(1,2,2)
stem(n,x)
axis([-2 5 -2 2])

37
b. x[n-2]
n = -1:1:4;
x = [1 1 1 1 1/2 1/2];
subplot(1,2,1)
plot(n-2,x)
axis([-4 5 -2 2])
subplot(1,2,2)
stem(n-2,x)
axis([-4 5 -2 2])

38
c. x[n+2]
n = -1:1:4;
x = [1 1 1 1 1/2 1/2];
subplot(1,2,1)
plot(n+2,x)
axis([-2 7 -2 2])
subplot(1,2,2)
stem(n+2,x)
axis([-2 7 -2 2])

d. x[n2]
n = -1:1:4;
x = [1 1 1 1 1/2 1/2];
subplot(1,2,1)
plot(power(n,2),x)
axis([-2 20 -2 2])
subplot(1,2,2)
stem(power(n,2),x)
axis([-2 20 -2 2])

39
Conclusion:-
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………

40
Experiment 7
Convolution of Continuous time signals
Exercise Objective:
To Plot convolution result using MATLAB and analyze the results.

Requirement:
• Intel based computer
• MATLAB

Theory:

The convolution of two functions is the overlap of the two functions as one function is passed
over the second. The convolution symbol is . The convolution of h (t) and g (t) is defined
mathematically as

The above equation is depicted for rectangular shaped h(t) and g(t)functions in this animation.

Procedure:
CONV
Convolution and polynomial multiplication
Syntax

41
w = conv(u,v)
Description
w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the same operation as
multiplying the polynomials whose coefficients are the elements of u and v
It is an easy matter to generate convolution signals such as square waves and triangular waves
using MATLAB. Consider first the generation of a square wave fundamental frequency 4 pi
(measured in radians per second).

Figure 7.1: The square wave z (t)

Figure 7.2: The square wave y (t)


now convolve the two signals

42
Figure 7.3: Convolution result a (t)

Conclusion:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………

43
Experiment 8
Convolution of Discrete time signals
Exercise Objective:
To study basics of convolution in discrete time signals.
Generation of convolved signal by the convolution of discrete signals.
In this lab you will learn
Convolution Background & Concepts
Discrete Convolution methodologies
Theconv Command
Structures

Theory:
Convolution is denoted by: y[n] = x[n] * h[n]..
First, we set up two signals x[k] and h[k]:

Flip one of the signals, say h[k], to form h[-k]

44
Shift h[-k] by n to form h[n-k]. For each value of n, form y [n] by multiplying and summing all
the element of the product of x [k]h[n-k],Starting, from - ∞ to + ∞, first partial overlap then
complete overlap and then end at no overlap.
The figure below shows an example of the calculation of y[1]. The top panel shows x[k]. The
middle panel shows h[1-k].The lower panel shows x[k]y[1-k]. Note that this is a sequence on a k
axis. The sum of the lower sequence over all k gives y[1]=2
Length of Convolution Sum = length of x[n] + length of h[n] – 1
Starting index of Convolution Sum = Starting index of x[n] + Starting index of h[n]
Ending index of Convolution Su
m = Ending index of x[n] + Ending index of h[n]

45
We repeat this shifting, multiplication and summing for all values of n to get the complete
sequence y[n]:

46
An easy approach to convolve the above signals is the polynomial multiplication. Since x[n] and
h[n] in the above example are finite sequences then we can use polynomial
multiplication as follows.
Length of Convolution Sum = length of x[n] + length of h[n]
–1
= 5 + 3 –1 = 7

Starting index of Convolution Sum = Starting index of x[n] + Starting index of h[n]
=0+0=0
Ending index of Convolution Sum = Ending index of x[n] + Ending index of h[n]
=4+2=6

MATLAB Commands:-
conv(a,b) performs a 1-D convolution of vectors a and b. The result is a vector with length =
length(a) + length(b) -1.
Imagine vector a as being stationary and the flipped version of b is slid from left to right. Note
that conv(a,b) = conv(b,a).
%Filename: example.m
%This m-file convolves two signals and plots the result
47
x = [0.5 0.5 0.5]; %define input signal x[n]
h = [3.0 2.0 1.0]; %unit-pulse response h[n]
y = conv(x,h); %compute output y[n] via convolution
n = 0:(length(y)-1); %for plotting y[n]
stem(n,y); % plot y[n]
grid;
xlabel('n');
ylabel('y[n]');
title('Output of System via Convolution');

Conclusion:-
………………………………………………………………………………………………………………
………………………………………………………………………………………………………………
………………

48
Experiment 9
Impulse Response of a Discrete Time System
Exercise Objective:

• Calculation of Delayed signal


• Determining the impulse response of a system.

Requirement:

➢ Intel based computer


➢ MATLAB
Theory:-
Impulse:-
The impulse is denoted δ [n] and defined by

Graphically impulse can be represented as:

Impulse Response:-
The impulse response of a system is its output when an impulse is applied at input of system

For delayed impulse

49
If we know the impulse response of a discrete system we can readily implement the system in a
simple way. To understand this, observe that any sampled signal is impulses whose amplitudes
are amplitudes of the original analogue signal. Thus if the input signal is just a series of impulses
and we know what the system does to impulses and we know the system obeys the principle of
superposition then we can calculate the output of the system to any input signal. We do
this by shifting an impulse response at each input sample scaled according to the amplitude of
the sample. The sum of the overlapping triggered scaled impulse responses is theoutput signal.
Mathematically this is called convolution.
Time Delay:-
A system is delayed in time if the system occurs at t = 1instead of t =0. Practically if an output
appears at t = 0 but we pass it through a delay block then it will appear at t =1.
Mathematically the delay is shifting in time.

Figure 2 represent the delay in a time. Consider a signal x[n] is passed through a delay box Delay
box will shifts the x[n].
Figure 2 represents the single delay of x[n].

Calculation of Impulse response in MATLAB:-

Consider a system

50
Consider a system shown in figure 3. This system is dividedinto two parts.
One part delays the input twice and amplifies the signal by the factor of 6.
Second part first delays the input by one and thenamplifies it by factor of 7.
MATLAB code
x=[1 zeros(1,10)]; %Input
D=[0 1]; %Unit Delay
% System 1
x1=conv(x,D);
x2=conv(x1,D);
y1=x2*6
% System 2
x3=conv(x,D);
y2=x3*7
%%% Final Output
y2=[y2 zeros(1,length(y1)-length(y2))];
y1=[y1 zeros(1,length(y2)-length(y1))];
y=y1+y2;
subplot(411)%%%% Plot Input
n=0:(length(x)-1);
stem(n,x);
axis([-1 10 0 max(x)]);
title('Input x');
subplot(412)%%% Plot First Output
n=0:(length(y1)-1);

stem(n,y1);
axis([-1 10 0 max(y1)]);
title('First Output y1');
subplot(413)%%% Plot Second Output
n=0:(length(y2)-1);
stem(n,y2);
axis([-1 10 0 max(y2)]);
title('Second Output y2');
subplot(414)%%% Plot Final Output

51
n=0:(length(y)-1);
stem(n,y);
axis([-1 10 0 max(y)]);
title('Final Output y')
The calculation of Impulse response involve following
steps.
1: Initially we will apply an impulse at the input if system and then observe the output. Figure 4
represent an impulse at input.

System 1 shifts the impulse at t = 2 and then increase the amplitude by 7. Figure 5 represents the
output of system 1

System 1 shifts the impulse at t = 1 and then increase the amplitude by 6. Figure 6 represents the
output of system 2.

52
The Sum of the outputs of system 1 and system 2 gives the final output, which is the over all
system impulse response i.e.
y = [0 7 6]
Figure 7 represents the impulse response of the system.

Now, once we have impulse response then for any input we can calculate output using
convolution sum:
y[n] = x[n]*h[n]

Conclusion:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………

53
Experiment 10
Frequency Response of a Discrete Time System
Exercise Objective:

The tasks given in the lab include,

• The frequency response of the signal.


• Plot the magnitude and phase of the system.
• Plot the real and imaginary parts of the system function by using
coefficients..
• Observe the time shifting property of DTFT.

Requirement:

➢ Intel based computer


➢ MATLAB
Theory:-

Frequency Response:

The frequency response is a representation of the system's response to sinusoidal inputs at


varying frequencies. The output of a linear system to a sinusoidal input is a sinusoid of the same
frequency but with a different magnitude and phase. Any linear system can be completely
described by how it changes the amplitude and phase of cosine waves passing through it. This
information is called the system's frequency response.Since both the impulse response and the
frequency response contain complete information about the system, there must be a one-to-one
correspondence between the two. Given one, you can calculate the other.The relationship
between the impulse response and the frequency response is one of the foundations of signal
processing:A system's frequency response is the Fourier Transform of its impulse response
Sinceh [ ] is the common symbol for the impulse response, H [ ] is used for the frequency
response.

Discrete Time Fourier Transform:

The discrete-time Fourier transform (DTFT) X(ejω) of a sequence x[n] is defined

54
In general X(ejω) is a complex function of the real variable ω and can be written as

whereXre(ejω) and Xim(ejω) are, respectively, the real and imaginary parts of X(ejω), and are
real functions of ω. X(ejω) can alternately be expressed in the form

The quantity |X(ejω)| is called the magnitude function and the quantity θ(ω) is called the phase
functionIn many applications, the Fourier transform is called the Fourier spectrum and, likewise,
|X(ejω)| and θ(ω) are referred to as the magnitude spectrum and phase spectrum,
respectively.The DTFT X(ejω) is a periodic continuous function in ω with a period 2π. The
DTFT satisfies a number of useful properties that are often uitilized in a number of applications.

MATLAB COMMANDS:

Procedure:
For complex Z, the magnitude R and phase angle theta are given by:
R = abs (Z)
Theta = angle (Z)
Y = fft(X) returns the discrete Fourier transform of vector X, computed with a fast Fourier
transform (FFT) algorithm.
Y = fft(X)
Y = fft(X,n) returns the n-point FFT.
Y = fft(X, n)

Question No 01:

Compute the discrete Fourier transform of the following function analytically and Then plot the
magnitude and phase:

Its DTFT is given as:

55
MATLAB Code:

w = [0:500]*pi/500;
z = exp(-j*w);
x = 3*(1-0.9*z).^(-1);
a = abs(x);
b = angle(x)*180/pi;
subplot(2,1,1);
plot(w/pi,a);
subplot(2,1,2);
plot(w/pi,b);

OUTPUT:

Question #2: Evaluate the DTFT of the given coefficients.

num=[2 1]

den=[1 –0.6]

• Plot real and imaginary parts of Fourier spectrum.


• Also plot the magnitude and phase spectrum.

56
MATLAB CODE:

% Evaluation of the DTFT


clc;
% Compute the frequency samples of the DTFT
w = -4*pi:8*pi/511:4*pi;
num = [2 1];
den = [1 -0.6];
h = freqz(num, den, w);
% Plot the DTFT
subplot(2,2,1)
plot(w/pi,real(h));
grid on;
title('Real part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,2,2)
plot(w/pi,imag(h));
grid on;
title('Imaginary part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,2,3)
plot(w/pi,abs(h));
grid on;
title('Magnitude Spectrum |H(e^{j\omega})|')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,2,4)
plot(w/pi,angle(h));
grid on;
title('Phase Spectrum arg[H(e^{j\omega})]')
xlabel('\omega /\pi');
ylabel('Phase, radians');
OUTPUT

57
Fast Fourier Transform:
The Fast Fourier Transform (FFT) is just a computationally fast way to calculate the DFT.
Question No 03:
Determine the Fourier transform of the following sequence. Use the FFT (Fast Fourier
Transform) function.
x (n) = {4 6 2 1 7 4 8}
MATLAB Code:
n = 0:6;
x = [4 6 2 1 7 4 8];
a = fft(x);
mag = abs(a);
pha = angle(a);
subplot(2,1,1);
plot(mag);
grid on
title('Magnitude Response');
subplot(2,1,2);
plot(pha);
grid on
title('phase Response');
OUTPUT:

58
Time-shifting property of DTFT:
If ‘x[n]’ be the sequence ,and X(ejw) be its fourier transform then,

x[n]----F-----X(ejw)

then, for the time-shifted sequences, a simple transformation of the index of summation
in the discrete-time Fourier transform yields

x[n-nd]----F-----e-jwndX(ejw)

Question#04: Observe the time-shifting property of DTFT.

• Plot and compare the magnitude spectrum of the original input with time delayed input.
• Plot and compare the phase spectrum of the original input with delayed input.

MATLAB CODE:

% Time-Shifting Properties of DTFT


clc;
w = -pi:2*pi/255:pi;
D = 10;
num = [1 2 3 4 5 6 7 8 9];
h1 = freqz(num, 1, w);
h2 = freqz([zeros(1,D) num], 1, w);
subplot(2,2,1)
plot(w/pi,abs(h1));
grid on;
title('Magnitude Spectrum of Original Sequence')
subplot(2,2,2)
plot(w/pi,abs(h2));
grid on;
title('Magnitude Spectrum of Time-Shifted Sequence')
subplot(2,2,3)
plot(w/pi,angle(h1));
grid on;
title('Phase Spectrum of Original Sequence')
subplot(2,2,4)
plot(w/pi,angle(h2));
grid on;
title('Phase Spectrum of Time-Shifted Sequence')

59
Frequency-shifting property of the DTFT:
Question#05: Observe the frequency shifting property of DTFT.

• Plot and compare the magnitude spectrum of the original input with frequency shifted
input.
• Plot and compare the phase spectrum of the original input with frequency shifted input..

MATLAB CODE:

% Frequency-Shifting Properties of DTFT


clc;
w = -pi:2*pi/255:pi;
wo = 0.4*pi;
num1 = [1 3 5 7 9 11 13 15 17];
L = length(num1);
h1 = freqz(num1, 1, w);
n = 0:L-1;
num2 = exp(wo*i*n).*num1;
h2 = freqz(num2, 1, w);

60
subplot(2,2,1)
plot(w/pi,abs(h1));
grid on;
title('Magnitude Spectrum of Original Sequence')
subplot(2,2,2)
plot(w/pi,abs(h2));
grid on;
title('Magnitude Spectrum of Frequency-Shifted Sequence')
subplot(2,2,3)
plot(w/pi,angle(h1));
grid on;
title('Phase Spectrum of Original Sequence')
subplot(2,2,4)
plot(w/pi,angle(h2));
grid on;
title('Phase Spectrum of Frequency-Shifted Sequence')

OUTPUT

61
LAB EXERCISES:
1. Determine the Fourier transform of the following sequence. Use the FFT (Fast Fourier
Transform) function,
x(n) = {4 3 2 1 1 2 3 4}

2. Compute the discrete Fourier transform of the following function analytically and then
Plot the magnitude and phase
x(n) = 2(0.8)n+2 u(n-2)

3. Determine H(w) and plot its magnitude and phase for the following system.

Y(n) = 2x(n) + x(n-1) – 0.25y(n-1) + 0.25y(n-2)

4. Given below is the frequency response of the system,

H(ejw) = 1+e-jw
1-e-jw+0.9e-j2w

a) Write a MATLAB code that manually implements the above system.


b) Compare with the spectrum obtained from freqz command
• Plot the magnitude and frequency spectrum.
• Also plot real and imaginary plots

Conclusion:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
…………………………

62
Experiment 11
Properties Linear Time-Invariant Discrete-Time
Systems
Exercise Objective:

Study the Commutative, Associative and Distributive


properties of LTI system.
Prove the Commutative, Associative and Distributive
properties of LTI system.

Requirement:

➢ Intel based computer


➢ MATLAB

Theory:
Commutative Property: [Book section 2.3.1]:-
The commutative property in discrete time is given by

This equation can be verified in a straightforward manner by means of a substitution of variable


in the following equation

When we are convolving the roles of x[n] and h[n] are interchangeable. According to above
equation, the output of an LTI system with input x[n] and unit impulse response h[n]is identical
to the output of an LTI system with input h[n] and unit impulse response x[n].
We want to calculate convolution of two signals e.g. x[n]=[1 2
3 4 5] (n=0:4) and h[n]=[-1 0 1] (n=-1:1).
First flip h[n] and shift h[-k] from –1 to 5 and compute the output (as shown in figure 1).

63
Now flip x[n] and shiftx[-n] from -1 to 5 and compute convolution sum. The output should be
same as found above (as in figure 2).

64
Distributive Property: [Book section 2.3.2]:-
Another property of convolution is the distributive property
x[n]*(h1[n] + h2[n]) = x[n]* h1[n] + x[n]*h2[n] = y1[n]+
y2[n]
This can be verified as

65
Therefore, the above two systems are equivalent. The convolved sum of two impulse responses
is equivalent to considering the two equivalent parallel systems (equivalent for discrete-time
systems)

Associative Property [Book section 2.3.3]:-


Another property of (LTI) convolution is that it is associative
x[n]*(h1[n]*h2[n]) = (x[n]*h1[n])*h2[n]

Practically when we are calculating the overall system response sequence of blocks connected in
series does not effect on system output.

Example:-
Consider two signals
>>x=[1 2 3 4]; h1=[2 1 0 1];
First compute

>> y1=conv(x,h1)
y1 =
2 5 8 12 6 3 4

Exercise:-
In MATLAB when we are using conv(a,b) if ‘a’ and ‘b’ are interchanged then because of
Commutative property outputwill not change.
For the following signals
x[n] = [-1.5 0 1.5 0 -1.5 0 1.5]
h1[n] = [1 0 0 1 1 ]
h2[n] = [-2 -1 0 1 2 3 ]
Prove
a. Commutative Property
x[n] * h2 [n] = h2 [n] * x[n]
b. Distributive Property
66
x[n]*(h1[n] + h2[n]) = x[n]* h1[n]+ x[n]* h2[n]
c. Associative Property
x[ n ] * ( h1[ n ] * h2[ n ]) = (x[ n ] * h1[ n ]) * h2[ n ]

Conclusion:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………

67
Experiment 12
Simulating different types of Modulation using MATLAB
Exercise Objective:

To simulate different type of modulation using MATLAB

Requirement:

➢ Intel based computer


➢ MATLAB
Theory:

Amplitude modulation (AM) is a method of impressing data onto an alternating-current (AC)


carrier waveform. The highest frequency of the modulating data is normally less than 10 percent
of the carrier frequency. The instantaneous amplitude (overall signal power) varies depending on
the instantaneous amplitude of the modulating data.

In AM, the carrier itself does not fluctuate in amplitude. Instead, the modulating data appears in
the form of signal components at frequencies slightly higher and lower than that of the carrier.
These components are called sidebands. The lower sideband (LSB) appears at frequencies below
the carrier frequency; the upper sideband (USB) appears at frequencies above the carrier
frequency. The LSB and USB are essentially "mirror images" of each other in a graph of signal
amplitude versus frequency, as shown in the illustration. The sideband power accounts for the
variations in the overall amplitude of the signal.

When a carrier is amplitude-modulated with a pure sine wave, up to 1/3 (33 percent) of the
overall signal power is contained in the sidebands. The other 2/3 of the signal power is contained
in the carrier, which does not contribute to the transfer of data. With a complex modulating
68
signal such as voice, video, or music, the sidebands generally contain 20 to 25 percent of the
overall signal power; thus the carrier consumes 75 to 80 percent of the power. This makes AM
an inefficient mode. If an attempt is made to increase the modulating data input amplitude
beyond these limits, the signal will become distorted, and will occupy a much greater bandwidth
than it should. This is called over modulation, and can result in interference to signals on nearby
frequencies.

Procedure:
AMPLITUDE MODULATION USING M-FILE
Y = MODULATE(X,Fc,Fs,METHOD,OPT) modulates the message signal X with a Carrier
frequency Fc and sampling frequency Fs, using the modulation scheme in METHOD.OPT is an
extra sometimes optional parameter whose purpose depends on the modulation scheme you
choose.
Fs must satisfy Fs> 2*Fc + BW, where BW is the bandwidth of the modulated signal.

FREQUENCY MODULATION USING SIMULINK


To create this model, you need to copy blocks into the model from the following
communication blockset libraries.

• Comm Sources library (the Random-Integer Generator)


• Modulation library (the FM Modulator Baseband)
• Comm Sinks (Discrete Time Eye Diagram Scope)
Now drag the Random-Integer Generator block, FM Modulator Baseband and Discrete Time
Eye Diagram Scope from the browser and drop it in the model window. Simulink creates a
copy of the Random-Integer Generator block at the point where you dropped the node icon.

69
Now run a simulation by clicking play button, you will see the following window.

Conclusion:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
…………………………

70
Experiment 13
Laplace transforms using MATLAB
Exercise Objective:

To plot and analyze Laplace transforms using MATLAB

Requirement:

➢ Intel based computer


➢ MATLAB
Theory:

The MATLAB control system toolbox contains numerous command that are useful for working
with Laplace transforms and continuous-time LTI systems described in terms of transfer
functions, poles zeros, or state-variable description.

Procedure:
POLES AND ZEROS
The command
r = roots (a)
Finds the roots of a polynomial described by the vector a and thus may be used to determine the
zeros and poles of a Laplace transform expressed as a ratio of polynomials in s. The element of
the vector a correspond to descending powers of s.
For example
Using the command
>> z = roots( [4, 0, 6] );
>> p = roots( [1, 1, 0, -2] );

PARTIAL FRACTION EXPANSIONS


The residue command finds the partial fraction expansion for a ratio of two polynomials. The
syntax is [r, p, k] = residue(b, a), where b represents the numerator polynomial, a represents the
denominator polynomial, r represents the partial fraction expansion coefficient or residues, p
represents the poles , and k is a vector describing any terms in powers of s. If the numerator
order is less then the denominators order.
To illustrate this command, we find the partial fraction expansion for the Laplace transform
consider in this example

71
Using this commands

>> [r, p, k] = residue ([3, 4], [1, 5, 8, 4]);

hence the residue r(1)= -1 corresponds to the pole at s = -2 given by p(1), the residue r(2)=2
corresponds to the double pole at s = -2 given by p(2), and the residue r(3) = 1 correspond to the
pole at s= -1 given by p(3). Partial fraction expansion is therefore

PLOTING ZEROS AND POLES


We may depict the poles and zeros of H(z) in the z-plane and plot the system’s magnitude
response

Figure 13.1: Zeros & Poles

Conclusion:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………

72
Experiment 14
Fourier Series in MATLAB
Exercise Objective:

To study the basics of Fourier series representationof discrete time periodic signal.
1.2. Generation of Fourier series of discrete time periodic signals.
In this lab you will learn
Representation of Fourier series in discrete time.
Linear Combinations of Harmonically related Complex
Exponentials.
Gibbs Phenomena

Requirement:

➢ Intel based computer


➢ MATLAB
Theory:

Fourier series provide an alternate way of representing data instead of representing the signal
amplitude as a function of time; we represent the signal by how much information is contained at
different frequencies.

Harmonics:-
In acoustics and telecommunication, the harmonic of a wave is a component frequency of the
signal that is an integer multiple of the fundamental frequency. For a sine wave, it is an integer
multiple of the frequency of the wave. For example, if the frequency is f, the harmonics have
frequency 2f, 3f, 4f, etc.
Sample for a harmonic series:
1f 440 Hz Fundamental frequency First harmonic
2f 880 Hz First overtone Second harmonic
3f 1320Hz Second overtone Third harmonic

Linear combination of Harmonically Related Complex exponential:-


As we know that a signal is periodic if for some positive value of T.
x(t)=x(t + T) for all t.
The fundamental period of x(t) is minimum positive, nonzero value of T for which the above
equation is satisfied, and the value ω0 = 2π / T is referred to as the fundamental
frequency.
73
Now we introduced two basic periodic signals, the sinusoidal signal x(t)=cosωοt and the periodic
complex exponential
x(t)=e j t both of these signals are periodic with fundamental frequency ω0 and fundamental
period T=2 / . Associatedwith the signal in the equation x(t)=e j t is the set
ofharmonically related complex exponentials.
k(t) ejk t ejk(2 /T)t ,k 0, ± 1, ± 2,.......
Each of these signals has a fundamental frequency that is a multiple of ωο , and therefore each is
periodic with period T.
Thus, a linear combination of harmonically related complex exponentials of the form:

Is also periodic with period T. In the above equation for k=0 is a constant. The term for k=+1 and
k=-1 both have fundamental frequency equal to ωο and are collectively referred to as the
fundamental components or the first harmonic components. The two terms for k=+2 and k=-2 are
periodic with half the period (or, equivalently, twice the frequency) of the fundamental
components. More generally, the components for k=+N and k=-N are referred to as the Nth
harmonic components.
The representation of a periodic signal in the form of equation (1) is referred to as the Fourier
series representation.
Consider a periodic signal x(t), with fundamental frequency 2π , that is expressed in the form of
equation (1)

Where

Rewriting equation (2) and collecting each of the harmonic components, which have the same
fundamental frequency, we obtain

Equivalently, using Euler’s relation. We can write x(t) in theForm

Equation (4) is an example of an alternative form for the Fourier series of real periodic signals.
We illustrate graphically how the signal x(t) is built up from its harmonic components

74
75
Application of Fourier Series (Gibbs
Phenomena):-
Now consider the pulse train x[n] with a Fourier series representation:

By Fourier series xn[n] should be converges to x[n].In other words |xn[n] – x[n]|should be
getting close to zero as N
increases.
Now we can plot the Fourier series representation using MATLAB and see how the series does
at reproducing the original signal. If we plot the first 20 terms in the sum, we see the general
shape of the original function but we see a lot of 'ringing'. As we plot more terms, we see the
original function is represented quite accurately. In general Fourier series can reconstruct a signal
with a small number of modes if the original signal is smooth.
Discontinuities require many high frequency components to construct the signal accurately.

The MATLAB code that generate this is given below:


N = 20;
x = [0:100]/100;
f = ones(1,101)*1/2;
for i = 1:2:N
a = 2/pi/i;
f = f+ a*sin(2*pi*i*x);
76
end
plot(x,f)

The process of resolving a signal into its Fourier series is called spectral analysis or Harmonic
analysis.

Conclusion:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………

77
Experiment 15
Fourier Transform using MATLAB
Exercise Objective:

To study the basics of Discrete-Time Fourier transforma periodic signals.


Generation of Fourier transform for periodic signals.
In this lab you will learn
Fourier Transform representation for periodic signals.

Requirement:

➢ Intel based computer


➢ MATLAB
Theory:

The discrete time Fourier transforms (DTFT) of a discrete sequence x[n] is a representation of
the sequence in terms of the complex exponential sequence { e j w n } where ω is the real
frequency variable. The DTFT representation of a sequence is unique.

Discrete-Time Fourier Transform:-


The discrete-time Fourier transform X ( e j w ) of a sequence x[n] is defined by,

In general { e j w n } is a complex function of the real variable ω and can be written in


rectangular form as

Where Xre( e j w ) and im X ( e j w ) are, respectively, the real and imaginary part of the X ( e j w
) , and are real functions of ω . X ( e j w ) can alternatively be expressed in the polar form as

The quantity X is called the magnitude function and the quantity (w) is called the phase function
with both functions again being real functions of w. The relationship between the rectangular and
polar forms of X ( e j w ) follows from above equations and are given by,

78
Procedure:
DTFT Computation using MATLAB:-
The signal processing toolbox in MATLAB includes a number of M-files to aid in the DTFT-
based analysis of discrete-time signals. Specifically, the functions that can be used are freqz, abs,
and angle. In addition, the built-in MATLAB function real and imag are also useful in some
applications.
The function freqz can be used to compute the values of the DTFT of a sequence, described as a
rational function in Xe j w ) in the form of following equation at a prescribed set of discrete
frequency points w = w

There are various forms of this function:


H = freqz (num, den, w), H= freqz (num, den, f, FT),
[H, w] = freqz (num, den, k), [H, f] = freqz (num, den, k,
FT),
[H, w] = freqz (num, den, k, ‘whole’),
[H,f] = freqz (num, den, k, ‘whole’, FT), freqz (num, den)
The functions freqz returns the frequency response values asa vector H of a DTFT defined in
terms of the vectors numand den containing the coefficients {pi} and {di}, respectively, at a
prescribed set of frequency pints. In H =freqz (num, den, w), the prescribed set of frequencies
between 0 and 2 pi are given by the vector w. in H= freqz(num, den, f, FT), the vector f is used
to provide the prescribed frequency points whose values must be in the range 0 to FT/2 with FT
being the sampling frequency. The total number of frequency points can be specified by k
equally spaced points between 0 and pi, and returned as the output data vector f. for faster
computation, it is recommended that the number k be chosen as a power of 2, such as 256 or 512.
by including ‘whole’ in the argument of freqz, the range of frequencies becomes 0 or 2pi or 0 to
FT, as the case may be. After the DTFT values have been determined, they can be plotted either
showing their real and imaginary parts using the functions real and imag or in terms of their
magnitude and phase components using the functions abs and angle. The function angle
computes the phase angle in radians. If desired, the phase can be unwrapped using the function
unwrap. freqz (num, den) with no output arguments computes and plots the magnitude and phase
response values as a function of frequency in the current figure window.

79
Examples of MATLAB:-
Consider a signal (referred to Example 5.1 page 362)

Consult the book for magnitude and imaginary plots.


Now, solve determine Fourier transform using fft. The following code calculates DTFT of above
signal.
t=0:100;
a=0.9;
s=0.9.^t % signal x[n] = pow(a,n)u[n]
S_M = abs(fft(s)); % Magnitude of signal
% Magnitude Plot
subplot(211)
n_S_M=linspace(0,2*pi,length(t));
plot(n_S_M,S_M);
xlabel('w');ylabel('Magnitude of signal');
title('Magnitude plot of x[n]');
S_P = angle(fft(s)); % Phase of Signal
% phase plot
subplot(212)
n_S_P=linspace(0,2*pi,length(t));
plot(n_S_P,S_P);
xlabel('w');ylabel('Phase');
title('Phase plot of x[n]');

Conclusion:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………

80
Experiment 16
Z- Transform using MATLAB
Exercise Objective:

To study the Z-transform of Aperiodic signals.


To Determine response of LTI system.
In this lab you learn
Poles, zeros and ROC of a LTI system calculation in MATLAB

Requirement:

➢ Intel based computer


➢ MATLAB
Theory:

In last lab, we discussed the discrete-time Fourier transform approach for representing discrete
signals using complex exponential sequences. There are two shortcomings to the
Fourier transform approach.
There are many useful signals in practice such as u[n] and nu[n] for which the discrete-time
Fourier transform does not exist.
Second, the transient response of a system due to initial conditions or due to changing inputs
cannot be computed using the discrete-time Fourier transform approach.
We now consider the z-transform an extension of the discrete-time Fourier transform to address
the above two problems.

Definition:-
For a given sequence x[n], its z-transforms X[z] is defined as

Where z is a complex variable. If we let z =r e j w , where ω is a real frequency variable and r is


attenuation then Equation (1)
become

81
Which can be interpreted as the DTFT of a modifiedsequence {x[n] r 1}. For r=1(i.e. |z|=1), the
z-transform of x[n] reduces to its DTFT. From equation (2), we see that X ( r e j w ) is the
Fourier transform of sequence of x[n] multiplied by real exponential r n , i.e.

Region of Convergence (ROC):-


The range of z values for which X(z) exists is called the region of convergence (ROC) and is
given by:

(Where, x R and x R positive numbers) Convergence of series in Eq. (1) depends only on |z|,
since
|X(z)| < ∞ if,

The region of convergence consists of all values of z such that inequality (4) holds. Thus if some
value of z, say z=z1 is in the ROC, then all values of z on the circle defined by |z|=|z1| will also
be in the ROC. The ROC consists of a ring in the z-plane centered about the origin. Its outer
boundary will be either a circle or mayextend outward to infinity, and its inner boundary will be
either a circle or may extend inward to include the origin. This is illustrated in Figure 1. In this
figure X(z) will exist for all values of z lie in shaded region.

Following three points decide the shape of ROC


The ROC for right-sided sequences (e.g. a n u[n]) is always outside of a circle toward infinity.
The ROC for left-sided sequences (e.g. a n u[-n]) is always inside of a circle to include the
origin.
The ROC for two-sided sequences (e.g. a n u[n]-a n u[- n-1])) is always an open ring

Z-Transforms of LTI system:-


In case of LTI Discrete-time systems that we are concerned with in the text, all pertinent z-
transforms are rationalfunction of Z 1 .as expressed in flowing Eq. (5)

82
p are numerator coefficients and q are denominator coefficients. Eq (5) results from solving LTI
system in z domain.

Procedure:
Z-Transforms using MATLAB:-
3.1 [z,p,k]=tf2zp(num, den) command
Pole, zeros and ROC of the expression of following form can determine using tf2zp command.
Consider response of an LTI system

To find poles and zeros fist we carry out the factorization of G(z). Following code do this.
% Determination of factor form
num = input('Type the Numerators coefficients = ');
den = input('Type the Denominators coefficients = ');
[z,p,k]=tf2zp(num,den);
m=abs(p);
disp('zeros are at');disp(z);
disp('poles are at');disp(p);
disp('Gain Constant');disp(k);
disp('Radius of Poles');disp(m);
zplane(num,den);
the program compute and prints the location of poles and
zeros, the value of gain
constant and the radius of poles
Input data:
Type the coefficients = [2 16 44 56 32]
Type the Denominators coefficients = [3 3 -15 18 -12]
Output
zeros are at
-4.0000
-2.0000
-1.0000 + 1.0000i
-1.0000 - 1.0000i
poles are at
-3.2361
1.2361
0.5000 + 0.8660i
0.5000 - 0.8660i

83
Gain Constant
0.6667
Radius of Poles
3.2361
1.2361
1.0000
1.0000

[r,p,k]=residuez(num,den) command:-
The M-file residuez can be used to develop partial fraction expansion of Eq (5) and vice versa

Now, we will find the partial fraction expansion using following code,
%Partial fraction expansion of rational z-transform

num = input('Type the Numerators coefficients = ');


den = input('Type the Denominators coefficients = ');
[r,p,k]=residuez(num,den);
disp('Residues');disp(r');
84
disp('ploes are at');disp(p');
disp('Gain Constant');disp(k);
% Ploes and zeros plotting
zplane(num,den);
Input data
Type the Numerator coefficients = [18]
Type the Denominator coefficients = [18 3 -4 -1]
Output data
Residues
0.3600 0.2400 0.4000
ploes are at
0.5000 -0.3333 -0.3333
Note also that the z-transform of G(z) has double poles at z=-1/3. The first entry in both the
residues and pole given above corresponds to the simple pole factor (1-0.5Z 1), the second entry
corresponds to the simple pole factor (1- 0.333Z 1), and the third entry correspond to the factor
(1+0.333Z 1) in the partial fraction. Thus the desired expansion is given by

Conclusion:
………………………………………………………………………………………………………
………………………………………………………………………………………………………
………………………………

85

You might also like