Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 25

University of Southeastern Philippines

College of Engineering
ECE 312L Signals, Spectra, and Signal Processing Laboratory

Laboratory Exercise 2: Signal Classifications & Properties

INTRODUCTION

The concepts of signals and systems arise eventually in virtually all areas of technology, including
electrical circuits, communication devices, signal processing devices, robotics and automation, automobiles,
aircraft and spacecraft, biomedical devices, chemical processes, and heating and cooling devices.
In this laboratory, various fundamental aspects of signals considered, specifically on continuous-time
and discrete-time signals, their classifications and properties.

OBJECTIVES
1. To apply basic commands of Matlab in obtaining a computer-generated plot of a common types
of continuous-time & discrete-time signals given by a mathematical expressions.
2. To implement operations involving signals and sequences using Matlab.
3. To verify the classifications of signals and their properties using Matlab.

ACTIVITIES
A. Continuous-Time Signals
Consider the signal x(t) given by

x(t) = 𝑒 !".$% sin & 𝑡


'

1. Open the Matlab, the click File – New – Script.


2. Use Matlab commands for generating x(t) as follows:

t=0:0.1:30;
x = exp(-
0.1*t).*sin(2/3*t);
plot(t,x)
axis([0 30 -1 1])
grid
xlabel('Time(sec)'
)
ylabel('x(t)')
>>x = exp(-0.1*t).*sin(2/3*t);
>>plot(t,x)
>>axis([0 30 -1 1])
>>grid
Plot x(t) versus >>xlabel('Time(sec)')
t for a range of values of t from 0 to 30 seconds with 0.1-second increment.

Filmann T. Simpao, PEcE Page|1 Omosay, Gap Elgyzon O.


ECE312L Instructor EC3-1 BSEcE Student
3. Save as CTS.m in your Laboratory 1 folder. Run the program and save the plot as CTS.fig. The figure looks
like as follows:

A.1 Basic Continuous-Time Signals


A.2 Unit Step Function, u(t)
The unit-step function, also known as the Heaviside unit, is defined as

1, 𝑡 > 0
𝑢(𝑡 =
) + 0, 𝑡 < 0

In Matlab
In Editor

function [x,t] = stepfunc(t,t0)


% Generates x(t) = u(t-t0);
% -------------------------------------------
%[x,t] = stepfunc(t,t0)
%
x = [(t-t0) >= 0];

In Command Window
>> t=-30:30; % specify t
>> y = stepfunc(t,0); % define the unit step function
>> plot(t,y,'Linewidth',5);grid % plot the function
Sketch of a unit step function

The shifted unit step function, written as u(t-t0), is defined as

