0% found this document useful (0 votes)
79 views

Lab Manual (PROGRAMMING!!)

Here are the steps to perform convolution in MATLAB: 1. Define the signals f(n) and g(n) as vectors. For example: f = [0 0 0 1 1 1 1 0 0]; g = [0 0 4 8 12 8 4 0 0]; 2. Use the conv command to compute the convolution: h = conv(f,g); 3. Plot the result: stem(h) 4. Add labels and titles as needed. So in summary: 1) Define signals as vectors 2) Use conv() to compute convolution 3) Plot result

Uploaded by

Zulfiqar Memon
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Lab Manual (PROGRAMMING!!)

Here are the steps to perform convolution in MATLAB: 1. Define the signals f(n) and g(n) as vectors. For example: f = [0 0 0 1 1 1 1 0 0]; g = [0 0 4 8 12 8 4 0 0]; 2. Use the conv command to compute the convolution: h = conv(f,g); 3. Plot the result: stem(h) 4. Add labels and titles as needed. So in summary: 1) Define signals as vectors 2) Use conv() to compute convolution 3) Plot result

Uploaded by

Zulfiqar Memon
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 57

PRACTICAL WORK BOOK

For The Course


EE-232 Signals and Systems

For
B.E. Electrical Engineering

Group Members

Degree Syndicate

Complied By: Checked By:

DEPARTMENT OF ELECTRICAL ENGINEERING


College of Electrical & Mechanical Engineering (CEME), NUST-Pakistan

4
LIST OF EXPERIMENTS

S.NO. TITLE OF EXPERIMENT


01 Basic MATLAB Commands
02 Plotting and Loops
03 Basic Signal Properties
04 Symbolic Variables and Equations
05 Introduction to Convolution
06 Introduction to Simulink
07 Recording audio signal using Audiorecorder,
and Convolution in Simulink
08 Building Graphical User Interface
09 Continuous Time Fourier Series and its
Properties
10 Discrete Time Fourier Series and its Properties.
11 Discrete Time Fourier Transform and its
Properties
12 Continous time fourier transform and its
properties
13 Implementing Filters, Recording Audio and
passing the audio through filters
14 Transfer Functions and their Step and Impulse
Response

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.

(b) Generate the following vectors:


B= [A a]
C= [a,A]
Concatenation is the process of joining small matrices to make bigger ones. In fact,
you made your first matrix by concatenating its individual elements. The pair of
square
brackets, [], is the concatenation operator.

(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.

(d) Generate the following vectors using the colon operator


F= [1 2 3 4 . . . 30]
4
G= [25 22 19 16 13 10 7 4 1]
H= [0 0.2 0.4 0.6 . . . 2.0]
The colon“:” is one of MATLAB’s most important operators.

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.

(e) What are the results of the following?

 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.

Name: Date of Lab:

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.

A very important feature of MATLAB is the plotting of signals. It is exceptionally


important in reference to the Signals and Systems course. There are many different
commands in MATLAB that can be used to plot different types of signals or vectors.
In this lab, the students will learn to plot signals in various ways and to use different
features of plotting signals in MATLAB.

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

(b) Check whether following set of commands:


for n = 1:100
x(n) = sin(n*pi/10)

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:

 t=0:2*pi; plot(t, sin(t))


 t=0:0.2:2*pi;plot(t, sin(t))
 t=0:0.02:2*pi; plot(t, sin(t))

Task 4:
For the following, use the signal described as:

t=0:0.2:2*pi

Now perform the following operations on the signal t:

 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.

Name: Date of Lab:

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:

 Shifting (with user defined shift)


 Flipping

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)

Comment on your observations:


Use the commands title, xlabel, ylabel to label the axes of your plots.

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.

Name: Date of Lab:

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.

Name: Date of Lab:

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.

Name: Date of Lab:

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.

Name: Date of Lab:

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:

1. x[n] = [0.5 2], h[n] = [1 1 1]


