Professional Documents
Culture Documents
Signals and System Lab 4
Signals and System Lab 4
LAB NO : 03
SUBMITTED BY : MAHNOOR
BATCH : AVIONICS 07
SECTION : B
Marks Obtained :
Remarks:
DEADLINE:
DATE OF SUBMISSION:
Piecewise Function:
Assume you have a piecewise function with values as follows:
F(t) = 1 ; -2<t<2
0; 2<=t<=5
t*Sin(t) ; 5<t<15
Implement this function in MATLAB and plot. Follow the steps:
Step 1:
Step 2:
Step 3:
The command y1(1,1:a)=1 on line 15 gets the 1st row and columns from 1 to a(the length of t1)
and puts in the value 1 in each index. Similar for line 16 and 17.
Step 4: Concatenate the matrices t1, t2, t3 into t and y1, y2, y3 into y so the signal can be plotted.
Step 5: plot.
t1 = linspace(-2,2,28)
t2 = linspace(2,5,26)
t3 = 5:0.1:15;
a = length(t1)
b = length(t2)
c = length(t3)
y1(1, 1:a) = 1
y2(1, 1:b) = 0
y3(1, 1:c) = t3 .* sin(t3)
y=[y1 y2 y3]
t=[t1 t2 t3]
figure;
plot(t,y)
OUTPUT:
Task 2. What is the difference between size and length command? Why does size
command not work?
In MATLAB, both the `size` and `length` functions provide information about array
dimensions, but they differ in their applications and outputs.
• `size` determines the rows and columns of arrays or matrices, while `length`
focuses on the length of the longest dimension, mainly for vectors.
• `size` returns dimension details, whereas `length` provides the length of the
longest dimension.
• size () returns the dimensions of an array or object in MATLAB. size
() returns the dimensions of an array or object in MATLAB.
Length() determines the number of elements in an array or string in MATLAB
• `size` is versatile, working with arrays and matrices, while `length` is primarily
for vectors.
• `size` might not function as expected due to syntax errors, variable name
conflicts, or suppressed output settings in MATLAB.
• Size can be used with a second argument like size(A, dim) to retrieve the
length of a specific dimension while length is useful for quickly assessing the
size of arrays and strings without needing detailed dimensional information.
Task 3. Using the steps above, plot the graph for the following piecewise function.
F(t) = 100* sin(t) ; -10<=t<=2
0 ; 2<=t<=15
10*exp(t3/50); 15<=t<=100
Keep the increment for ts as 0.1 for smooth graph.
INPUT:
t1 = -10:0.1:2;
t2 = linspace(2,15,26)
t3 = linspace(15,100,26)
a = length(t1)
b = length(t2)
c = length(t3)
y1(1, 1:a) = 100.*sin(t1)
y2(1, 1:b) = 0
y3(1, 1:c) = 10*exp(t3/50)
y=[y1 y2 y3]
t=[t1 t2 t3]
figure;
plot(t,y)
Unit Impulse Function
The unit step function, also known as the Heaviside function, is a mathematical function that is
often used in engineering and physics to represent a signal that turns on at a specific time. It is
denoted as u(t) and is defined as:
u(t) = 0 for t < 0
u(t) = 1 for t >= 0
In other words, the unit step function is a piecewise function that has a value of zero for negative
values of t and a value of one for non-negative values of t. It represents a signal that is turned
on at t=0 and remains on for all values of t greater than or equal to zero.
The unit step function is used to model a wide variety of phenomena, such as the flow of current
in an electrical circuit when a switch is closed or the motion of a mechanical system when a force
is suddenly applied.
Creating a Unit Step Signal
Method 1: Using Heaviside function in MATLAB
Plot a unit step function from -3 to 3 with 0.5 increment.
.
Task 4. Why is the value of y at n=0, is 0.5 when using the Heaviside function? Look
up on google why is that so.
The value of 0.5 at n=0 when using the Heaviside function is due to specific conventions and
mathematical properties:
1. The Heaviside function returns 0 for x<0, 1 for x>0, and 0.5 for x=0.
2. So there are two conventions for the discrete Heaviside function at n=0, whose choice is
significant in practice. For the continuous version of the Heaviside function, the value
at t=0 is often deemed less important, whenever it is used under integration.
3. For the discrete Heaviside function, the convention you expected is:
4. The Heaviside function returns 0, 1/2, or 1 depending on the argument value. If the argument is a
floating-point number (not a symbolic object), then Heaviside returns floating-point results.
Task 5. Plot a unit step function for n= -6 to 6.
INPUT:
t1=linspace(-6,0,26)
l1=length(t1)
y1=zeros(1,l1)
t2=linspace(0,6,26)
l2=length(t2)
y2=ones(1,l2)
y=[y1 y2]
t=[t1 t2]
plot(t,y)
figure
stem(t,y)
OUTPUT:
Unit Impulse Function
The unit impulse function, also known as the Dirac delta function, is a mathematical function that
is used to model a very short duration, high-amplitude signal. It is often used in engineering,
physics, and mathematics to represent a point source or a point force.
The unit impulse function is denoted by the symbol δ(t) and is defined as:
δ(t) = 0 for t ≠ 0
∫δ(t)dt = 1
In other words, the unit impulse function has a value of zero for all values of t except t=0, where
it is infinite. However, since the integral of the unit impulse function over all time must be equal
to one, the area under the curve of the unit impulse function must be one.
The unit impulse function is used to represent a very short, high-intensity signal or event, such as
a sudden impact or a point source of light. It is also used in the solution of differential equations
and in the Fourier transform.
Note that the unit impulse function is not a true function in the traditional sense, since it is not
defined for any value of t except t=0. Instead, it is called a distribution or generalized function.
Write code for generating a unit impulse function and plot it for n in range of -roll no to
+roll no. Take the code for unit impulse for help. Use the last digit of roll number +3.
INPUT:
OUTPUT:
Conclusion:
From this lab, we have learned how to make a plot of piece wise function, unit step function, unit
impulse function, also about the difference of size and length command and how to make a code
for the desired or given conditions using basic commands that we have learnt in the lab1 .