1, 𝑡 > 𝑡"
𝑢(t − 𝑡") = 3
0, 𝑡 < 𝑡 "
In Matlab

>> t=-10:10; % specify t


>> y = stepfunc(t,4); % define the shifted unit step function at t 0
>> plot(t,y,'Linewidth',5);grid % plot the function

Sketch the discrete-time function u(t-4) for -10< t < 10.

A.3 Unit Impulse Function, δ(t)


The Dirac delta function, written as δ(t), is defined as

0, 𝑡 ≠ 0
δ(t) = +
∞, 𝑡 = 0
In Matlab

In Editor

function [x,t] = impfunc(t,t0)


% Generates x(t) = delta(t-t0);
% -------------------------------------------
%[x,n] = = impfunc(t,t0)
%
x = [(t-t0) == 0];

In Command Window
>> t=-30:30; % specify index n
>> y=impfunc(t,0); % define the delta function
>> plot(t,y,'Linewidth',5) % plot the delta sequence

Sketch of unit impulse function

The shifted Dirac delta function, written as δ(t-t0), is defined as

0, 𝑡 ≠ 0
δ(t − t") = 3
∞, 𝑡 = t "

Sketch the disc rete-time function δ(t-4) for -10< t < 10.
Provide a Matlab code to sketch the continuous-time signal x(t) specified by

x(t)= 2δ(t) + 3δ(t-1) - 5δ(t-3)

Code:
t=-10:10;
y=(2*impfunc(t,0)+3*impfunc(t,1)-5*impfunc(t,3));
plot(t,y,'Linewidth',5)

Sketch

A.4 Ramp Function, r(t)


The ramp function, r(t), is defined as

𝑡, 𝑡 ≥ 0
r(t)= +
0, 𝑡 < 0
In Matlab
In Editor

function [x,t] = rampfunc(t,t0)


% Generates x(t) = ramp t.*(t-t0);
% -------------------------------------------
%[x,t] = rampfunc(t,t0)
%
x = (t-t0).*[(t-t0) >= 0];

In Command Window
>> t=-10:10; % define t
>> y=rampfunc(t,0); % define a ramp
>> plot(t,y,'Linewidth',5) % plot ramp
Sketch of a ramp function

The shifted ramp function , r(t-to), is defined as

𝑡, 𝑡" ≥ 0
r(t-t0)= 3
0, 𝑡 <" 0

Sketch the continuous-time function r(t-4) for -10< t < 10.

A.4. Exponential Function


Define and sketch the continuous-time exponential function given by

x[n] = (0.8)t u[t]

In Matlab

>> t=-30:30; % specify t


>> x=(0.8).^t.*stepfunc(t,0); function % define the exponential function x(t) & step
>> plot(t,x,'Linewidth',2);grid
% plot the exponential function
Sketch the exponential function.

A.5. Sinusoidal Function


Generate a 50 Hz sinusoidal signal.
In Matlab

>> Fs=1000; % sampling frequency


>> Ts=1/Fs; % sampling interval
>> t=0:Ts:0.1; % sampling instants
>> x=sin(2*pi*50*t); % signal vector
>> plot(t,x);grid % plot the signal
>> xlabel('Time (sec)') % add label to the horizontal axis
>> ylabel('Amplitude') % add label to the vertical axis

Sketch the sinusoidal signal.

B. Basic Discrete-Time Signals

Signals are broadly classified into analog and discrete signals. An analog signal will be denoted by
xa(t), in which the variable t can represent any physical quantity, but we will assume that it represents time in
seconds. A discrete signal will be denoted by x(n), in which the variable n is integer valued and represents
discrete instances in time. Therefore it is also called a discrete-time signal, which is a number sequence and
will be denoted by one of the following notations:

x(n) = {x(n)} = {. . . , x(−1), x(0), x(1), . . .}

where the up-arrow indicates the sample at n = 0


Suppose that the discrete-time signal x[n] is given by

x[0] = 1, x[1] = 2, x[2] = 1, x[3] = 0, x[4] = -1

with x[n] = 0 for all other n.

1. Plot this signal using the Matlab commands as follow:

>>n= -2:6
>>x = [0 0 1 2 1 0 -1 0 0];
>>stem (n, x,'filled');
>>xlabel('n')
>>ylabel('x[n]')

2. Save as DTS.m in your Laboratory 2. Run the program and save the plot as DTS.fig. The figure is as

follows:

B.0 Basic Discrete-Time Sequences


B.1. Unit Step Sequence, u[n]
The unit-step sequence, written as u[n], is defined as

1, 𝑛 ≥ 0
𝑢[𝑛] = +
0, 𝑛 < 0
In Matlab
In Editor

function [x,n] = stepseq(n0,n1,n2)


% Generates x(n) = u(n-n0); n1 <= n <= n2
% -------------------------------------------
%[x,n] = = stepseq(n0,n1,n2)
%
n = [n1:n2]; x = [(n-n0) >= 0];

In Command Window

>> n1=-30; % specify index n1


>> n2=30; % specify index n2
>> [x,n]=stepseq(0,n1,n2); % define the unit step sequence
>>stem(n, x) % plot the unit step sequence

Sketch of a step sequence

The shifted unit step sequence, written as u[n-k], is defined as

1, 𝑛 ≥ 𝑘
𝑢[𝑛 − 𝑘] = 30, 𝑛 < 𝑘
In Matlab
>> n1=-30; % specify index n1
>> n2=30; % specify index n2
>> [x,n]=stepseq(5,n1,n2); % define the unit step sequence with n0 = 5
>>stem(n, x) % plot the unit step sequence
Sketch the discrete-time sequence u[n-4] for -10< n < 10.

B.2. The Delta Sequence, δ [n]

The delta sequence plays an important role in the characterization of discrete-time linear time
invariant systems. The delta sequence, written as δ [n], is defined as

1, 𝑛 = 0
δ[𝑛] = +0, 𝑛 ≠ 0
In Matlab
Editor

function [x,n] = impseq(n0,n1,n2)


% Generates x(n) = delta(n-n0); n1 <= n <= n2
% -------------------------------------------
%[x,n] = = impseq(n0,n1,n2)
%
n = [n1:n2]; x = [(n-n0) == 0];

Command Window

>> n1=-30; % specify index n1


>> n2=30; % specify index n2
>> [x,n]=impseq(0,n1,n2); % define the impulse sequence
>> stem(n, x) % plot the impulse sequence
Sketch of an impulse sequence

The shifted delta sequence, written as δ [n], is defined as

1, 𝑛 = 𝑘
δ[𝑛 − 𝑘] = 3
0, 𝑛 ≠ 𝑘

Implement the Matlab code to sketch the discrete-time sequence x[n] specified by

x[n]= 2δ[n] + 3δ[n-1] - 5δ[n-3 ] ; -10< n < 10

Code:

n1=-30;
n2=30;
[x,n]=(2*impseq(0,n1,n2)+3*impseq(1,n1,n2)-5*impseq(3,n1,n2));
stem(n, x);

Sketch
B.3. The Ramp Sequence , r[n]

𝑛, 𝑛 ≥ 0
r[𝑛 ]= + 0, 𝑛 ≠ 0

In Matlab
In Editor

function [x,n] = rampseq(n0,n1,n2)


% Generates x(n) = ramp n.*(n-n0); n1 <= n <= n2
% -------------------------------------------
%[x,n] = = rampseq(n0,n1,n2)
%
n = [n1:n2]; x = (n-n0).*[(n-n0) >= 0];

In Command Window

>> n1=-30; % specify index n1


>> n2=30; % specify index n2
>> [x,n]=rampseq(0,n1,n2); % define the ramp sequence
>> stem(n, x) % plot the ramp sequence

Sketch of a ramp sequences.

Generate and plot a shifted version of a ramp sequence, r[n-5]. Provide the blank command below.

In Matlab

>> n1=-30; % specify index n1


>> n2=30; % specify index n2
>> [x,n]=rampseq(5,n1,n2);% define the shifted ramp sequence
>> stem(n, x)% plot the shifted ramp sequence
Sketch the output.

B.4. Exponential Sequence


Define and sketch the discrete-time exponential sequence given by
x[n] = (0.8)n u[n]
In Matlab

>> n=-30:30; % specify index n


>> xn=(0.8).^n.*(n>=0); % define the exponential sequence x[n]
>> stem(n,xn);grid % plot the exponential sequence

Sketch the exponential sequence.

B.5. Sinusoidal Sequence

Sketch the discrete-time exponential sequence given by

x(n)=3cos(0.1πn+π/3)+2sin(0.5πn) for 0 < n < 50


In Matlab

>>n=linspace(0,50,25);
>>x=3*cos(0.1*pi*n+pi/3)+2*sin(0.5*pi*n);
>>stem(n,x)
Sketch the sinusoidal sequence.

C. Operations on Sequences

C.1 Signal Addition


Consider:
x1(n)+x2(n)
In Matlab
Command Window

>> n=[1 2 3 4 5];


>> y1=[1 0 1 0 1];
>> y2=[0 2 2 1 0];
>> z=y1+y2

Z = 1 2 3 1 1

However, if the sequences are of unequal lengths, or if the sample positions are different for
equal-length sequences, then we cannot directly use the operator (+). We have to use ‘‘sigadd’’
function.
In Matlab
In Editor

function [y,n]=sigadd(x1,n1,x2,n2)
% Implements y(n) = x1(n) + x2(n)
% -------------------------------------------
%[y,n]=sigadd(x1,n1,x2,n2)
% y = sum sequence over n, which includes n1 and n2
% x1 = first sequence over n1
% x2 = first sequence over n2
n=min(min(n1),min(n2)): max(max(n1),max(n2)); % duration of y(n)
y1=zeros(1,length(n)); y2=y1; % initialization
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % x1 with duration of
y y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % x2 with duration of
y y=y1+y2; % sequence addition
In Command Window

>> x1=[2 2 2 2];


>> n1=[2 3 4 5];
>> x2=[2 2 2 2];
>> n2=[1 2 3 4];
>>sigadd(x1,n1,x2,n2)
Ans=

2 4 4 4 2

C.2 Signal Multiplication

x1(n)*x2(n) Only change (+) to (.*) and sigadd to sigmult.

In Command Window

>> x1=[2 2 2 2];


>> n1=[2 3 4 5];
>> x2=[2 2 2 2];
>> n2=[1 2 3 4];
>>sigmult(x1,n1,x2,n2)

ans

0 4 4 4 0
C.3 Scaling

Each example is multiplied by a scalar a. (a*x(n))

>>A=[3 5 8]
>>B=3*A

ans

A =

3 5 8

B =

9 15 24

C.4 Shifting

y(n)=x(n-k) m=n-k and n=m+k

In Matlab
In Editor

function [y,n] = sigshift(x,m,k)


% Implements y(n) = x[n-k]
% -------------------------------------------
%[y,n] = sigshift(x,m,k)
%
n = m + k; y = x;

In Command Window

>> x=[2 0 1 3 5];


>> n=[-3 -2 -1 0 1];
>>[y1,n1]=sigshift(x,n,4)

y1 = 2 0 1 3 5

n1 = 1 2 3 4 5

C.5 Folding

y(n)=x(-n)
In Matlab
In Editor

function [y,n] = sigfold(x,n)


% Implements y(n) = x[-n]
% -------------------------------------------
%[y,n] = sigfold(x,n)
%
y = fliplr(x); n = -fliplr(n);

In Command Window
>> a=[1 2 3 4];
>> n=2:5;
>>[y,n1]=sigfold(a,n)

y = 4 3 2 1

n1 = -5 -4 -3 -2

C.6 Sample Summation

It adds all sample values of x(n) between n1 and n2.


(&

< x(n) = x(n1) + ⋯ … + x(n2)


()($

In Command Window

>> sum(x(N1:N2))

>> x=[1 1 4 2 6 3];


>> sum(x(2:4))

ans = 7

C.7 Sample Product

It multiplies all sample values of x(n) between n1 and n2.

(&
∏()($ x(n) = x(n1) ∗ … … ∗ x(n2)
In Command Window

>> prod(x(n1:n2))

>> x=[8 9 7 3];


>> prod(x(1:4))

ans = 1512

C.8 Signal Energy

The energy of a sequence


(&

< x[n] ∗ [n] = <|𝑥[𝑛]|&


()($

In Command Window

>> Ex= sum(x.*conj(x))


>> Ex=sum(abs(x).^2)
Try for x=[2 4 5]
Both of the answers will be same
Ex = 203
Ex = 203
C.9 Signal Power

The average power of a periodic sequence

*!$

𝑃𝑥 = (1/𝑁) < |𝑥[𝑛]|&


"

In Command Window

>> Px=sum(abs(x).^2)/N

>> x=[9 6 4 7]
>> Px=sum(abs(x).^2)/2 % N=2
>> Px=sum(abs(x).^2)/3 % N=3

x = 9 6 4 7

For N = 2; For N = 3;
Px =91 Px =60.667
D. Classifications of Signals
D.1 Signal Decomposition into Even and Odd Parts
Any signal x(t) or x[n] can be expressed as a sum of two signals, one of which is even and one of
which is odd. That is,

x(t) = xe(t) + xo(t)


x[n] = xe[n] + xo[n]

where:
xe(t) = $ {𝑥(𝑡) + 𝑥(−𝑡)} even part of x(t)
&
xo(t) = $ {𝑥(𝑡) − 𝑥(−𝑡)} odd part of x(t)
&
xe[n] = $ {𝑥[𝑛] + 𝑥[−𝑛]} even part of x[n]
&
xo[n] = $ {𝑥[𝑛] − 𝑥[−𝑛]} odd part of x[n]
&

In Matlab
In Editor

function [xe,xo,m] = evenodd(x,n)


% Real signal decomposition into even and odd parts
% -------------------------------------------
%[xe,xo,m] = evenodd(x,n)
%
if any(imag(x) ~= 0)
error ('x is not a real
sequence') end
m = -fliplr(n);
m1 = min([m,n]); m2 = max([m,n]); m = m1:m2;
nm = n(1) - m(1); n1 = 1:length(n);
x1 = zeros(1,length(m)); x1(n1+nm) = x; x =
x1; xe = 0.5*(x + fliplr(x));

In Command Window

>> n=[1:4];
>> x=[1 2 3 4];
>> [xe,xo,m]=evenodd(x,n);
>> subplot(2,1,1)
>> stem(xe)
>> subplot(2,1,2)
>> stem(xo)

Adding the even and odd parts x[n] = xe[n] + xo[n]

>> xe+xo
ans =
0 0 0 0 0 1 2 3 4

Sketch the output


APPLICATIONS

1. Use Matlab to plot the functions for -1< t < 5 sec.


a. x(t) = sin 5t + sin πt
CODES:
>>Fs=500;

>>Ts=1/Fs;
>>t= -1:Ts:5;
>>x=sin(5*t)+sin(pi*t);
>>plot (t,x);
>>xlabel('Time (-1< t < 5 sec)');
>>ylabel(' x(t)=sin(πt)+sin(πt)');
>>title('Graph of x(t)=sin(πt)+sin(πt)');
b. x(t) = 3e-t cos 2t
CODES:
>>t=-1:5;
>>x=3*exp(-t).*cos(2*t);

>>plot (t,x);
>>xlabel('Time (-1< t < 5 sec)');
>>ylabel('x(t)=3e^ ^-^tcos2t');
>>title('Graph of x(t)=3e^ ^-^tcos2t');

2. Use Matlab to generate and plot the following sequences over the indicated interval.
a. x[n] = 2δ[n+2] – δ[n-4], -5 < n < 5
EDITOR:
function [x,n] = impseq(n0,n1,n2)
n = [n1:n2]; x = [(n-n0) == 0];
CODES:
>>n1=-5;
>>n2=5;
>>n=n1:n2;
>>x= 2*impseq(-2,n1,n2)- impseq(4,n1,n2);
>>stem(n,x);
>>grid;
>>title(‘Graph of x[n] = 2δ[n+2] – δ[n-4]’);

b. x[n] = n{u[n] – u[n-10]} + 10e-0.3[n-10]{u[n-10]-u[n-20]}, 0 < n < 20


EDITOR:
function [x,n] = stepseq(n0,n1,n2)
n = [n1:n2]; x = [(n-n0) >= 0];
CODES:
>>n1=0;
>>n2=20;
>>n=n1:n2;
>>x= (n.*(stepseq(0,n1,n2)-
(stepseq(10,n1,n2))))+ (10.*exp(-.3*
stepseq(10,n1,n2)).*( stepseq(10,n1,n2
)- (stepseq(20,n1,n2))));
>>stem(n,x);
>>grid;
>>title(‘x[n] = n(u[n] – u[n-10])
+ 10e-0.3[n-10](u[n-10]-u[n-20])’);

c. x[n] = cos[0.04𝜋𝑛] + 0.2ω(n), 0 < n < 50

CODES:
>>n=linspace(0,50,25);
>>x=cos(0.4*pi*n)+(0.2*randn(size(n)));
>>stem(n,x);
>>grid;
>>title(‘x[n] = cos[0.04𝜋𝑛] + 0.2ω(n)’) ;

3. Let x[n] = [ 1,2,3,4,5,6,7,6,5,4,3,2,1], -2 < n < 10. Determine and plot the following sequences.
a. x1[n] = 2x[n-5] – 3x[n+4]
CODES:

>>n=-2:10;
>>x=[1,2,3,4,5,6,7,6,5,4,3,2,1];
>> [xb,nb]=sigshift(x,n,-4);
>> [xa,na]=sigshift(x,n,5);
>> [x1,n1]=sigadd(xa,na,xb,nb);
>>stem(n1,x1);
>>grid;
>>title('Graph of x2[n] = x[3-n] + x[n] x[n-2]');

b. x2[n] = x[3-n] + x[n] x[n-2]

CODES:

n=-2:10;
x=[1,2,3,4,5,6,7,6,5,4,3,2,1];
[xa1,na1]=sigshift(x,n,3);
[xa,na]=sigfold(xa1,na1);
[xb1,nb1]=sigshift(x,n,2);
[xb,nb]=sigmult(x,n,xb1,nb1);
[x2,n2]=sigadd(xa,na,xb,nb);

stem(n2,x2);grid
title('Graph of x2(n) = x(3-n) x(n) x[n-2]');

4. Use Matlab to plot each signal, and verify its periodicity.


a. x(t) = cos + 𝑡 + sin + 𝑡
CODES:
>>t=0:0.0001:30;
>>x=cos((pi/3)*t)+sin((pi/4)*t);
>>plot(t,x);
>>grid;
>>title(' Graph of x(t) = cos + 𝑡 + sin +𝑡');

b. x[n] = cos ((1/3)n)

CODES:
n=0:30;
x=cos((1/3)*n);
stem(n,x);
grid;
title('Graph of x[n] = cos ((1/3)n)');

You might also like