2. x[n] = 1, 0≤n≤4
h[n]=𝑎𝑛 , 0≤n≤6

Also check results using ‘conv’ command

Task 2:
• Record a 5 second sound signal using ‘audiorecorder’ and save it in a ‘.wav’ file.

• Read the ‘.wav’ file using ‘audioread’

• Plot the original sound signal.

4
• Play the sound file in the following ways:

– Complete file

– First half and second half of the file separately

– Middle one-third of the 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]

The block diagram to be created by students are:

The system block diagram is to be created as:

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.

Name: Date of Lab:

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.

How Does a GUI Work?

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.

Ways to Build MATLAB GUIs

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.

You can build MATLAB GUIs in two ways:

Use GUIDE (GUI Development Environment), an interactive GUI construction kit.

Create M-files that generate GUIs as functions or scripts (programmatic GUI

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:

Command line by typing guide


Start menu by selecting MATLAB > GUIDE (GUI Builder)
MATLAB File menu by selecting New > GUI
MATLAB toolbar by clicking the GUIDE button

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

Displays the following toolbar in the Layout Editor window.

Setting the GUI Size

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.

Component Icon Description


Push Button Push buttons generate an action when clicked. For example, an
OK button might apply settings and close a dialog box. When
you click a push button, it appears depressed; when you release
Toggle Button Toggle buttons generate an button
action appears
and indicate whether they are
the mouse button, the push raised.
turned on or off. When you click a toggle button, it appears
depressed, showing that it is on. When you release the mouse
button, the toggle button remains depressed until you click it a
second time. When you do so, the button returns to the raised
Radio Button Radio buttons are
state, showing thatsimilar toUse
it is off. check boxes,group
a button but radio buttons are
to manage
typically
mutually mutually
exclusiveexclusive within a ngroup of related radio
toggle buttons.
buttons. That is, when you select one button the previously
seleted button is deselected. To activate a radio button, click the
mouse button on the object. The display indicates the state of
Check Box Check boxes
the button. cana generate
Use an action
button group when mutually
to manage checked and indicate
exclusive
their state as checked or not checked. Check boxes are useful
radio buttons.
when providing the user with a number of independent choices,for
example, displaying a toolbar.

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.

Slider Sliders accept numeric input within a specified range by


enabling the user to move a sliding bar, which is called a slider or
thumb. Users move the slider by clicking the slider and dragging
it, by clicking in the trough, or by clicking an arrow. The location
of the slider indicates the relative location within the specified
range.

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.

M-Files and FIG-Files

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

the first time, GUIDE automatically opens the

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.

GUI M-File Structure

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

1-Put the following components in the figure.

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

4- The final design will be 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 .

7-The M file will open as follow

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

9-Run to see the plot of the functions.

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

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.

Name: Date of Lab:

Task 1:

Task 2:

Verified: Date/Time:

CEME (NUST), Rawalpindi 0


EE Department Signals and Systems

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:

CTFS representation of a periodic signal:


∞ ∞

𝑥(𝑡) = ∑ 𝑎𝑘 𝑒 𝑗 𝑘 𝑤𝑜 𝑡
= ∑ 𝑎𝑘 𝑒 𝑗 𝑘 ( T )𝑡
𝑘=−∞ 𝑘=−∞

Fourier Series Coefficients of a periodic signal:

1 𝑇/2 1 𝑇/2 2π
𝑎𝑘 = ∫ 𝑥(𝑡)𝑒 −𝑗 𝑘 𝑤𝑜 𝑡 = ∫ 𝑥(𝑡) 𝑒 − 𝑗 𝑘 ( T )𝑡 𝑑𝑡
𝑇 −𝑇/2 𝑇 −𝑇/2

Properties of the Continuous Time Fourier Series:

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

𝐹𝑆(𝑥(𝑡) 𝑦(𝑡)) = ∑ 𝑎𝑙 𝑏𝑘−𝑙


𝑙=−∞
2. Differentiation:
The Fourier Series representation of differentiation of a periodic signal x(t) is equal to –
jw*(Fourier Series of x(t)).
𝑑 𝑥(𝑡) 2π
𝐹𝑆 ( ) = 𝑗𝑘 𝑤𝑜 𝑎𝑘 = 𝑗 𝑘 𝑎
𝑑𝑡 𝑇 𝑘

CEME (NUST), Rawalpindi 1


EE Department Signals and Systems

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

The specifications of the two signals should be:

 x(t) = sin(πt)
 y(t) = cos(πt)
 The signal period Tp=2*pi
 Number of coefficients k=-10 to 10

CEME (NUST), Rawalpindi 2


EE Department Signals and Systems

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.

Name: Date of Lab:

Task 1:

Task 2:

Verified: Date/Time:

CEME (NUST), Rawalpindi 3


EE Department Signals and Systems

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:

DTFS representation of a periodic signal:


𝑁−1 𝑁−1

𝑥[𝑛] = ∑ 𝑎𝑘 𝑒 𝑗 𝑘 𝑤𝑜 𝑛
= ∑ 𝑎𝑘 𝑒 𝑗 𝑘 ( N )𝑛
𝑘=0 𝑘=0

Fourier Series Coefficients of a periodic signal:


𝑁−1 𝑁−1
1 1 2π
𝑎𝑘 = ∑ 𝑥[𝑛]𝑒 −𝑗 𝑘 𝑤𝑜 𝑛 = ∑ 𝑥[𝑛]𝑒 − 𝑗 𝑘 ( N )𝑛
𝑁 𝑁
𝑛=0 𝑛=0

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

Properties of the Discrete Time Fourier Series:

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

CEME (NUST), Rawalpindi 4


EE Department Signals and Systems

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

The specifications of the two signals are:

 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

CEME (NUST), Rawalpindi 5


EE Department Signals and Systems

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.

CEME (NUST), Rawalpindi 6


EE Department Signals and Systems

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.

Name: Date of Lab:

Task 1:

Task 2:

Task 3:

Verified: Date/Time:

CEME (NUST), Rawalpindi 7


EE Department Signals and Systems

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:

DTFT representation of a finite discrete signal (Analysis equation):


𝑁−1
𝑗𝑤
𝑋(𝑒 ) = ∑ 𝑥[𝑛]𝑒 −𝑗𝑤𝑛
𝑛=0

Calculation of a signal from its DTFT (Synthesis equation):


2𝜋
1
𝑥[𝑛] = ∫ 𝑋(𝑒 𝑗𝑤 )𝑒 𝑗𝑤𝑛 𝑑𝑤
2𝜋
0

Properties of the Discrete Time Fourier Transform:

There are many properties associated with the DTFT, in this lab the students will prove the
following two properties, where:

 x[n] and y[n] are two discrete time a-periodic signals


 𝑋(𝑒 𝑗𝑤 ) and 𝑌(𝑒 𝑗𝑤 ) are the DTFT representation of x[n] and y[n] respectively
1. Convolution Property:
This property states that the DTFT of convolution of two discrete time sequences is equal
to multiplication of the DTFTs of the sequences.
𝑥[𝑛] ∗ 𝑦[𝑛] = 𝐼𝐷𝑇𝐹𝑇 (𝑋(𝑒 𝑗𝑤 )𝑌(𝑒 𝑗𝑤 ))
2. Multiplication Property:
The DTFT of multiplication of two discrete time a-periodic signals is equal to the
periodic convolution of the DTFT of the individual signals.
2𝜋
1
𝑥[𝑛]𝑦[𝑛] = 𝐼𝐷𝑇𝐹𝑇 ( ∫ 𝑋(𝑒 𝑗𝜃 )𝑌(𝑒 𝑗(𝑤−𝜃) ) 𝑑𝜃)
2𝜋
0

CEME (NUST), Rawalpindi 8


EE Department Signals and Systems

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

which is illustrated below for 𝑁1 = 2.

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.

For Convolution Property:

 x[n]=[1 0 1 0 1]
 y[n]=[1 1 0 1 0]
 N is the length of the signal.

CEME (NUST), Rawalpindi 9


EE Department Signals and Systems

For Multiplication Property:

 x[n]=[1 2 3 1 3]
 y[n]=[3 4 3 3 2]
 N is the length of the signal.

CEME (NUST), Rawalpindi 10


EE Department Signals and Systems

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.

Name: Date of Lab:

Task 1:

Task 2:

Task 3:

Verified: Date/Time:

CEME (NUST), Rawalpindi 11


EE Department Signals and Systems

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:

The Continuous Time Fourier Transform is used for representation of continuous-time a-


periodic signals.

Fourier Transform of a continuous time signal (Analysis equation):



𝑋(𝑗𝑤) = ∫ 𝑥(𝑡)𝑒 −𝑗𝑤𝑡 𝑑𝑡
−∞

To calculate the Inverse Fourier Transform (Synthesis equation):



1
𝑥(𝑡) = ∫ 𝑋(𝑗𝑤)𝑒 𝑗𝑤𝑡 𝑑𝑤
2𝜋
−∞

Properties of the 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,

CEME (NUST), Rawalpindi 12


EE Department Signals and Systems

 x(t) is a continuous time a-periodic signal


 𝑋(𝑗𝑤) is the CTFT representation of x(t)

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.

CEME (NUST), Rawalpindi 13


EE Department Signals and Systems

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.

Name: Date of Lab:

Task 1:

Task 2:

Task 3:

Verified: Date/Time:

CEME (NUST), Rawalpindi 14


EE Department Signals and Systems

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:

1. Low pass Filters (LPF)


2. Band pass Filters (BPF)
3. High pass Filters (HPF)
1. Low Pass Filter:
A low pass filter, as its name suggests, is used to pass only the low frequency components of
a signal, and block all higher frequency components. The ideal low pass filter is shown
below:

2. Band Pass Filter:


A band pass filter is a filter that passes all frequencies of a signal within a certain range,
(which neither includes zero frequency nor pi), and block all other frequencies outside that
range. An ideal band pass filter is shown below:

CEME (NUST), Rawalpindi 15


EE Department Signals and Systems

3. High Pass Filter:


A high pass filter is used to pass all frequency components of a signal higher than a cutoff
frequency, and stop all other frequency components which are lower than the cutoff
frequency. An ideal high pass filter is shown below:

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:

a) A Low Pass Filter with pass band (f < 1500 Hz)


