You are on page 1of 6

SIGNALS & LINEAR SYSTEMS LABORATORY COURSE - EELE3110

PREPARED BY: ENG. SANABEL N. EL-HADDAD - TEACHING ASSISTANT AT


ISLAMIC UNIVERSITY OF GAZA

LAB (3) / POWER AND ENERGY SIGNALS


clear; % Clear all variables in the workspace
close all; % Close all open figure windows
clc; % Clear all text from the command window
cd(fileparts(matlab.desktop.editor.getActiveFilename)); % Set the current directory to dir of
this file

set(groot, 'defaultAxesXAxisLocation', 'origin'); % Set default X axis location to origin


set(groot, 'defaultAxesYAxisLocation', 'origin'); % Set default Y axis location to origin

syms t x1(t) x2(t) % Use the symbolic math toolbox--

FIRST EXAMPLE:

DEFINE AS A PIECEWISE FUNCTION

1.1 USING SYMBOLIC FUNCTION:

syms t x1(t)
x1(t) = piecewise(t < 0 , 0, ... % Define x1 as a piecewise fn
0 < t < 2 , 3*t, ...
t > 2 , 6*exp(-(t-2)))

x1(t) =

PLOT THE SIGNAL

figure('Visible', 'on')
fplot(x1(t), [-3 8], 'LineWidth', 2, 'Color', 'c')
title('1^{st} Example: Plot of x_1(t) vs t')
grid on;
xlabel('t');
ylabel('x_1(t)');
text(0.8, 3, '3t', 'FontSize', 14, 'Color', 'b', 'interpreter', 'latex', 'BackgroundColor', 'w')
text(2, 3, '$6e^{-(t-2)}$', 'FontSize', 14, 'Color', 'b', 'interpreter', 'latex')%, 'BackgroundColor',
'w')
axis([-3 8 0 7])

PLOT THE INSTANTANEOUS POWER IN THE SIGNAL

%figure %('Visible', 'on')


hold on
fplot(x1(t)^2, [-3 8], 'LineWidth', 2, 'Color', 'r')
title('1^{st} Example: Plot of Instantaneous Power of x_1(t) vs t')
grid on;
xlabel('t');
ylabel('$p(t) = x_1^2(t)$', 'Color','r', 'interpreter', 'latex');
text(0.4, 20, '$9t^2$', 'FontSize', 14, 'Color', 'r', 'interpreter', 'latex')
text(3, 15, '$\left ( 6e^{-(t-2)} \right ) ^2$', 'FontSize', 14, 'Color', 'r', 'interpreter', 'latex')
axis([-3 8 0 40])

FILL IN THE AERA UNDER THE CURVE

hold on
tt = -3:0.01:8;
area(tt, x1(tt).^2,'FaceColor','r','FaceAlpha', 0.25, 'EdgeColor', 'none');

COMPUTE THE ENERGY IN THE SIGNAL X1(T)

E = int((3*t)^2, t, 0, 2) + int((6*exp(-(t-2)))^2, t, 2, inf)

E=

42

E_X=int((x1(t)).^2, t, 0, inf)

E_X =

42

1.2 USING HANDLE FUNCTION:

x2=@(t)(3*t.*(t>=0 & t<2)+6*exp(-(t-2)).*(t>2));


