You are on page 1of 12

The Islamia University of Bahawalpur

University College of Engineering &Technology


Department of Electronic Engineering
LAB MANUAL SIGNALS AND SYSTEMS EE-311 5thSemester

LAB EXPERIMENT # 03
Performing operations on continuous and discrete time signals in MATLAB

Student Name: Abdul Rehman Roll No: 16ES08

Lab Instructor Signatures: Date:

OBJECTIVE:
To perform time reversal (flip), time shift (advance & delay),converting signal into odd and
even components, time scaling (signal expansion-compression) for continuous-time signals in
MATLAB.

1. SIGNAL TRANSFORMATIONS:

1.1 Time Reversal (Signal Flipping):

is a time-reversed version of horizontally symmetric with respect to


the origin .

MATLAB IMPLEMENTATION:

3-1
Code:
%% Time Reversal (Signal Flip)
% time reversal being applied by if-else loop to introduce decision
%loops. Moreover with this scheme, we can perform signal flip whether
%signal defined as column or row vector.
t=-10:0.002:10; % time vector
t0=2; % start position of the signal
x=double((t-t0>=0) &(t<6));
plot(t,x);
hold on;
[r c]=size(x);
if c==1
y=flipud(x); % Returns X with coloumns preserved and rows
%flipped in up/down direction.
else
y=fliplr(x); % Flip matrix in left/right direction.
end
[r c]=size(t);
if c==1
t=-flipud(t);
else
t=-fliplr(t);
end
plot(t,y,'r');
hold off;
ylim([-.03 1.3]);

OUTPUT:

3-2
Task 1: Modify the above code to create a decaying real exponential function, ,
where t= 0-to-10 with 1000 points and then time reversed (flip) this new signal.

MATLAB CODE:
%% Time Reversal (Signal Flip)
% time reversal being applied by if-else loop to introduce decision
%loops. Moreover with this scheme, we can perform signal flip whether
%signal defined as column or row vector.
t=0:0.0001:10; % time vector
t0=2; % start position of the signal
x=2*exp(-2*t);
plot(t,x);
hold on;
[r c]=size(x);
if c==1
y=flipud(x); % Returns X with coloumns preserved and rows
%flipped in up/down direction.
else
y=fliplr(x); % Flip matrix in left/right direction.
end
[r c]=size(t);
if c==1
t=-flipud(t);
else
t=-fliplr(t);
end
plot(t,y,'r');
hold off;
ylim([-.03 1.3]);

OUTPUT:

3-3
1.2 Time Shifting:

is either right-shifted if , or left-shifted if .

%% Shifting the signal


t3=-10:0.002:10;
t0=0;
x3=double(t3-t0>=0);% convert to double precision.
plot(t3,x3);
hold on;
k=-2;
t=t3+k;
y=x3;
plot(t,y,'r-');
hold off;
ylim([-.03 1.3]);
grid on;
title('shifting the signal');

OUTPUT:

3-4
Task 2: Generate decaying real exponential function, , where t= 0-to-10 with
1000 points and then shift it 5 units to right and 3 units to left and show generated and right
and left shifted signals on the same figure as subplots.

3-5
1.3 Even-Odd Functions:
Even functions and odd functions are functions which satisfy particular
symmetry relations, with respect to taking additive inverses.

Even Function: Let x(t) be a real-valued function of a real variable t.


Then x(t) is even if the following equation holds for all t and -t in the domain of x.

Odd Function: Again, let x(t) be a real-valued function of a real variable t.


Then x(t) is odd if the following equation holds for all t and -t in the domain of x(t).

Any signal can be decomposed into even and odd components


xe (t) = 1/ 2 [x(t) + x(−t)]
xo(t) = 1/ 2 [x(t) − x(−t)] .

3-6
Code:
% Converting of a signal into its even-odd components