b) A Band Pass Filter with pass band (1500 < f < 3000 Hz)
c) A High Pass Filter with pass band (f > 3000 Hz)

CEME (NUST), Rawalpindi 16


EE Department Signals and Systems

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.

CEME (NUST), Rawalpindi 17


EE Department Signals and Systems

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.

Name: Date of Lab:

Task 1:

Task 2:

Verified: Date/Time:

CEME (NUST), Rawalpindi 18


EE Department Signals and Systems

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:

A transfer function is a mathematical function relating the output or response of a system,


such as a filter, to the input. For example:

X(s) Transfer Function Y(s)


H(s)

Hh
Where,

Y(s)= H(s) X(s)


𝑌(𝑠)
and 𝐻(𝑠) = 𝑋(𝑠)

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:

Using ‘tf’ command:


𝑠+1
6𝑠 5 + 5𝑠 4 + 4𝑠 3 + 3𝑠 2 + 2𝑠 + 1
Using ‘zpk’ command:
2(𝑠 − 1)(𝑠 − 2)
(𝑠 + 1)(𝑠 + 2)(𝑠 + 3)(𝑠 + 4)(𝑠 + 5)

CEME (NUST), Rawalpindi 19


EE Department Signals and Systems

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

CEME (NUST), Rawalpindi 20


EE Department Signals and Systems

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.

Name: Date of Lab:

Task 1:

Task 2:

Verified: Date/Time:

CEME (NUST), Rawalpindi 21

You might also like