m = -3 : 1e-3 : 8;
plot(m, x2(m), 'LineWidth', 2, 'Color', 'c')
title('1^{st} Example: Plot of x_1(t) vs t')
grid on;
xlabel('t');
ylabel('x_1(t)');
text(0.8, 3, '3t', 'FontSize', 14, 'Color', 'b', 'interpreter', 'latex', 'BackgroundColor', 'w')
text(2, 3, '$6e^{-(t-2)}$', 'FontSize', 14, 'Color', 'b', 'interpreter', 'latex')%, 'BackgroundColor',
'w')
axis([-3 8 0 7])
%----------------------------------------------------------------------------------------------
hold on
plot(m, x2(m).^2, 'LineWidth', 2, 'Color', 'm')
title('1^{st} Example: Plot of Instantaneous Power of x_1(t) vs t')
grid on;
xlabel('t');
ylabel('$p(t) = x_1^2(t)$', 'Color','k', 'interpreter', 'latex');
text(0.4, 20, '$9t^2$', 'FontSize', 14, 'Color', 'b', 'interpreter', 'latex')
text(3, 15, '$\left ( 6e^{-(t-2)} \right ) ^2$', 'FontSize', 14, 'Color', 'b', 'interpreter', 'latex')
axis([-3 8 0 40])
%---------------------------------------------------------------------------------------------------
hold on
tt = -3:0.01:8;
area(tt, x1(tt).^2,'FaceColor','m','FaceAlpha', 0.25, 'EdgeColor', 'none');

Energy_X2 = integral(@(t)(x2(t).^2),0,inf)

Energy_X2 = 42.0000

SECOND EXAMPLE :
x2(t) = 4 * cos(2 * pi * t / 10);
T = 10; % Period of the periodic signal

PLOT THE SIGNAL

figure ('Visible', 'on')


fplot(x2(t), [-14 18], 'LineWidth', 2, 'Color', 'c')
title('2^{nd} Example: Plot of x_2(t) vs t')
grid on;
xlabel('t');
ylabel('x_2(t)');
text(3, 2, '$$4 cos \left ( \frac {2 \pi t} {10} \right )$$', 'FontSize', 14, 'Color', 'b', 'Interpreter',
'latex')
axis([-14 18 -5 5])

PLOT THE INSTANTANEOUS POWER IN THE SIGNAL

%figure %('Visible', 'on')


hold on
fplot(x2(t)^2, [-14 18], 'LineWidth', 2, 'Color', 'r')
title('2^{nd} Example: Plot of Instantaneous Power of x_2(t) vs t')
grid on;
xlabel('t');
ylabel('$$p(t)=x_2^2(t) = 4^2 cos^2 \left ( \frac {2 \pi t} {10} \right )$$', 'FontSize', 14, 'Color',
'r', 'Interpreter', 'latex');
axis([-14 18 -5 20])

FILL IN THE AERA UNDER THE CURVE

hold on
tt = -14:0.01:88;
area(tt, x2(tt).^2,'FaceColor','r','FaceAlpha', 0.25, 'EdgeColor', 'none');
COMPUTE THE AVERAGE POWER IN THE SIGNAL:

Pav = (1/T) * int(x2(t)^2, t, -T/2, T/2) % <T> can be -T/2 < t < T/2, or any interval "T" wide

Pav =

Pav = (1/T) * int(x2(t)^2, t, 0, T) % <T> can be 0 < t < T, or any interval "T" wide

Pav =

NEITHER AN ENERGY NOR POWER SIGNAL

PLOT THE SIGNAL

x3(t) = t;
figure('Visible', 'on')
fplot(x3(t), [-10 10], 'LineWidth', 2, 'Color', 'c')
title('3^{rd} Example: Plot of x_3(t) vs t')
grid on;
xlabel('t');
ylabel('x_3(t)');
text(4, 6, '$t$', 'FontSize', 16, 'Color', 'b', 'Interpreter', 'latex')
axis([-10 10 -10 10])

PLOT THE INSTANTANEOUS POWER IN THE SIGNAL

hold on
fplot(x3(t)^2, [-10 10], 'LineWidth', 2, 'Color', 'g')
title('3^{rd} Example: Plot of Instantaneous Power of x_3(t) vs t')
grid on;
xlabel('t');
ylabel('$$p(t)=x_3^2(t) = t^2$$', 'FontSize', 14, 'Color', 'g', 'Interpreter', 'latex');
axis([-10 10 -10 100])

FILL IN THE AERA UNDER THE CURVE

tt = -10:0.01:10;
area(tt, x3(tt).^2,'FaceColor','g','FaceAlpha', 0.25, 'EdgeColor', 'none');

E = int((t)^2, t, 0,inf)

E=

You might also like