University of Southeastern Philippines
University of Southeastern Philippines
University of Southeastern Philippines
College of Engineering
ECE 312L Signals, Spectra, and Signal Processing Laboratory
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
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.
1, 𝑡 > 0
𝑢(𝑡 =
) + 0, 𝑡 < 0
In Matlab
In Editor
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
1, 𝑡 > 𝑡"
𝑢(t − 𝑡") = 3
0, 𝑡 < 𝑡 "
In Matlab
0, 𝑡 ≠ 0
δ(t) = +
∞, 𝑡 = 0
In Matlab
In Editor
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
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
Code:
t=-10:10;
y=(2*impfunc(t,0)+3*impfunc(t,1)-5*impfunc(t,3));
plot(t,y,'Linewidth',5)
Sketch
𝑡, 𝑡 ≥ 0
r(t)= +
0, 𝑡 < 0
In Matlab
In Editor
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
𝑡, 𝑡" ≥ 0
r(t-t0)= 3
0, 𝑡 <" 0
In Matlab
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:
>>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:
1, 𝑛 ≥ 0
𝑢[𝑛] = +
0, 𝑛 < 0
In Matlab
In Editor
In Command Window
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.
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
Command Window
1, 𝑛 = 𝑘
δ[𝑛 − 𝑘] = 3
0, 𝑛 ≠ 𝑘
Implement the Matlab code to sketch the discrete-time sequence x[n] specified by
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
In Command Window
Generate and plot a shifted version of a ramp sequence, r[n-5]. Provide the blank command below.
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
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
2 4 4 4 2
In Command Window
ans
0 4 4 4 0
C.3 Scaling
>>A=[3 5 8]
>>B=3*A
ans
A =
3 5 8
B =
9 15 24
C.4 Shifting
In Matlab
In Editor
In Command Window
y1 = 2 0 1 3 5
n1 = 1 2 3 4 5
C.5 Folding
y(n)=x(-n)
In Matlab
In Editor
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
In Command Window
>> sum(x(N1:N2))
ans = 7
(&
∏()($ x(n) = x(n1) ∗ … … ∗ x(n2)
In Command Window
>> prod(x(n1:n2))
ans = 1512
In Command Window
*!$
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,
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
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)
>> xe+xo
ans =
0 0 0 0 0 1 2 3 4
>>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]’);
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]');
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]');
CODES:
n=0:30;
x=cos((1/3)*n);
stem(n,x);
grid;
title('Graph of x[n] = cos ((1/3)n)');