EGR3305-Lab-1-Fall 2023

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 16

AL AKHAWAYN UNIVERSITY

School of Science and Engineering

EGR 3305, Signals and Systems


Laboratory

FALL 2023

Note: Students are required to submit the lab report before


Thursday 7th December 2023

1
Signals and Systems Laboratory

Objectives:
Signals and Systems Labs introduce students to modeling and analysis of signals and
systems. The laboratory experiments are designed to provide students with a practical
experience to apply signals and systems theory introduced in lectures and tutorials. In this
regard, MATLAB and Simulink will be used to

 characterize various continuous and discrete time signals.


 gain experience applying various modeling techniques including time and frequency
domains analysis.
 generate, perform signal operations, analyze, and interpret signals in both time and
frequency domains, analogue and digital forms.
 analyze the spectral characteristics of signals using Fourier analysis.
 use MATLAB/Simulink Tools to study and analyze engineering systems using
Laplace transform.
 study filtering and other forms of signal conditioning using MATLAB/Simulink
Tools.
 Analysis of simple feedback systems to establish stability in engineering systems.

EQUIPMENT AND SOFTWARE TOOLS:

1. Laptop
2. MATLAB and SIMULINK

2
Introduction:
MATLAB provides a variety of commands that allow controlling the flow of commands
in a program. The most common construct is the if-elseif-else structure. With these
commands, we can allow different blocks of code to be executed depending on some
condition. The format of this construct is

if condition1
command1
elseif condition2
command2
else
command3
end

which executes statements in command1 if condition-1 is satisfied; otherwise, statements


in command2 if condition-2 is satisfied, or finally statements in command3.

Another common control flow construct is for ... end loop. It is simply an iteration loop
that tells the computer to repeat some task a given number of times. The format of a
for...end loop is

for index = values


program statements
:
End

Scripts

MATLAB Scripts are implemented using a script file called an m-file (with an
extension .m), which is only a text file that contains each line of the file as though you
typed them at the command prompt. These scripts are created using MATLAB’s built-in
editor, which also provides for context-sensitive colors and indents for making fewer
mistakes and for easy reading. The script is executed by typing the name of the script at
the command prompt. The script file must be in the current directory on in the directory
of the path environment.

3
Elementary Sequences:
We use several elementary sequences in signals and systems for analysis purposes. Their
definitions and MATLAB representations are as follows:

Unit Impulse sequence


function [x,n] = impseq(n0,n1,n2)
% Generates x(n) = delta(n-n0); n1 <= n,n0 <= n2
% [x,n] = impseq(n0,n1,n2)
if ((n0 < n1) | (n0 > n2) | (n1 > n2))
error('arguments must satisfy n1 <= n0 <= n2')
end
n = [n1:n2];
x = [(n-n0) == 0];

Unit Step sequence


function [x,n] = stepseq(n0,n1,n2)
% Generates x(n) = u(n-n0); n1 <= n,n0 <= n2
% [x,n] = stepseq(n0,n1,n2)
if ((n0 < n1) | (n0 > n2) | (n1 > n2))
error('arguments must satisfy n1 <= n0 <= n2')
end
n = [n1:n2];
x = [(n-n0) >= 0];

Complex exponential sequence


function [x,n] = stepseq(n0,n1,n2)
% Generates x(n) = u(n-n0); n1 <= n,n0 <= n2
% [x,n] = stepseq(n0,n1,n2)
if ((n0 < n1) | (n0 > n2) | (n1 > n2))
error('arguments must satisfy n1 <= n0 <= n2')
end
n = [n1:n2];
x = [(n-n0) >= 0];

4
MATLAB Functions

The second construct of creating a block of code is through subroutines. These are called
functions, which also allow us to extend the capabilities of MATLAB. In fact, a major
portion of MATLAB is assembled using function files in several categories and using
special collections called toolboxes. Functions are also m-files (with extension .m).

A major difference between script and function files is that the first executable line in a
function file begins with the keyword function followed by an output-input variable
declaration.

Plotting
One of the most powerful features of MATLAB for signal and data analysis is its
graphical data plotting. MATLAB provides several types of plots, starting with simple
two-dimensional (2D) graphs to complex, higher dimensional plots with full-color
capability. We will examine only the 2D plotting, which is the plotting of one vector
versus another in a 2D coordinate system. The basic plotting command is the plot(t, x)
command, which generates a plot of x values versus t values in a separate figure window.
The arrays t and x should be the same length and orientation. Optionally, some additional
formatting keywords can also be provided in the plot function. The commands xlabel and
ylabel are used to add text to the axis, and the command title is used to provide a title on
the top of the graph. When plotting data, one should get into the habit of always labeling
the axis and providing a title. Almost all aspects of a plot (style, size, color, etc.) can be
changed by appropriate commands embedded in the program.

The following set of commands creates a list of sample points, evaluates the sine function
at those points, and then generates a plot of a simple sinusoidal wave, putting axis labels
and title on the plot.

