Signal and System Manual
Signal and System Manual
Submitted To:
Engr. Kiran Arshad
Submitted By:
Muhammad Abdullah
BEEF18M032
Credit Hours 1
Contact Hours 3
Course Objectives:
CLO-1: To implement, perform and verify the basic MATLAB graphics, theorems, signals
systems and transforms on MATLAB software.
2 Demonstrate the use of MATLAB Graphics and Implementation of Basic Signals in MATLAB.
6 Implementation of Moving Average System and Convolution in MATLAB (With and Without
Built in Command).
Implementation of Auto and Cross Correlation of signals in MATLAB.
7
(With and Without Built in Command)
10 Demonstration of Simulink and Implementation of its building blocks for signal processing.
MATLAB COMMAND:
linspace (5,8)
RESULT:
MATLAB COMMAND:
eye (3,4)
RESULT:
1 0 0 0
0 1 0 0
0 0 1 0
Some other Matlab commands and their function are shown in Table 1.3.
Table 1.3: Matlab commands and their function
Commands Functions
Linspace Creates regularly spaced vector
Logspace Creates logarithmically spaced vector.
Length Computers number of elements
Eye Creates an identity matrix
Ones Creates an array of ones
Zeros Creates an array of ones. Zeros
Print Prints plot or saves plot to a file title
Xlabel Adds text label to x-axis.
Ylabel Adds text label to y-axis.
plot Generates xy plot
Loglog Create loglog plot
Semilog Create semilog plot
Lab Task
Task 1: Write a MATLAB function of your name that inputs two variables x and y. Call these
variables x and y in command window to plot the sine and cosine waves. (Range of x and y can
be from 0 to 2*pi).
Task 2: Write a MATLAB function that inputs two variables x and y. Call these variables x and
y in command window that performs the following operation x2+y2. (Use x=left digit of your
registration number and y=right digit of your registration number)
TASK 1:
TASK 2:
Conclusion
MATLAB (matrix laboratory) is a fourth-generation high-level programming
language and interactive environment for numerical computation,
visualization and programming.It allows matrix manipulations; plotting of
functions and data; implementation of algorithms; creation of user interfaces;
interfacing with programs written in other languages, including C, C++, Java,
and FORTRAN; analyze data; develop algorithms; and create models and
applications.
It has numerous built-in commands and math functions that help you in
mathematical calculations, generating plots, and performing numerical
methods.
…………………….
Comments
MATLAB is widely used as a computational tool in science and engineering
encompassing the fields of physics, chemistry, math and all engineering
streams. It is used in a range of applications including −
Legends
LEGEND(string1,string2,string3, ...) puts a legend on the current plot using the specified strings
as labels.
Add a legend to the graph identifying each data set using the legend function. Specify legend
descriptions in the order that you plot the lines.
x=0:0.1:2*pi;
y=sin(x)
z=cos(x)
plot(x,y,'-g.',x,z,'--r*')
legend('y=sin(x)','z=cos(x)')
Its output graph is shown below in Fig. 2.6.
Fig. 2.6: Use of legends in graph
Data Exploration
Display Data Values Interactively:
Data cursors enable you to read data directly from a graph by displaying the values of points you
select on plotted lines, surfaces, images, and so on. You can place multiple data tips in a plot and
move them interactively. If you save the figure, the data tips in it are saved, along with any other
annotations present.
Enabling Data Cursor Mode:
Once you have enabled data cursor mode, clicking the mouse on a line or other graph object
displays data values of the point clicked. Clicking elsewhere does not create or update data tips
as shown in Fig. 2.7.
Fig. 2.7: Graph showing data cursor
Using multiple data tips
• Use the following procedure to create multiple data tips.
• Enable data cursor mode from the figure toolbar. The cursor changes to a cross.
• Click on the graph to insert a data tip.
• Right-click to display the context menu. Select Create New Data tip.
• Click on the graph to place the second data tip. e way to annotate a number of points on a
graph.
Input Command
Input command gives the user the prompt in the text string and then waits for input from the
keyboard.
The input can be any MATLAB expression, which is evaluated, using the variables in the current
workspace, and the result returned in any variable e.g.
D = input('No of days')
Signal:
Signal is basically a pattern of variation of some form e.g. Electrical signals:
Voltages and currents in a circuit
Electrical representation of a signal is:
Continuous Signal
Signals that vary continuously over specified range. They are represented by small parenthesis in
SNS. i.e x(t), y(t) etc.Represented by Amplitude, frequency and phase. In MATLAB, plot
command is used. Continous signal is shown in Fig. 2.8.
Fig. 2.8: Continuous signal
Discrete Signal
It represents discrete or discontinuous quantities. They are represented by large square brackets
in SNS. i.e. x[t], y[t] etc. They are represented by Amplitude and location of samples. In
MATLAB, stem command is used. Discrete signal is shown in Fig. 2.8.
TASK 1:
TASK 2:
TASK 3:
a=1
a>1
a<1
a=-1
TASK 4:
Comments
In this lab we studied introduction to line specification commands to alter line
color, marker symbol, marker style. The lab also provides an introduction to basic
signals like unit step and unit impulse signal and how they are made.
We studied line specification, line style, line color, line markers, legends , data
exploration,
input comman etc. And we wrote some basic matlab codes. Matlab is an
interpreted language for numerical computation. It allows one to perform
numerical calculations, and visualize the results without the need for complicated
and time consuming programming. Matlab allows its users to accurately solve
problems, produce graphics easily and produce code effeciently.
…………………………….
Conclusion
MATLAB is a tool for technical computing, computation and visualization in an
integrated environment. MATLAB is an abbreviation for MATrix LABoratory, so
it is well suited for matrix manipulation and problem solving related to Linear
Algebra, Modelling, Simulation and Control applications, etc.
…………………………….
Experiment # 03
Demonstration and Implementation of loops and decision making in
MATLAB
Objective
In this lab we will study about loops. Loops are concerned with the concept of iteration. There
are two most prominent types of loop in Matlab and these are for and while loop. In this lab we
will also study about the basic concept of conditional statement also called if-else statement.
Apparatus
PC having MATLAB
Theory
Much like C or FORTRAN we can use loop syntax to repeat a sequence of commands. However,
MATLAB is not efficient in executing loop operations. In other words, we can say that using
loops in MATLAB is very slow. There are two basic types of loops. Counted loops also called
‘for loop’ and Conditional loops also called ‘while loop’.
“For” LOOP:
The ‘for’ loop allow us to repeat certain commands. If you want to repeat some action in a pre-
determined way, you can use the ‘for’ loop. All of the loop structures in MATLAB are started
with a key word such as ‘for’ or while’ and they all end with the word ‘end’.
The ‘for’ loop will loop ground some statement, and you must tell MATLAB where to start and
where to end. Basically, you give a vector in the ‘for’ statement and MATLAB will loop through
for each value in the vector. The ‘for’ loop Matlab syntax is:
for var = start:end
commands;
end
Example 3.1:
>>for j=1:4,
j
end
Output:
j=
1
j=
2
j=
3
j=
4
Note: Once the MATLAB reads the ‘end’ statement, it will loop through and print out j each
time. For another example, if we define a vector and data want to change the entries, we can step
through and change each individual entry.
Example 3.2:
v= 1:3:10
for j=1:4,
v(j) =j;
end
Result: The output shows the values of vector v from1 to 10 with the space of 3.
Output:
v=
1 4 7 10
Important Note: Using loops in MATLAB are not efficient. Loops cause the programs to run
very slow. Always use some alternative way so that programs run fast.
Example 3.4:
clc
clear all
close all
x=20:20:200;
total =length(x);
temp=0;
for i=1:total
temp =temp+x(1);
temp
end
Result: init we define the vector x whose values are between 20 and 200 with the interval of 20
and the loop run length of x times and add the numbers and display it in the output.
Output:
x=
20 40 60 80 100 120 140 160 180 200
temp =
1100
Prescription:
In example 4 we define a vector ‘x’ with values,
x = [20 to 60 80 100 120 140 160 180 200]
then we use “total = length(x)”. In this statement we are calling the “length” function. This will
return the total number of elements in ‘x’ & assign it to the total variable. Then we define a
‘temp’ variable and set it to ‘o’, using “temp = 0” statement.
Then we use a ‘for’ loop & using this ‘for’ loop we add the x (i) value to temp and reassign that
value to temp again.
While LOOP:
The “while” loop repeats a sequence of commands as long as some condition is met. The while
loop Matlab syntax is:
while expression
commands;
end
Example 3.5:
j=1;
while(j<=4)
a(j)=10*j;
j=j+1;
end
a
Output:
a=
10 20 30 40
Result: The loop run four times and each time multiply the index with ten and display it in the
output.
The while loop continues to execute until the value of j becomes greater than 4. When this
happens the loop exits. The above ‘while’ loop body will execute until the condition “j < = 4”.
When this condition becomes false the ‘while’ loop will stop executing.
Example 3.6:
a=1:10
i=1;
while(i<=10)
b(i)=2^a(i);
i=i+1;
end
b
Output:
a=
1 2 3 4 5 6 7 8 9 10
b=
2 4 8 16 32 64 128 256 512 1024
Result: The loop will run less than or equal to 10 times, taking that number as the power of 2
find result and display it.
Description: The above example declares a vector
a = [1 2 3 4 5 6 7 8 9 10].
Then using a “while” and tells that loop until the value of ‘i’ is less than or equal to 10. Then
using the statement “b (i) = 2 a (i)” & “i = i + 1" it makes another vector having values.
b = [21 22 23 24 25 26 27 28 29 210] at the end it displays the value of ‘b’
IF Statement:
We can make decisions by using the ‘if’ statement. The ‘if’ must be terminated with an ‘end’
statement.
Example 3.7
c=2;
if(c==1)
disp('c is 1')
elseif (c==2)
disp('c is 2')
else
disp('c is neither 1 nor 2');
end
Output: c is 2
Result: init we use the if-else command and check the value of c.
The above example declares a variable ‘c’ & assigns it a value ‘2’ by using “c = 2”.
Then it uses ‘if’, if-‘else’ and ‘else’ statements to check the value of ‘c’ and displays the result
using “disp” command.
Joseph Fourier:
Joseph Fourier showed that any periodic signal could be represented by a series of sinusoidal
functions. The figure shows how odd harmonics of sine waves are added to give a square wave.
Example 3.8
Square wave
A square wave can be constructed from multiple sine waves at different frequencies. The sine
waves added in addition to the fundamental frequency are called harmonics; a square wave has
harmonics at odd multiples of the fundamental frequency. As higher harmonics are added, the
result gets closer to an ideal square wave, which contains infinite harmonics.
Example 3.9
Write a MATLAB code to generate a square wave having user defined amplitude… Use for loop
to add up the sine waves…
EXERCISE:
E.1. Define a vector a = [1 2 3 4 5] and then using a “for” loop create another vector ‘b’ haring
the following values corresponding to ‘a’.
E.2. Without using a “for” loop and using some alternative method define vector
a = [1 2 3 4 5] and create b1 = []
E.3. Indicate the error in the following. Tell the line # which contains the error and what is the
error.
1.......v=0:2:10
2.......for c=1:length(v)
3........ v(c-1)=v(c)+5;
4........end
5........v
E.4. Refer to the “example 4”. We have vector
x = [20 40 60 80 100 120 140 160 180 200] and we want to multiply all the elements of the
vector ‘x’ e.g. (20 x 40 x 60 …………. x 200) and store the result in temp. Modify the code for
“example 4” so that it performs the above task.
E.5. Refer to “example 6”. Change the code so that it creates vector ‘b’ having values
b = [51 52 53 …………. 510].
E.6. What will be the output of “example 7” if we define C = 3 and other code remains
unchanged?
Comments
The FOR loop is nicer and more compact, if the number of iterations is known
before the loop is started. The WHILE loop is nicer, when the number of
iterations is determined inside the loop. There are some overlaps, e.g. running
an iteration until a certain number of loops or a specific criterion is reached.
Then usually WHILE is preferred with the convergence limit as test, because
this reflects the main character of the loop, while the limitation of iterations is
a fallback mechanism only.
……………………….
Conclusion
In this lab we studied about For loop and While loop in Matlab.
we performeed some examples and got the results.
END
……………………….
Experiment # 04
Objective
In this lab we will studied about the concept of time shifting, scaling and reversal and their
implementation. This lab also provide us introduction about the even and odd signal and their
manipulation. In this lab we will also study that a signal is the combination of even and odd
components and how we can break signal into even and odd component.
Apparatus
Pc having MATLAB
Theory
Signal Operations are simply modifications to the time variable of the signal to generate new
signals. These are pretty similar to the mathematical graphical transformations. The three kinds
of Signal Operations are Time Shifting, Time Scaling and Time reversal.
• Time shifting:
Time Shifting is simply shifting the signal in time. If a continuous time signal is defined as:
y(t) = x(t - to)
Then we can say that y(t) is the time shifted version of x(t).
• When to be greater than zero then signal shifts to the right and the signal obtained is
called delayed signal.
• When to be less than zero then signal shifts to the left and the signal obtained is called
advanced signal.
• Or we can define it as when we add a constant to the time, we obtain the advanced signal,
& when we decrease the time, we get the delayed signal.
For example: If we want to shift the signal then in MATLAB we can write the code as:
t=-10:0.01:10
f=0.1
to=2
tt=-2
x=sin(2*pi*f*t)
y=sin(2*pi*f*(t-to))
z=sin(2*pi*f*(t-tt))
subplot(311)
plot(t,x)
subplot(312)
plot(t,y)
subplot(313)
plot(t,z)
Its output graph is shown in Fig. 4.1.
Example: If we want to scale the signal then in MATLAB we can write the code as:
t=-10:0.01:10
f=0.1
a=1.5
x=sin(2*pi*f*t)
y=sin(2*pi*f*(a*t))
z=sin(2*pi*f*(t/a))
subplot(311)
plot(t,x)
title('orignal signal')
subplot(312)
plot(t,y)
title('compressed signal')
subplot(313)
plot(t,z)
title('expanded signal')
Its output is shown in Fig. 4.2.
Fig. 4.2: Time scaling
• Time reversal:
The reversing or flipping the time indexes is called flipping or time reversal.
We can define it as: y(t) = x(-t). in matlab for reversal we use the “fliplr” command.
Example
t=-10:0.01:10
f=0.1
a=1.5
x=sin(2*pi*f*t)
y=fliplr (x)
z=sin(2*pi*f*(-t))
subplot(131)
plot(t,x)
title('orignal signal')
subplot(132)
plot(t,y)
title('by builtin command')
subplot(133)
plot(t,z)
title('flipped signal')
Its output is shown in Fig. 4.3.
Fig. 4.3: Time reversal
Even signal
If a signal becomes equal to the flipped version of itself, it is called even signal. We can
mathematically define it as: x(t) = x(-t)
Odd signal
If the flipped version of the signal becomes equal to the signal that is amplitude scaled by -1,
then the signal is called odd signal. Mathematically we can define it as: x(-t) = -x(t).
Conventially any signal is the combination of even and odd component. We can break the break
the signal into its even and odd parts. The even part of a signal can be expressed:
Xe (t) = 1/ 2 [x(t) + x (−t)]
And the odd part of the signal can be expressed as:
Xo (t) = 1/ 2 [x (t) − x (−t)]
Task: Solve for whether the signal is even or odd or combination of both.
• Cos(2*pi*f*time)
• sinc(2*pi*f*time)
• square(2*pi*f*time)
• sin(2*pi*f*time) .* sinc(2*pi*f*time)
• cos(2*pi*f*time) .*square(2*pi*f*time)
CODE:
function k=lab4tasksns()
t=-10:0.01:10
f=0.1
x=cos(2*pi*f*t)
a=fliplr(x)
subplot(5,2,1)
plot(t,x)
title('original signal cos(2*pi*f*t)')
subplot(5,2,2)
plot(t,a)
title('reversed signal')
y=sinc(2*pi*f*t)
b=fliplr(y)
subplot(5,2,3)
plot(t,y)
title('original signal sinc(2*pi*f*t)')
subplot(5,2,4)
plot(t,b)
title('reversed signal')
z=square(2*pi*f*t)
c=fliplr(z)
subplot(5,2,5)
plot(t,z)
title('original signal z=square(2*pi*f*t)')
subplot(5,2,6)
plot(t,c)
title('reversed signal')
p=sin(2*pi*f*t).*sinc(2*pi*f*t)
q=fliplr(p)
subplot(5,2,7)
plot(t,p)
title('original signal sin(2*pi*f*t).*sinc(2*pi*f*t)')
subplot(5,2,8)
plot(t,q)
title('reversed signal')
m=cos(2*pi*f*t).*square(2*pi*f*t)
n=fliplr(m)
subplot(5,2,9)
plot(t,m)
title('original signal cos(2*pi*f*t).*square(2*pi*f*t)')
subplot(5,2,10)
plot(t,n)
title('reversed signal')
OUTPUT:
Task 1:
Take the values n = (-3 -2 -1 0 1) and x= (7 -6 5 0 -1); use plot command to get the continuous
shaped signal as shown below. Then write a MATLAB code to get the time reversed signal:
(i) by reversing n indexes (ii) by using fliplr command.
CODE:
function f=lab4sns()
n=[-3,-2,-1,0,1]
x=[7,-6,5,0,-1]
subplot(3,1,1)
plot(n,x)
title('Original continuos signal')
xlabel('time')
ylabel('amplitude')
z=[3,2,1,0,-1]
subplot(3,1,2)
plot(z,x)
title('Reverse signal by reversing indices of n')
xlabel('time')
ylabel('amplitude')
y=fliplr(n);
subplot(3,1,3)
plot(y,x)
title('Reverse signal by using fliplr')
xlabel('time')
ylabel('amplitude')
OUTPUT:
Task 2:
Let n = [-3 -2 -1 0 1 2]; x = [-7 5 -1 -4 4 3]; Use stem command to plot it in first window. Then
time scale (Compressed concept) this signal by 2. i.e x[2n] and plot the scaled signal in 2 nd
window. Also time scale this signal by x[n/2] and plot in 3rd window.
OUTPUT:
Comments
MATLAB can be used to perform shifting of signals. A signal can be delayed
as well as advanced.
The basic idea is to add the shift value to indices and thereby plotting the
signal.The inbuilt function fliplr() function can be used to perform
reversing or folding a signal.
Syntax:
fliplr(a) : if a is row vector it returns a vector with the same size of a but with
reversed order.
if a is column vector it flips the elements one column to the other.
Basic idea :
flip the elements
flip the indices with a ‘ – ‘ sign.
……………………………….
Conclusion
Time scaling of signals of signals involves the modification of a periodicity of
the signal, keeping its amplitude
constant. Its mathematically expressed as,
Y (t) = βX(t)
Where, X(t) is the original signal, and β is the scaling
factor. If β > 1 implies, the signal is compressed. And
if β < 1 implies, the signal is expanded.
Following example will help you understand the time
scaling property with the help of MATLAB’s has a builtin function tripuls to
generate a triangular pulse.
Experiment # 05
Implementation of Laplace Transform and Partial Fraction in MATLAB
Objective
In this lab we will study about partial fraction and Laplace transform. We will study about how
to represent them in MATLAB.
Apparatus
PC having MATLAB
Theory
Laplace Transform
Laplace transform will convert a function in some domain into a function in another domain,
without changing the value of the function. For example, let’s take this function where a Laplace
transform is used to convert a function of time to a function of frequency.
L {cos(wt)} = w / (s² + w²)
Why do we use Laplace Transform?
• We use Laplace transform to convert equations having complex differential equations to
relatively simple equations having polynomials. Since equations having polynomials are
easier to solve, we employ Laplace transform to make calculations easier.
• With Laplace transform nth degree differential equation can be transformed into an nth
degree polynomial. One can easily solve the polynomial to get the result and then change it
into a differential equation using inverse Laplace transform.
• The development of the logarithm was considered the most important development in
studying astronomy. In much the same way, the Laplace transform makes it much easier
to solve differential equations.
• The amazing thing about using Laplace transforms is that we can convert the whole ODE
initial value problem (I.V.P) into Laplace transformed functions of s, simplify the algebra,
find transformed solution F(s) the undo the transform to get back to the required solution f as
a function of t.
• If O.D.E is solved, particular and Homogeneous solutions are calculated separately but
LAPLACE finds both simultaneously.
• Normally, Homogeneous response is transient response and particular corresponds to steady
state. So, if solving in Time Domain, we first find time domain solution then apply initial
conditions but LAPLACE directly includes initial conditions.
• A Laplace transform is a type of integral transform. (Unilateral).
How to take the Laplace of functions in MATLAB:
• In MATLAB the command laplace is used.. While ilaplace is used for inverse of laplace..
Recall syms and pretty command from lab 01.
Example 5.1: Take the Laplace Transform of e^-t.
Output:
Partial Fraction
In algebra, the partial fraction decomposition or partial fraction expansion of a rational
function (that is, a fraction such that the numerator and the denominator are both polynomials) is
an operation that consists of expressing the fraction as a sum of a polynomial (possibly zero) and
one or several fractions with a simpler denominator.
The importance of the partial fraction decomposition lies in the fact that it
provides algorithms for various computations with rational functions, including the explicit
computation of anti-derivatives, Taylor series expansions, inverse Z-transforms, inverse Laplace
transforms.
Transfer function
A Transfer Function is the ratio of the output of a system to the input of a system, in the Laplace
domain considering its initial conditions and equilibrium point to be zero. If we have an input
function of X(s), and an output function Y(s), we define the transfer function H(s) to be:
There are two forms of transfer function representation in MATLAB. The most obvious is the
polynomial form where
It is entered as two row vectors with the polynomial coefficients entered in the order of
ascending powers of s.
>> b = [1, 2, 3]; >> a = [1, 4, 5, 6];
Missing coefficients must be entered as zero: so q(s) = s2 + 2s and r(s) = s4 + s2 + 1 are entered
as:
>> q = [1, 2, 0]; >> r = [1, 0, 1, 0, 1];
MATLAB CODE:
OUTPUT:
Task 1: Find laplace and ilaplace of the following.
TASK 1:
Laplace Transform of each part is given in sequence with Code and Output
part 1
part 2;
part 3;
part 4;
part 5;
part 6;
part 7;
part 8;
part 9;
part 10;
part 11;
Task 2: Express the following in partial fraction form using residue command and also convert
back the partial fraction expansion to polynomial co-efficient.
Comments:
Most ordinary differential equations arising in science and engineering
applications cannot be solved easily or it takes too much time, Classical
methods may not be able to give solution. A transformations method can
be used to get an exact solution to a differential equation. There are many
methods which use transformation, Laplace transforms are commonly
used in solving mathematical and physical problems which contains
ordinary or partial differential equations with constant coefficients and
integral equations as those problems are arising in the many branches of
physics as electronic circuit analysis .But it takes too much time for
solving by hand and in papers, These ODE can be analyzed. However,
mathematical software’s was developed for solving the ordinary
differential equations easily in some seconds, To compute quickly the
solution of differential equation, One of such powerful and must know
software’s language is MATLAB language, which is easy to use, developed
by Mathworks
Conclusion:
Matlab program is contains Many easy to use tools,
programs and functions to solve or simulate differential equation by
Laplace transform and numerical methods such .In last decades
must of researcher developed new functions and programs for Matlab
program for solving and computing exact solution for ordinary differential
equations, developed functions estimated exact solution in some second
with graph of exact solution, which reduced too many time for
mathematicians and physicist in solving these problem by hand in paper.
……………………….
Signals and Systems (EE-311)
Experiment # 06
BEEF18M032
MUHAMMAD ABDULLAH
Implementation of Moving Average System and Convolution in MATLAB
(With and Without Built in Command)
Objective
This lab provides us introduction about the convolution and moving average system phenomena,
we will learn how to implement them in MATLAB with and without built in command.
Apparatus
PC having MATLAB
Theory
1. Moving average system
The moving average system can be defined by the equation as:
Moving average system take the succession of averages derived from successive segments
(typically of constant size and overlapping) of a series of values.
In simple words moving average system take the present value of the input and also by using
previous values according to the formula and calculate their average. The casual moving average
system can be represented as the cascade system.
Signals and Systems (EE-311)
2. Convolution
Convolution is the process used to find the response of a Linear Time Invariant system to a given
input, assuming we already know the impulse response of that system. The physical meaning of
the convolution is the multiplication of two signal functions. The convolution of two signals helps
to delay, attenuate and accentuate signals.
Simply we can that the convolution of one function (the input signal) with a second function
(the impulse response) gives the output of a linear time-invariant system (LTI). At any given
moment, the output is an accumulated effect of all the prior values of the input function, with the
most recent values typically having the most influence (expressed as a multiplicative factor). The
impulse response function provides that factor as a function of the elapsed time since each input
value occurred.
In case of continuous-time signals, we can find the system response using the Convolution Integral,
while in case of discrete-time systems; the response can be calculated using the Convolution Sum.
For example, let 𝑥1(𝑛) and 𝑥2(𝑛) be two discrete-time signals. The convolution sum of the two
signals can be calculated using the formula:
In convolution there are two sequences M and N if 𝑥1(𝑛) is a M- point sequence and 𝑥2(𝑛) is an
N – point sequence, then the convolved sequence, 𝑦(𝑛) is a (M+N-1) – point sequence.
We can perform the convolution by different methods:
● By using built-in command:
MATLAB has a built-in function called “conv” function, which basically performs a linear
convolution of any two given sequences.
● By using the Linear Convolution Sum formula:
In this method we use the convolution sum formula and substitute values of 𝑛 and 𝑘 in the
expression and calculate the values of the convolved signal. Alternatively, we can perform the
signal inversion-time shift-superposition method, by which we can calculate the resultant
signal values.
Signals and Systems (EE-311)
OUTPUT:
Signals and Systems (EE-311)
EXPLANATION:
Step 4: If we want to plot three signals we use a subplot and stem functions.
OUTPUT:
Signals and Systems (EE-311)
EXPLANATION:
Step 4: If we want to plot three signals we use a subplot and stem functions.
OUTPUT:
Signals and Systems (EE-311)
EXPLANATION:
Comments:
A mathematical way of combining two signals to form a new signal is known as Convolution. In matlab
for convolution ‘conv’ statement is used. The convolution of two vectors, p, and q given as “a = conv( p,q
)” which represents that the area of overlap under the points as p slides across q. Convolution is the
most important technique in Digital Signal Processing. The direct calculation of the convolution can be
difficult so to calculate it easily Fourier transforms and multiplication methods are used. Convolution is
used in differential equations, statistics, image and signal processing, probability, language processing
and so on.
Conclusion:
Step 4: If we want to plot three signals we use a subplot and stem functions.
Signals and Systems (EE-311)
Experiment # 08
Implementation and Verification of Discrete Time Fourier Transform in
MATLAB
Objective
The objective of this lab is to understand the concept of Fourier series and implement it in
MATLAB.
Apparatus
PC having MATLAB
Theory
Time and Frequency Domain
● Time domain and frequency domain are two modes used to analyze data. Both time domain
analysis and frequency domain analysis are widely used in fields such as electronics,
acoustics, telecommunications, and many other fields.
● Frequency domain analysis is used in conditions where processes such as filtering, amplifying
and mixing are required.
● Time domain analysis gives the behavior of the signal over time. This allows predictions and
regression models for the signal.
● Frequency domain analysis is very useful in creating desired wave patterns such as binary bit
patterns of a computer.
● Time domain analysis is used to understand data sent in such bit patterns over time
Time Domain
Time domain analysis is analyzing the data over a time period. Functions such as electronic
signals, market behaviors, and biological systems are some of the functions that are analyzed
using time domain analysis. For an electronic signal, the time domain analysis is mainly based
on the voltage – time plot or the current – time plot. In a time domain analysis, the variable is
always measured against time. There are several devices used to analyze data on a time domain
basis. The cathode ray oscilloscope (CRO) is the most common device when analyzing
electrical signals on a time domain.
Signals and Systems (EE-311)
Tells us how properties (air pressure in a sound function, for example) change over time:
● Amplitude = 100
● Frequency = number of cycles in one second = 200 Hz
Frequency Domain
Frequency domain is a method used to analyze data. This refers to analyzing a mathematical
function or a signal with respect to the frequency. Frequency domain analysis is widely used
in fields such as control systems engineering, electronics and statistics. Frequency domain
analysis is mostly used to signals or functions that are periodic over time. This does not mean
that frequency domain analysis cannot be used in signals that are not periodic. The most
important concept in the frequency domain analysis is the transformation. Transformation is
used to convert a time domain function to a frequency domain function and vice versa.
Time-Frequency Analysis
■ A signal has one or more frequencies in it, and can be viewed from two different
standpoints: Time domain and Frequency domain
● Differential and difference equations and convolution operations in the time domain
become algebraic operations in the frequency domain.
● We can go between the time domain and the frequency domain by using a tool called
Fourier transform.
● A Fourier transform converts a signal in the time domain to the frequency domain
(spectrum).
● An inverse Fourier transform converts the frequency domain components back into the
original time domain signal.
Example:
Then the DFT of the signal is a sequence X[k] for k=0… N-1.
Where N represents no. of points that are equally spaced in the interval 0 to 2pi. And the inverse
is then,
Signals and Systems (EE-311)
Output:
DFT in MATLAB
Signals and Systems (EE-311)
A fast Fourier transform (FFT) algorithm computes the discrete Fourier transform (DFT) of a
sequence, or its inverse. Fourier analysis converts a signal from its original domain (often time or
space) to a representation in the frequency domain and vice versa. The Fast Fourier Transform
does not refer to a new or different type of Fourier transform. It refers to a very efficient algorithm
for computing the DFT. The time taken to evaluate a DFT on a computer depends principally on
the number of multiplications involved. DFT needs N2 multiplications. FFT only needs Nlog2(N).
● Y=fft(X) computes the discrete fourier transform (DFT) of X using a fast fourier transform
transform algorithm.
MATLAB Code
● pzmap(sys) plots the pole-zero map of the continuous- or discrete-time LTI model sys.
● For SISO systems, pzmap plots the transfer function poles and zeros. The poles are plotted as
x's and the zeros are plotted as o's
Lab Tasks:
Task 1: Find the DFT of x=[2 4 -1 6] using Build-in command and also by summation formula
Signals and Systems (EE-311)
By built in Command
By Formula
Signals and Systems (EE-311)
3. Create the convolved sequence. i.e. M+N-1 (n1+n2-1) in N and create T=1:N
6. Then multiply the ffts of signals. i.e. y3=y1.*y2. This will give the multiplication.
CODE:
clear all;
x1=[0 1 2 3]
x2=[2 4 -1 6]
n1=length(x1);
n2=length(x2);
N=n1+n2-1;
T=1:N;
y1=fft(x1,N)
y2=fft(x2,N)
y3=y1.*y2;
subplot 211
plot(y3,T)
title('Convolution in frequency Domain');
subplot 212
z=conv(x1,x2)
plot(z,T)
title('Conv (x1,x2)');
Signals and Systems (EE-311)
Task 3: Find the zeros and poles for the following transfer function using tf2zp and then plot the
pz map to confirm your answer:
CODE:
b=[2 1];
a=[1 3 2];
[b,a]=eqtflength(b,a);
[z,p,k] = tf2zp(b,a)
fvtool(b,a,'polezero')
text(real(z)+.1,imag(z),'Zero')
text(real(p)+.1,imag(p),'Pole')
Signals and Systems (EE-311)
Signals and Systems (EE-311)
Experiment # 09
Implementation and Verification of Periodicity and Harmonics of Periodic
Signals in MATLAB
Objective
The objective of this lab is to understand the periodicity and harmonics of signals.
Apparatus
PC having Matlab.
Theory
A very common class of signals that we encounter is the class of periodic signals. A periodic
continuous time signal has the property that there is a positive value of‘t’ for which
X(t) = x(t + aT) A (continuous time)
Where a = 0, 1,2,3,4 -----------For all values of‘t’.
In other words a periodic signal has the property that it is unchanged by a time shift of ‘T’. In
this case we say that x(t) is periodic signal is the sine signal.
X(t) = sin (wt) , where w = 2πf; therefore X(t) = sin (2πft)
Since sin (Q) = sin(Q + 2π) therefore the signal is periodic with the period ‘2π’.
A periodic signal in discrete time is defined similarly to continuous time periodic signal.
Specifically a discrete time signal x[n] is periodic with period ‘N’ where ‘N’ is positive integer,
i:e if it is unchanged by a time shift of ‘N’ i:e.
X[n] = x[n + bN] (discrete time), where b = 0, 1, 2, 3, 4, -----------
Fundamental period
The fundamental period is the smallest positive value of ‘T’(continuous) or ‘N’ (discrete) for
which the equations of periodicity held. Consider the example of a sine function. In that case the
signal is periodic on 2π, 4π, 6π and so on but the fundamental time period of the signal is 2π.
Example # 1: Matlab explanation of periodic signals.
Code:
t=0:0.01:6;
f=0.5;
x=sin(2*pi*f*t);
plot(t,x);
Its output is shown in Fig. 9.1.
Signals and Systems (EE-311)
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 0.5 1 1.5 2 2.5 3 3.5 4
xlabel('Time');
ylabel('Amplitude');
title('Square wave Signal');
Its output is shown in Fig. 9.4.
Square wave Signal
20
15
10
5
Amplitude
-5
-10
-15
-20
0 5 10 15 20 25 30 35 40 45 50
Time
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Comments:-
This lab provides us introduction about the periodicity and harmonics of signals, we learned how
to implement them in MATLAB. We implemented it in lab and observed output.
Conclusion:-
MATLAB is a high-performance language for technical computing. It integrates computation,
programming and visualization in an easy environment where problems and solutions are
expressed in familiar mathematical notations. This lab provides the basic knowledge of plotting
time shifting, scaling and reversal and to implement these signals in MATLAB.
Signals and Systems (EE-311)
Experiment # 11
Implementation and Verification of Sampling Theorem in MATLAB
Objectives
This lab provides an introduction to the concept of sampling and verification of sampling
theorem in MATLAB.
Apparatus
PC having MATLAB
Theory
Period: For periodic waveforms, the duration of the waveform before it repeats is called the
period of the waveform as shown below in Fig. 11.1.
Sampling:
To represent waveforms on digital computers, we need to digitize or sample the waveform.
In signal processing sampling is the reduction of a continuous-time signal to a discrete-time
signal. A common example is the conversion of a sound wave (a continuous signal) to a
sequence of samples (a discrete-time signal).A sample is a value or set of values at a point in
time and/or space.
A sampler is a subsystem or operation that extracts samples from a continuous signal. A
theoretical ideal sampler produces samples equivalent to the instantaneous value of the
continuous signal at the desired points. A sample is a value or set of values at a point in time
and/or space. A sampler is a subsystem or operation that extracts samples from a continuous
signal as shown below in Fig. 11.2. A theoretical ideal sampler produces samples equivalent
to the instantaneous value of the continuous signal at the desired points.
Example:
Fig. 11.4: Frequency versus amplitude plot showing an aliased signal, fa, which occurs due to
"aliasing back" from the original signal of 70MHz
Signals and Systems (EE-311)
Oversampling
• When we sample at a rate which is greater than the Nyquist rate, we say we are
oversampling as shown below in Fig. 11.5.
function abdulmoeezl15()
f=1000;
T=1/f;
t=0:0.01*T:2*T;
x=cos(2*pi*f*t);
subplot 221
plot(t,x)
title('Continuous Signal')
xlabel('t')
ylabel('x(t)')
fs1=15*f;
n1=0:1/fs1:2*T;
x1=cos(2*pi*f*n1)
subplot 222
stem(n1,x1)
hold on;
Signals and Systems (EE-311)
plot(n1,x1,'k')
hold off;
title('Over Sampling Condition: Fs = 15*F')
xlabel('n')
ylabel('x[n]')
fs2=2*f;
n2=0:1/fs2:2*T;
x2=cos(2*pi*f*n2)
subplot 223
stem(n2,x2)
hold on;
plot(n2,x2,'r')
hold off;
title('Sampling at Nyquist Frequency:Fs = 2F')
xlabel('n')
ylabel('x[n]')
fs3=1.5*f;
n3=0:1/fs3:2*T;
x3=cos(2*pi*f*n3)
subplot 224
stem(n3,x3)
hold on;
plot(n3,x3,'r')
hold off;
title('Under Sampling Condition: Fs=1.5F')
xlabel('n')
ylabel('x[n]')
Its output is shown in Fig. 11.7.
Continuous Signal Over Sampling Condition: Fs = 15*F
1 1
x(n)
x(t)
0 0
-1 -1
0 0.5 1 1.5 2 0 0.5 1 1.5 2
t -3 n -3
x 10 x 10
Sampling at Nyquist Frequency:Fs = 2F Under Sampling Condition: Fs=1.5F
1 1
x(n)
x(n)
0 0
-1 -1
0 0.5 1 1.5 2 0 0.5 1 1.5 2
n -3 n -3
x 10 x 10
Output:-
Comments:-
Over-sampling is that when we do sampling greater than normal sampling i.e. >2f and it gives
same signal if we convert back to analogue signal. While under-sampling is that when we did
<2f i.e. less than normal sampling and when we convert back from under-sampling then we get
totally distorted/another signal which is not same as input.
Conclusion:-
This lab provides us introduction about the sampling theorem, under-sampling, over-sampling,
and Nyquist theorem and aliasing. We learned how to implement them in MATLAB. We
implemented it in lab and observed output.
Signals and Systems (EE-311)
Experiment # 12
Implementation of Sound Manipulation and Noise Reduction in MATLAB
Objective:
The objective of this lab is to understand the concept of sound manipulation and how to
reduce noise in sound.
Theory:
Matlab provides functions to read sound files in two formats ‘wavread’ for ‘.wav files’
and ‘auread’ for ‘.au files’. Both return a vector of sound values in the range -1 to 1, the
sampling frequency in Hz, and the number of bits of resolution.
Sound waves are fluctuations in air pressure that have various amplitudes and frequencies.
The amplitude represents the pressure (or intensity) of the sound, while the frequency
specifies how fast the pressure is varying.
MATLAB commands for audio files:
Y= wavread(‘FILE.wav’) reads a WAVE file specified by the string FILE, returning the
sampled data in Y. The ".wav" extension is appended if no extension is given.
[Y,FS,NBITS]= wavread(‘FILE.wav’) returns the sample rate (FS) in Hertz and the number
of bits per sample (NBITS) used to encode the data in the file.
Y=auread(AUFILE) loads a sound file specified by the string AUFILE, returning the
sampled data in y. The ".au" extension is appended if no extension is given.
[Y,Fs,BITS]=auread(AUFILE) returns the sample rate (Fs) in Hertz and the number of bits
per sample (BITS) used to encode the data in the file.
Example:
Command window: >> [Y,FS,NBITS]=wavread('lab.wav')
Output: Its output is shown in Fig. 12.1.
Comments:-
This lab provides us introduction about the sound manipulation and noise reduction, we
learned how to implement them in MATLAB. We implemented it in lab and observed output.
Conclusion:-
MATLAB is a high-performance language for technical computing. It integrates
computation, programming and visualization in an easy environment where problems and
solutions are expressed in familiar mathematical notations. This lab provides the basic
knowledge of plotting time shifting, scaling and reversal and to implement these signals in
MATLAB.
Signals and Systems (EE-311)
Experiment # 13
Verification of Z-Transformation and Related Functions in MATLAB
Objective
This lab provides us introduction about z-transform. We also study about region of convergence
(ROC) and how to implement z-transform and its related functions i.e. ROC in MATLAB.
Apparatus
PC having Matlab
Theory
Z-Transform
In mathematics and signal processing, the Z-transform converts a time domain signal, which is a
sequence of real or complex numbers, into a complex frequency domain representation.
Where A is the magnitude of z, j is the imaginary unit, and ɸ is the complex argument (also
referred to as angle or phase) in radians.
Unilateral Z-transform
Alternatively, in cases where x[n] is defined only for n ≥ 0, the single-sided or unilateral Z-
transform is defined as:
Signals and Systems (EE-311)
In signal processing, this definition can be used to evaluate the Z-transform of the unit impulse
response of a discrete-time causal system.
Matlab implementation: In matlab we use the command of ‘ztrans’ for finding the z-transform
and ‘iztrans’ for finding inverse z-transform of the function or signal. For example:
Write matlab code for conversion from time domain into frequency domain.
Code:
syms t
x= exp(-2*t)
ztrans(x)
Command window:
x=
1/exp(2*t)
ans =
z/(z - 1/exp(2))
Code:
b=[0 1 1/2]
a=[1 3/5 2/25]
zplane(b,a)
Command window:
b=
0 1.0000 0.5000
a=
1.0000 0.6000 0.0800
Its output graph is shown in Fig. 13.2.
Signals and Systems (EE-311)
Output:-
Task-1
(i)
(ii)
Signals and Systems (EE-311)
(iii)
(iv)
Signals and Systems (EE-311)
(v)
(vi)
Signals and Systems (EE-311)
(vii)
(viii)
Signals and Systems (EE-311)
(ix)
(x)
Signals and Systems (EE-311)
(xi)
(xii)
Signals and Systems (EE-311)
Task-2
(i)
(ii)
Signals and Systems (EE-311)
Comments:-
In this lab we learned introduction about z-transform and inverse z-transform. We also studied
about region of convergence (ROC) and how to implement z-transform and its related functions
i.e. ROC in MATLAB.
Conclusion:-
MATLAB is a high-performance language for technical computing. It integrates computation,
programming and visualization in an easy environment where problems and solutions are
expressed in familiar mathematical notations. This lab provides the basic knowledge of plotting
time shifting, scaling and reversal and to implement these signals in MATLAB.