t3=-10:0.002:10;
t0=2;
x3=double(t3-t0>=0);
plot(t3,x3);
hold on;
negx=fliplr(x3);
plot(t3,negx,'r-')
ylim([-.03 1.3]); hold
off; figure(2)
subplot(211)
evx=(x3+negx)/2; odx=(x3-
negx)/2; plot(t3,evx,'b--
'); ylim([-1 1.5]);
subplot(212);
plot(t3,odx,'r-'); ylim([-
1 1.5]); figure(3)
xn=evx+odx;
plot(t3,xn);

1.4 Signal Scaling (Compression and Expansion)

A signal x(t) is scaled in time by multiplying the time variable by a positive constant
b, to produce x(bt). A positive factor of b either expands (0 < b < 1) or compresses (b > 1) the
signal in time.

3-7
% Inline (EXPR) constructs an inline function object from the Matlab expression contained in string expression.
Code:

t=(-2:.001:2)
; g=inline('exp(-t).*cos(2*pi*t).*(t>=0)','t');
plot(t,g(t))
subplot(3,1,1)
plot(t,g(t))
subplot(3,1,2)
plot(t,g(2*t))
subplot(3,1,3)
plot(t,g(1/2*t))
figure
subplot(3,1,1)
plot(t,g(t))
subplot(3,1,2)
plot(t,g(t+1))
subplot(3,1,3)
plot(t,g(t-1))
figure subplot(3,1,1)
plot(t,g(t))
subplot(3,1,2)
plot(t,1/2*(g(t)+g(-t)))
subplot(3,1,3)
plot(t,1/2*(g(t)-g(-t)))

OUTPUT:

Task 3: Generate, , where t= 0-to-10 with 1000 points and then expand it 3 times
and compress it 2 times. Moreover show generated and time scaled signals on the same figure
as subplots.

3-8
1.5 Periodic Signals

Code:
%% Generation of Periodic Sequence
% x(t)=x(t+T)
t=0:0.002:10; x1=tanh(t)+ cosh(t+4); figure(2)
subplot(211); plot(t,x1); x2=repmat(x1,1,5);%
Replicate and title an array.
subplot(212);
plot(x2);
axis tight

OUTPUT:

1.6 Differentiation
To illustrate how to take derivatives using the Symbolic Math Toolbox, first
create a symbolic expression:
Example 1

3-9
symsx f
=sin(5*x)
The command diff (f)differentiates f with respect to x:
Output = 5*cos(5*x)

Example 2: Find
diff_f =dx /df
where f = e-axx3bsin(cx) and a, b and c are unspecified constants,
>>clear; >>syms a b c x; >>f=exp(-a*x)*x^(3*b)*sin(c*x); >>diff_f = diff(f,x)
Output=
diff_f =
(3*b*x^(3*b-1)*sin(c*x))/exp(a*x)+(c*x^(3*b)*cos(c*x))/exp(a*x) -
(a*x^(3*b)*sin(c*x))/exp(a*x)

simplify it,
>>diff_f_simp = simple(diff_f)
Output= diff_f_simp = (x^(3*b - 1)*(3*b*sin(c*x) + c*x*cos(c*x) - a*x*sin(c*x)))/exp(a*x)

1.7 Integration:

Let f is a symbolic expression, then int(f) returns the indefinite integral or antiderivative of f.

Indefinite integrals: For int_g = ʃ gdx where


g = e^-axsin(cx),

>>clear; >>syms a c x; >>g=exp(-a*x)*sin(c*x); >>int_g = int(g,x)


+‫ח‬
Definite integrals: int_def_g= ʃ gdx
- -‫ח‬

>>clear; >>syms a c x; >>g = exp(-a*x)*sin(c*x); >>int_def_g = int(g,x,-pi,pi)

3-10
HOMEWORK PROBLEMS:

1. Decompose the following signal into its even and odd parts

Program:

Output:

2. Use MATLAB to produce a plot of a discrete-time sinusoid with amplitude 2.0 and a
period of T = 7.

Program:

3-11
Output:

3-12

You might also like