Example-1:
t = 0:0.01:2; % sample points from 0 to 2 in steps of 0.01
x = sin(2*pi*t); % Evaluate sin(2 pi t)
plot(t,x, 'b '); % Create plot with blue line
xlabel('t in sec '); ylabel('x(t) '); % Label axis
title('Plot of sin(2\pi t) '); % Title plot

5
For plotting a set of discrete numbers (or discrete-time signals), we will use the stem
command which displays data values as a stem, that is, a small circle at the end of a line
connecting it to the horizontal axis. The circle can be open (default) or filled (using the
option ’filled’). Using Handle Graphics (MATLAB’s extensive manipulation of graphics
primitives), we can resize circle markers. The following set of commands displays a
discrete-time sine function using these constructs.

Example-2:
n = 0:1:40; % sample index from 0 to 40
x = sin(0.1*pi*n); % Evaluate sin(0.2 pi n)
Hs = stem(n,x, 'b', 'filled'); % Stem-plot with handle Hs
set(Hs, 'markersize',4); % Change circle size
xlabel('n'); ylabel('x(n) '); % Label axis
title('Stem Plot of sin(0.2 \pi n) '); % Title plot

MATLAB provides an ability to display more than one graph in the same figure window.
By means of the hold on command, several graphs can be plotted on the same set of axes.
The hold off command stops the simultaneous plotting. The following MATLAB
fragment displays graphs in as one plot, depicting a “sampling” operation.

Another approach is to use the subplot command, which displays several graphs in each
individual set of axes arranged in a grid, using the parameters in the subplot command.
The following fragment displays graphs in as two separate plots in two rows.

Example-3:
clc;
t = 0:0.01:2; % sample points from 0 to 2 in steps of 0.01
x = sin(2*pi*t); % Evaluate sin(2 pi t)
subplot(2,1,1); % Two rows, one column, first plot
plot(t,x, 'b '); % Create plot with blue line
xlabel('t in sec '); ylabel('x(t) '); % Label axis
title('Plot of sin(2\pi t) '); % Title plot
hold on
n = 0:1:40; % sample index from 0 to 20
x = sin(0.1*pi*n); % Evaluate sin(0.2 pi n)
subplot(2,1,2); % Two rows, one column, second plot
Hs = stem(n,x, 'b', 'filled'); % Stem-plot with handle Hs
set(Hs, 'markersize',4); % Change circle size

6
xlabel('n'); ylabel('x(n) '); % Label axis
title('Stem Plot of sin(0.2 \pi n) '); % Title plot
hold off

The plotting environment provided by MATLAB is very rich in its complexity and
usefulness. Therefore, readers are strongly recommended to consult MATLAB’s manuals
on plotting. Many of these constructs will be used throughout this book. In this brief
review, we have barely made a dent in the enormous capabilities and functionalities in
MATLAB. Using its basic integrated help system, detailed help browser, and tutorials, it
is possible to acquire sufficient skills in MATLAB in a reasonable amount of time.

7
Purpose
The goal of this lab is to become familiar with computations and plotting using
MATLAB and Simulink software commands. You will investigate operations on signals
and delve into several elementary continuous and discrete-time signals. These signals are
essential for modeling numerous physical phenomena found in nature.

- Accessing MATLAB:
(1) Click on the Start button in the lower left portion of the screen.
(2) Select Programs -> Matlab -> MATLAB from the cascading menus. The MATLAB Command
Window will appear. This is the window in which you can enter commands.

Create an M-file

- To create a new MATLAB script:


From the menu bar at the top of the MATLAB command window, Click on the New Script:

This activates the MATLAB “M-File Editor/Debugger” program. A separate window will appear in which
you can type your m-file. This is like a specialized “word processor” for writing MATLAB m-files. Note
that you now have two different windows to work in: the MATLAB command window and the M-file
Editor/Debugger window.

An m-file, or script file, is a simple text file where you can place Matlab commands. When the file is run,
Matlab reads the commands and executes them exactly as it would if you had typed each command
sequentially at the Matlab prompt. All m-file names must end with the extension '.m' (e.g. plot.m). If you
create a new m-file with the same name as an existing m-file, Matlab will choose the one which appears
first in the path order (help path for more information). To make life easier, choose a name for your m-file
which doesn't already exist. To see if a filename.m exists, type helps filename at the Matlab prompt.

8
Procedure-1

1. Create MATLAB scripts for examples 1, 2 and 3.


 From the menu bar at the top of the MATLAB command window, save your
“Files As” and type ‘example1’ for Example-1.
 Repeat step “1” for Example 2 and 3.
2. To execute an m-file:
 Go to the MATLAB command window. From the menu bar at the top, ->
Click on “Run.”

3. Save the obtained plots and analyze your results.

Answers-1

9
Procedure-2: Signal Operations

The primary objective of this problem is to delve into the foundational concepts of signal
processing, specifically focusing on the effects of time delays and scaling on signals.

By experimenting with various values of time shifts ( t0) and scaling factors (a), you will
gain a hands-on understanding of how these transformations impact the signal's shape
and behavior.

To achieve this understanding, you will utilize two MATLAB codes: input_signal.m,
which defines the signal, and signal_operations.m, which applies the transformations
and visualizes the results.

input_signal.m

function y = input_signal(t)
if t < -1 || t > 1
y = 0;
elseif t == 1
y = 1;
else
y = 0.5*t + 0.5;
end
end
signal_operations.m

% Create a time vector


T = linspace(-10, 10, 1000);
L = length(T);
x = zeros(1, L); % reserve some space for x

a = 1; t0 = 0; % initial values

% Compute x as f(a*t+t0)
for k = 1:L
x(k) = input_signal(a*T(k) + t0);
end

% Plotting the signal

10
figure;
plot(T, x);
xlabel('Time');
ylabel('Amplitude');
axis([-5 5 -3 3 ])
grid on;

1. Setup:
o Ensure both input_signal.m and signal_operations.m are saved in the
same directory.
2. Experimentation:
o Modify the values of a and t0 in the signal_operations.m script to
study the effects of different time shifts and scaling factors on the signal.
o Recommended values to experiment with:
 a=1, t0=0
 a=1, t0=+2
 a=1, t0=-2
 a=-1, t0=0
 a=-1, t0=2
 a=-1, t0=-2
 a=1/2, t0=0
 a=2, t0=0
3. Visualization:
o After modifying the values of a and t0, run the signal_operations.m
script to visualize the transformed signal and analyse the obtained result.

11
Answers-2

12
Procedure-3

The primary objective of this experiment is to determine whether a given system is linear.
A system is deemed linear if it satisfies two fundamental conditions: homogeneity and
additivity. If the system does not meet even one of these conditions for any given input, it
is termed non-linear.

Experiment with Simulink:

Consider a system characterized by the following equation:

y(t) =2 x(t) + 1

In this equation, x(t) represents the input signal, while y(t) denotes the output signal.

System Setup:

1. Open Simulink: Start MATLAB and subsequently open Simulink.


2. Create a New Model: Navigate to "New" and select "Model."
3. Add Components as shown in Figure Q-3:
 Drag a "Sine Wave" block from the "Sources" library to represent the
input.
 Set the parameters of the sine generator as follow:

o Amplitude: 1V,
o Frequency (rad/sec): 1, Phase: 0
o Sample time: 0

 Drag a "Gain" block from the "Math Operations" library for the
multiplication operation.
 Drag a "Sum" block from the "Math Operations" library for the addition
operation.
 Connect these blocks in the following sequence: Sine Wave -> Gain ->
Sum.
 Set the value of the Gain block to 3.
 For the Sum block, configure one of its inputs to have a constant value of
1.

13
Figure Q-3

4. Create a Subsystem: Highlight all the blocks, right-click, and select "Create
Subsystem."

Questions:

1. Using the Simulink model of the system, determine if the system is homogeneous.
Provide justification for your answer.
2. Evaluate if the system exhibits additivity. Elaborate on your response with
appropriate reasoning.

Answers-3

14
Procedure-4

The primary objective of this experiment is to determine whether a given system is


time-invariant. To ascertain if a system is time-invariant, one must input a signal into the
system, obtain the output, and then delay this output by a value, τ. Concurrently, the input
is also delayed by τ and then processed through the system. If the two resulting outputs
match, the system is time-invariant.

Experiment with Simulink:

Consider a system characterized by the following equation:

y(t)=x(t) × sin(2πt)

where y(t) is the output signal, x(t) is the baseband input signal, and sin(2πt) is the sine
wave with a frequency of 1.

For the time-invariance test, the system's output is delayed by τ and the input is also
delayed by τ. The system is considered time-invariant if the outputs from both these
setups match. In this case, they did not, leading to the conclusion that the system is time
varying.

System Setup:

 Open Simulink: Start MATLAB and then open Simulink.


 Create a New Model as shown in Figure Q-4: Click on "New" > "Model."
 Add Components:
o Drag a "Step" block from the "Sources" library for the input.
o Drag a "Sine Wave" block from the "Sources" library.
o Drag a "Product" block from the "Math Operations" library to multiply the
step input with the sine wave.
o Connect these blocks in sequence: Step -> Product (first input), Sine Wave
-> Product (second input).
o Add a "Scope" block from the "Sinks" library and connect it to the Product
block's output.
o A "Variable Time Delay" block from the continuous menu is introduced.
o The top input of this block receives the signal, while the bottom input
determines the delay value, τ. For this experiment, τ is arbitrarily set to 3.

15
 A constant block, set to the value of 3, feeds into the delay block to
establish the delay.
o The delayed output is then visualized using a scope.

Figure Q-4

 Create a Subsystem: Select the appropriate blocks to create the mean Subsystem
and the delay Subsystem.

Question:

Using the Simulink model of the system, determine if the system is time-invariance.
Provide justification for your answer.

Answers-4

16

You might also like

pFad - Phonifier reborn

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

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


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy