Lab Manual (PROGRAMMING!!)
Lab Manual (PROGRAMMING!!)
For
B.E. Electrical Engineering
Group Members
Degree Syndicate
4
LIST OF EXPERIMENTS
4
Experiment No. 1
Objective:
The objective of this lab is to create an understanding of the basic MATLAB
commands and familiarize the students with MATLAB environment.
Theoretical Background:
MATLAB stands for matrix laboratory. MATLAB allows matrix manipulations,
plotting of functions and data, implementation of algorithms, creation of user
interfaces, and interfacing with programs written in other languages including C,
C++, Java, etc. The MATLAB application is built around the MATLAB scripting
language. Common usage of the MATLAB application involves using the Command
Window as an interactive mathematical shell or executing text files containing
MATLAB code. This lab deals with an introduction to MATLAB, where students
will learn different ways of creating vectors, and to perform various operations on
vectors.
Tasks:
The following tasks are to be performed by the students.
Task 1:
The students will learn the different ways of creating vectors in MATLAB in this
task.
(a) Generate the following vectors:
A = [1 0 4 5 3 9 0 2]
a= [4 5 0 2 0 0 7 1]
Be aware that MATLAB is case sensitive. Vector A and a have different values.
(c) Generate the following vectors using function zeros and ones:
D= [0 0 0 . . . 0] with fifty 0’s.
E= [1 1 1 . . . 1] with a hundred 1’s.
Task 2:
Operate with the following vectors to perform tasks (a) to (e):
V1 = [1 2 3 4 5 6 7 8 9 0]
V2 = [0.3 1.2 0.5 2.1 0.1 0.4 3.6 4.2 1.7 0.9]
V3 = [4 4 4 4 3 3 2 2 2 1]
(a) Calculate, respectively, the sum of all the elements in vectors V1, V2, and V3.
(b) How to get the value of the fifth element of each vector?What happens if we
execute the command V1(0) and V1(11)?Remember if a vector has N elements, their
subscripts are from 1 to N.
(c) Generate a new vector V4 from V2, which is composed of the first five elements
of V2. Generate a new vector V5 from V2, which is composed of the last five
elements of V2.
(d) Derive a new vector V6 from V2, with its 6th element omitted.
Derive a new vector V7 from V2, with its 7th element changed to 1.4,
and a vector V8 from V2, whose elements are the 1st, 3rd, 5th, 7th, and 9th elements of
V2.
9-V1
V1*5
V1+V2
V1-V3
V1.*V2
V1*V2
V1.^2
V1.^V3
V1^V3
V1 == V3
V1>6
V1>V3
V3-(V1>2)
(V1>2) & (V1<6)
(V1>2) | (V1<6)
4
any(V1)
all(V1)
4
INSTRUCTOR VERIFICATION SHEET
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Verified: Date/Time:
4
Experiment No. 2
Objective:
The objective of this lab is to create an understanding of using loops and conditional
statements in MATLAB. It also introduces the basics of plotting signals.
Theoretical Background:
As in any language, MATLAB also has loops and conditional statements. The ‘for’
and ‘while’ loops can be used to run a specific set of commands a number of times
based on some conditions. Similarly, the ‘if-else’ conditional statements are used to
run a specific set of commands only if a specified condition is true, and another set
of commands may be run if the condition is not true.
Tasks:
The following tasks are to be performed by the students.
Task 1:
Write a MATLAB code to display the following using for loop, while loop and if
statements separately:
First 30 numbers
First 30 even numbers
First 30 odd numbers
Task 2:
(a) Check whether the following set of commands :
for i = 1:20
H(i) = i * 5
End
have the same result as:
H = 1:20;
H = H*5
4
end
have the same result as:
n = 1:100;
x = sin(n*pi/10)
Task 3:
Run the following three MATLAB lines of code and explain why the plots are
different:
Task 4:
For the following, use the signal described as:
t=0:0.2:2*pi
Put two plots on the same axis, i.e. sin(t) and sin(2t)
Produce a plot without connecting the points
Try the following command and comment:
t=0:0.2:2*pi; plot (t, sin(t), t, sin(t),’r.’)
4
INSTRUCTOR VERIFICATION SHEET
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Task 3:
Task 4:
Verified: Date/Time:
4
Experiment No. 3
Objective:
The objective of this lab is to practice some basic operations performed on a signal
like shifting and flipping. Also, students will learn how to prove the stability and
causality properties of a signal in MATLAB. An introduction to convolution is also
included in this lab.
Theoretical Background:
For any signal, say 𝑥(𝑡), the independent variable ‘t’ can be transformed in various
ways, including shifting and flipping. These two operations will be observed in this
lab. Shifting of a signal in time, or the independent variable, is shown in the figure
below for a discrete time signal, and a continuous time signal.It can be seen in this
figure that the signal x[n] is shifted by a factor of no, making the signal x[n-no],
similar observations can be made about x(t). These signals are exactly similar in
shape, but are shifted or displaced relative to each other. Time shifts can be observed
for both continuous and discrete time signals.
A second basic transformation of the time axis is the time reversal. The time
reversed or time flipped signal is obtained from a signal x[n] by reflection about n=0.
Thus x[-n] is the signal x[n] displayed backwards. Similarly, x(-t) is the flipped
signal for x(t). The time reversal of discrete and continuous time signals is shown
below:
4
Tasks:
The following tasks are to be performed by the students.
Task 1:
Generate four basic discrete time signals(unit step, unit impulse, sinusoid and
exponential ). Perform following operations on them:
Task 2:
Make stem plots of the following signals. Decide for yourself what the range of n
should be.
f(n)=u(n)-u(n-4)
g(n)=n.u(n)-2(n-4)u(n-4)+(n-8)u(n-8)
x(n) = δ(n) − 2δ(n − 4)
y(n) = 0.9 n (u(n)-u(n-20))
v(n) = cos(0.12πn) u(n)
Task 3:
f(n) = u(n)−u(n−4)
g(n) = n·u(n)−2(n−4)·u(n−4) + (n−8)·u(n−8).
Make stem plots of the following convolutions. Use the MATLAB conv command to
compute the convolutions.
(a) f(n)∗f(n)
(c) f(n)∗g(n)
(d) g(n)∗δ(n)
4
(e) g(n)∗g(n)
4
INSTRUCTOR VERIFICATION SHEET
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Verified: Date/Time:
4
Experiment No. 4
Objective:
The objective of this lab is to learn the use of symbolic variables and use them to
solve differential equations, and find differentiation and integration of functions.
Theoretical Background:
One of the very attractive features of MATLAB includes the symbolic math toolbox.
It is of great utility in applications in which symbolic expressions are necessary for
reasons of accuracy in calculations. Symbolic numbers, variables and expressions
may be declared and used in MATLAB. The command used to declare a symbolic
variable, expression or number is ‘sym’. The command ‘syms’ can be used to
declare multiple symbolic objects at a time. Symbolic math is very useful in finding
exact solution of differential equations, differentiation, integration, and simultaneous
solution of equations.
Tasks:
The following tasks will help the students to familiarize themselves with the
symbolic math in MATLAB and to use symbolic expressions to practice various
operations.
Task 1:
Define five 5th order equations using symbolic variables. Solve each of the
equations separately with respect to one variable.
Task 2:
Declare two 2nd order equations using symbolic variables and solve them
simultaneously. Make five sets of equations.
Task 3 :
Declare five 5th order symbolic equations and differentiate them. Find first, second,
third, fourth and fifth order derivatives
Task 4:
Find the definite integral of five symbolic expressions with lower and upper limits 0
and 1 respectively.
4
INSTRUCTOR VERIFICATION SHEET
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Task 3:
Task 4:
Verified: Date/Time:
4
Experiment No. 5
Objective:
The objective of this lab is to create an understanding of convolution by writing a
code to perform convolution of two signals.
Theoretical Background:
Convolution is the representation of an LTI system in terms of its unit impulse
response. Impulse response of a system h[n] is the output when a unit impulse δ[n] is
given at its input. For a system with input x[n] and the system impulse response h[n],
the output y[n] of the system is calculated by convolution of the system response and
input, given as:
Tasks:
Write your own code for convolution of the following sets of discrete sequences,
such that the convolved signal y[n] is given as described above. Explain each and
every step in your code. Compare your results with the results of built in conv
function
Task 1:
When x[n] is a unit impulse and h[n] is a unit step function.
Task 2:
When both x[n] and h[n] are unit step functions.
Task 3:
When 𝑥[𝑛] = (0.5)𝑛 𝑢[𝑛] and h[n] is a unit step function.
4
INSTRUCTOR VERIFICATION SHEET
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Task 3:
Verified: Date/Time:
4
Experiment No. 6
Objective:
The objective of this lab is to give the students an introduction to Simulink and to
learn to use some basic blocks in Simulink.
Theoretical Background:
Simulinkis a graphical programming environment for modeling, simulating and
analyzing dynamic systems. Its primary interface is a graphical block diagramming
tool and a customizable set of block libraries. It offers tight integration with the rest
of the MATLAB environment and can either drive MATLAB or be scripted from it.
In this lab, the students will be introduced to the Simulink environment. The students
will learn to apply various basic operations on simple signals like the unit step and
sine wave, and observe the results using the ‘scope’ block in Simulink, which works
like an oscilloscope.
Tasks:
The students have to create each of the following block diagrams in Simulink, and
learn the purpose and usage of each of the blocks used.
Task 1:
4
Task 2:
Task 3:
4
INSTRUCTOR VERIFICATION SHEET
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Task 3:
Verified: Date/Time:
4
Experiment No. 7
Objective:
The objective of this lab is to create a generalized code for convolution of two
discrete signals and to perform convolution using Simulink. The students will also
learn to use audio signals in MATLAB.
Theoretical Background:
Convolution is the representation of an LTI system in terms of its unit impulse
response. Impulse response of a system h[n] is the output when a unit impulse δ[n] is
given at its input. The convolution of two discrete time signals is called the
convolution sum while the convolution of two continuous time signals is referred to
as the convolution integral.
Convolution of sequence x[n] with the response of LTI system h[n] is the
convolution sum, given as:
𝑦[𝑛] = ∑ 𝑥[𝑘]ℎ[𝑛 − 𝑘]
𝑘=−∞
𝑦[𝑛] = ∑ ℎ[𝑘]𝑥[𝑛 − 𝑘]
𝑘=−∞
Tasks:
Task 1:
Write a MATLAB code for Convolution of the following signals, and plot the results
for each case:
Task 2:
• Record a 5 second sound signal using ‘audiorecorder’ and save it in a ‘.wav’ file.
4
• Play the sound file in the following ways:
– Complete file
Task 3:
Perform convolution of an audio file imported in Simulink with a system defined
below. Plot the audio signal before and after passing through the system using
function callback (File -> Model properties -> Callbacks) The system is defined as:
• System=10*[1 1 1 1 1 1 1 1]
4
4
INSTRUCTOR VERIFICATION SHEET
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Task 3:
Verified: Date/Time:
4
Experiment No. 8
Objective:
The aim of Today’s lab is to introduce the students to create Graphical User
Interfaces (GUIs) in MATLAB. By the end of this lab the students should be able to
display information/instructions to user and accepting user inputs from keyboards
and deal with GUIs for performing basic functions.
What Is GUI?
A graphical user interface (GUI) is a graphical display that contains devices, or components,
that enable a user to perform interactive tasks. To perform these tasks, the user of the GUI
does not have to create a script or type commands at the command line. Often, the user does
not have to know the details of the task at hand. The GUI components can be menus,
toolbars, push buttons, radio buttons, list boxes, and sliders. In MATLAB, a GUI can also
display data in tabular form or as plots, and can group related components.
Each component, and the GUI itself, is associated with one or more user-written routines
known as callbacks. The execution of each callback is triggered by a particular user action
such as a button push, mouse click, selection of a menu item, or the cursor passing over a
component. This kind of programming is often referred to as event-driven programming. In
event-driven programming, callback execution is asynchronous, controlled by events
external to the software. In the case of MATLAB GUIs, these events usually take the form
of user interactions with the GUI.
A MATLAB GUI is a figure window to which you add user-operated controls. You can
select, size, and position these components as you like. Using callbacks you can make the
components do what you want when the user clicks or manipulates them with keystrokes.
construction).
The first approach starts with a figure that you populate with components from within a
graphic layout editor. GUIDE creates an associated M-file containing callbacks for the GUI
and its components. GUIDE saves both the figure (as a FIG-file) and the M-file. Opening
either one also opens the other to run the GUI.
In the second, programmatic, GUI-building approach, you code an M-file that defines all
component properties and behaviors; when a user executes the M-file, it creates a figure,
4
populates it with components, and handles user interactions. The figure is not normally saved
between sessions because the M-file creates a new one each time it runs.
As a result, the M-files of the two approaches look different. Programmatic M-files are
generally longer, because they explicitly define every property of the figure and its controls,
as well as the callbacks. GUIDE GUIs define most of the properties within the figure itself.
They store the definitions in its FIG-file rather than in its M-file. The M-file contains
callbacks and other functions that initialize the GUI when it opens.
MATLAB software also provides functions that simplify the creation of standard dialog
boxes, for example to issue warnings or to open and save files. The GUI-building technique
you choose depends on your experience, your preferences, and the kind of application you
need the GUI to operate.
You can combine the two approaches to some degree. You can create a GUI with GUIDE and
then modify it programmatically. However, you cannot create a GUI programmatically and
later modify it with GUIDE.
Starting GUIDE
There are many ways to start GUIDE. You can start GUIDE from the:
However you start GUIDE, it displays the GUIDE Quick Start dialog box shown in
the following figure.
4
GUIDE Tools Summary
The GUIDE tools are available from the Layout Editor shown in the figure below. The tools
are called out in the figure and described briefly below.
Show Toolbar
Set the size of the GUI by resizing the grid area in the Layout Editor. Click the lower-right
corner and drag it until the GUI is the desired size. If necessary, make the window larger.
4
Available Components
The component palette at the left side of the Layout Editor contains the components that you
can add to your GUI. You can display it with or without names.
4
Edit Text Edit text components are fields that enable users to enter or modify
text strings. Use edit text when you want text as input. Users can
enter numbers but you must convert them to their numeric
equivalents.
Static Text Static text controls display lines of text. Static text is typically
used to label other controls, provide directions to the user, or
indicate values associated with a slider. Users cannot change static
text interactively.
List Box List boxes display a list of items and enable users to select one or
more items.
Pop-Up Menu Pop-up menus open to display a list of choices when users click
the arrow.
Axes Axes enable your GUI to display graphics such as graphs and
images. Like all graphics objects, axes have properties that you can
set to control many aspects of its behavior and appearance. See
“Axes Properties” in the MATLAB Graphics documentation and
commands such as the following for more information on axes
objects: plot, surf, line, bar, polar, pie, contour, and mesh. See
Functions — By Category in the MATLAB documentation for a
complete list.
Panel Panels arrange GUI components into groups. By visually grouping
related controls, panels can make the user interface easier to
understand. A panel can have a title and various borders. Panel
children can be user interface controls and axes
as well as button groups and other panels. The position of each
Button Group component
Button within
groups a panel
are like is interpreted
panels relative
but are used to theexclusive
to manage panel. If you
move the behavior
selection panel, itsfor
children move with
radio buttons andittoggle
and maintain
buttons.their
positions on the panel.
4
Callbacks: An Overview
After you have layed out your GUI, you need to program its behavior. The code you write
controls how the GUI responds to events such as button clicks, slider movement, menu item
selection, or the creation and deletion of components. This programming takes the form of a
set of functions, called callbacks, for each component and for the GUI figure itself.
What Is a Callback?
A callback is a function that you write and associate with a specific GUI component or with
the GUI figure. It controls GUI or component behavior by performing some action in
response to an event for its component. This kind of programming is often called event-
driven programming. When an event occurs for a component, MATLAB invokes the
component’s callback that is triggered by that event. As an example, suppose a GUI has a
button that triggers the plotting of some data. When the user clicks the button, MATLAB
calls the callback you associated with clicking that button, and the callback, which you have
programmed, then gets the data and plots it. A component can be any control device such as
a push button, list box, or slider. For purposes of programming, it can also be a menu or a
container such as a panel or button group.
By default, the first time you save or run a GUI, GUIDE stores the GUI in two files:
A FIG-file, with extension .fig, that contains a complete description of the GUI
layout and the GUI components, such as push buttons, axes, panels, menus, and so
on. The FIG-file is a binary file and you cannot modify it except by changing the
layout in GUIDE.
An M-file, with extension .m, that initially contains initialization code and templates
for some callbacks that are needed to control GUI behavior. You must add the
callbacks you write for your GUI components to this file. When you save your GUI
M-file in your default editor. The FIG-file and the M-file, usually reside in the same
directory. They correspond to the tasks of laying out and programming the GUI.
When you lay out the GUI in the Layout Editor, your work is stored in the FIG-file.
When you program the GUI, your work is stored in the corresponding M-file.
The GUI M-file that GUIDE generates is a function file. The name of the main function is the
same as the name of the M-file. For example, if the name of the M-file is mygui.m, then the
name of the main function is mygui. Each callback in the file is a subfunction of the main
function. When GUIDE generates an M-file, it automatically includes templates for the most
commonly used callbacks for each component. The M-file also contains initialization code, as
well as an opening function callback and an output function callback. You must add code to
the component callbacks for your GUI to work as you want. You may also want to add code to
the opening function callback and the output function callback. The major sections of theGUI
M-file are ordered as shown in the following table.
8
Task 1
plot a function f(t)=t*[u(t+1)-u(t-1)]+u(t-1)-u(t-3) and plot a time shifted and time scaled
version of f(t) which has the general form cf(at+b). The user can input variables values of a,b
and c. The original function appears on GUI axis1 and the other on GUI axis2.
Designing steps
2. Change the name of the (static text) by double clicking on each one as follow
9
3-change the size ,colour and weight of the text as follow
1
0
5- push on the green arrow (Run) and save the design
1
1
6-Right click on the Plot button and select view callback and choose callback .
1
2
8-Write the following code under the Plot_callback function
axes(handles.axes1)
a = str2double(get(handles.a,'String'));
b = str2double(get(handles.b,'String'));
c = str2double(get(handles.c,'String'));
t = eval((get(handles.t,'String')));
%plot the first function
f=inline('((t>=1)&(t<3))','t');
plot(t,f(t))
ylim ([ min(f(t))-.2 max(f(t))+.2])
grid on
%plot the seconed function
f1=c.*f(a*t+b);
axes(handles.axes2)
plot(t,f1)
ylim ([ min(f1)-.2 max(f1)+.2])
grid on
Task 2:
Build a GUI that makes plots of the following signals. Take input from the user for the
range of n. The user should be able to input range of n for each function. Place a push
button for producing plots of both functions simultaneously .Also insert a pop up menu
for producing plots one by one and when one option from the menu is selected the other
plot should disappear.
f(n)=u(n)-u(n-4)
g(n)=n.u(n)-2(n-4)u(n-4)+(n-8)u(n-8)
1
3
EE Department Signals and Systems
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Verified: Date/Time:
Experiment No. 9
Objective:
The objective of this lab is to create a practical understanding of the Continuous time Fourier
Series (Chapter 3 of textbook) and to prove various properties of the CTFS.
Theoretical Background:
The Continuous Time Fourier Series is used for representation of continuous-time periodic
signals:
1 𝑇/2 1 𝑇/2 2π
𝑎𝑘 = ∫ 𝑥(𝑡)𝑒 −𝑗 𝑘 𝑤𝑜 𝑡 = ∫ 𝑥(𝑡) 𝑒 − 𝑗 𝑘 ( T )𝑡 𝑑𝑡
𝑇 −𝑇/2 𝑇 −𝑇/2
There are many properties associated with the CTFS, in this lab the students will prove the
following two properties, where:
x(t) and y(t) are two continuous time periodic signals with period T and fundamental
frequency 𝑤𝑜 = 2 π/T
𝑎𝑘 and 𝑏𝑘 are the Fourier Series Coefficients
1. Multiplication:
The Fourier Series representation of the product of two continuous time periodic signals x(t)
and y(t) is equal to the convolution of their Fourier Series coefficients
∞
Tasks:
The following tasks are to be performed individually by each student:
Task 1:
Create separate functions in MATLAB for Continuous Time Fourier Series (CTFS), i.e.
Fourier series coefficients of a signal and the Inverse Continuous Time Fourier Series
(ICTFS), i.e. creating signal from Fourier Series Coefficients.
Task 2:
Using the functions for CTFS and ICTFS created in Task 1, prove the following properties
(explained in theoretical background) of CTFS:
Multiplication Property
Differentiation Property
x(t) = sin(πt)
y(t) = cos(πt)
The signal period Tp=2*pi
Number of coefficients k=-10 to 10
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Verified: Date/Time:
Experiment No. 10
Objective:
The objective of this lab is to create a practical understanding of the Discrete Time Fourier
Series (Chapter 3 of textbook) and to prove some properties of the DTFS.
Theoretical Background:
The Discrete Time Fourier Series is used for representation of discrete-time periodic signals:
Periodic Convolution:
The convolution of two periodic sequences is calculated through periodic convolution. The
basic idea is to take one period of each signal and perform periodic convolution to get one
period of the resultant sequence. Then this one period is repeated over all time to create a
periodic sequence. The formula for periodic convolution is:
𝑁−1
𝑦[𝑛] = ∑ 𝑥1 [𝑚]𝑥2 [𝑛 − 𝑚]
𝑚=0
where x1[n] and x2[n] are two discrete time periodic sequences and y[n] is one period of
a discrete time periodic sequence
N is the length of each sequence
There are many properties associated with the DTFS, in this lab the students will prove the
following two properties, where:
x(t) and y(t) are two continuous time periodic signals with period T and fundamental
frequency 𝑤𝑜 = 2 π/T
𝑎𝑘 and 𝑏𝑘 are the Fourier Series Coefficients
1. Periodic Convolution:
This property states that the DTFS of periodic convolution of two discrete time periodic
sequences is equal to multiplication of the DFS coefficients of the sequences.
2. Frequency Shifting:
The shifting of DFS coefficients is equivalent to multiplication of complex exponential to the
actual periodic signal.
Tasks:
The following tasks are to be performed by each student:
Task 1:
Create separate functions in MATLAB for Discrete Time Fourier Series (DTFS), i.e. Fourier
series coefficients of a signal and the Inverse Discrete Time Fourier Series (IDTFS), i.e.
creating signal from Fourier Series Coefficients.
Task 2:
a). Create a function that performs periodic convolution on two discrete time periodic
sequences of same length.
b). Using the functions for DTFS and IDTFS created in Task 1 and the function for periodic
convolution, prove the following properties (explained in theoretical background) of DTFS:
Periodic Convolution
Frequency Shifting
x[n]=[1 2 1 2 1 2 1]
y[n]=[1 0 1 0 1 0 1]
The period N is the length of the signal
Task 3:
Take the discrete time periodic square wave as shown below:
Take N1=5 and the number of zeros in each period is also equal to N1 (Example 3.12 of
textbook)
Calculate the DTFS of this square wave, then calculate its inverse DTFS using the IDTFS
function. Plot the original signal, the DTFS and the IDTFS results in the same figure using
subplot.
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Task 3:
Verified: Date/Time:
Experiment No. 11
Objective:
The objective of this lab is to create a practical understanding of the Discrete Time Fourier
Transform (Chapter 5 of textbook) and to prove some properties of the DTFT.
Theoretical Background:
The Discrete Time Fourier Transform is used for representation of discrete-time a-periodic
signals:
There are many properties associated with the DTFT, in this lab the students will prove the
following two properties, where:
Tasks:
The following tasks are to be performed by each student.
Task 1:
Create separate functions in MATLAB for Discrete Time Fourier Transform (DTFT), i.e.
analysis equation, and Inverse Discrete Time Fourier Transform (IDTFT), i.e. synthesis
equation.
Task 2:
Consider the rectangular pulse:
1, |𝑛| ≤ 𝑁1
𝑥[𝑛] = {
0, |𝑛| > 𝑁1
Find the DTFT of x[n] using the DTFT function created in Task 1. Then, find the IDFT of
this result using the IDTFT function, also created in Task 1. Using subplot, display the input
signal x[n], and the output of the IDTFT function. The result in both subplots should be
same. This task is an implementation of Example 5.3 of your textbook.
Task 3:
Using the functions created in task 1, prove the convolution and multiplication properties of
the DTFT in separate codes. Display the time domain (n- domain) results in each case using
the subplot command.
The specifications of the two signals are given below for both properties separately.
x[n]=[1 0 1 0 1]
y[n]=[1 1 0 1 0]
N is the length of the signal.
x[n]=[1 2 3 1 3]
y[n]=[3 4 3 3 2]
N is the length of the signal.
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Task 3:
Verified: Date/Time:
Experiment No. 12
Objective:
The objective of this lab is to create a practical understanding of the Continuous Time
Fourier Transform (Chapter 4 of textbook) and to prove some properties of the CTFT. Also,
students will learn implementation of the Laplace Transform (Chapter 9 of textbook) and
prove some of its properties.
Theoretical Background:
Continuous Time Fourier Transform:
There are many properties associated with the CTFT; in this lab the students will prove the
following two properties:
1. Time Shifting Property:
This property states that the CTFT of a time shifted continuous time signal is equal to
multiplication of the Fourier Transform of the original signal by a complex exponential.
𝐶𝑇𝐹𝑇{𝑥(𝑡 − 𝑡𝑜 )} = 𝑒 −𝑗𝑤𝑡𝑜 𝑋(𝑗𝑤)
2. Differentiation Property:
This property states that the CTFT of the differentiation of a continuous time signal is
equal to multiplication of the CTFT of the original signal with (jw).
𝑑 𝑥(𝑡)
𝐶𝑇𝐹𝑇 { } = 𝑗𝑤 𝑋(𝑗𝑤)
𝑑𝑡
where,
Tasks:
The following tasks are to be performed by each student:
Task 1:
2
Using symbolic variables, calculate the Fourier transform of a signal 𝑥 = 𝑒 −𝑡 . Also
calculate the Inverse Fourier Transform to get the original signal. Plot all three signals in a
subplot figure.
Task 2:
2
a) Prove the time shifting property for the CTFT using the signal 𝑥 = 𝑡𝑒 −𝑡 . The time shift
given to this signal is𝑡0 = 3. Plot the signals in time domain using subplot.
2
b) Using the input signal 𝑦 = 𝑒 −𝑥 , prove the differentiation property of the CTFT. Plot the
signals in time domain using subplot.
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Task 3:
Verified: Date/Time:
Experiment No.13
Objective:
The objective of this lab is to learn how to implement the basic types of filters in MATLAB
and to apply them on an audio signal.
Theoretical Background:
Filters:
Filters, in general, are used to block some part of a signal and to pass some particular part of
a signal. In frequency domain, we say that a filter will block a certain range of frequencies,
while passing a specific range of frequencies. The three most common types of filters are:
Tasks:
In order to create an understanding of passing signals through filters, the following tasks are
to be performed by the students:
Task 1:
Using the filter design toolbox, (FDA tool), design three filters with the following
specifications:
Task 2:
Using audiorecorder, record a 5 second audio in MATLAB
Export the filters into workspace, and save the filters and recorder object in a ‘.mat’ file.
In a new MATLAB script, load the ‘.mat’ file into workspace. Now pass the signal
through each of the three filters separately.
Reconstruct the original signal by adding the outputs of all three filters
Using subplot, show the original signal, the outputs of the three filters, and then the
reconstructed signal.
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Verified: Date/Time:
Experiment No.14
Objective:
In this lab, students will learn how to create transfer functions in MATLAB and Simulink,
and to use them further to find step and impulse response of a signal.
Theoretical Background:
Transfer Functions:
Hh
Where,
The transfer function may be written in z-domain or in s-domain (or Laplace domain).
Tasks:
The following tasks are to be performed by the students:
Task 1:
Using the ‘TF’ and ‘ZPK’ commands, create two transfer functions. Plot the step and impulse
response of each transfer function. The transfer functions to be generated are:
Task 2:
In Simulink, take three step functions. Add them and apply a transfer function to the result.
View the input and output in scope, and also export the result to workspace. Also view the
result in case of one step function only. The transfer function to be applied to the input is:
𝑠+1
6𝑠 5 + 5𝑠 4 + 4𝑠 3 + 3𝑠 2 + 2𝑠 + 1
For each verification, be prepared to explain your answer and respond to other related
questions that the lab TA’s or Professors might ask.
Task 1:
Task 2:
Verified: Date/Time: