0% found this document useful (0 votes)
18 views12 pages

Lab 3 SP18

The document discusses various signal characteristics that can be explored using MATLAB including unit step, unit impulse, ramp, signum, square wave, periodic, even, odd, deterministic, and stochastic signals. It provides the mathematical definitions and examples of generating and analyzing these signals in MATLAB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views12 pages

Lab 3 SP18

The document discusses various signal characteristics that can be explored using MATLAB including unit step, unit impulse, ramp, signum, square wave, periodic, even, odd, deterministic, and stochastic signals. It provides the mathematical definitions and examples of generating and analyzing these signals in MATLAB.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems

LAB # 03

Signal Characteristics using MATLAB

1
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems

Lab 03-Study of Signal Characteristics using MATLAB


Lab Objective
The objective of this lab is to explore different signals including periodic, even odd etc.

3.1 Basic Signal Generation in MATLAB:


3.1.1 Unit Step Function:
The Heaviside step function, or the unit step function, usually denoted by u, is a discontinuous function
whose value is zero for negative argument and one for positive argument. Mathematically, a continuous
time unit step function is written as
1 t  0
u (t )  
0 t  0
In discrete form, a unit step function can be mathematically written as

1 n  0
u[n]  
0 n  0

Graphically, discrete time unit step sequence is shown in figure 3.1.

Figure 3.1: Unit Step Sequence

2
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems

3.1.2 Unit Impulse Sequence:

Unit Impulse sequence is very important to characterize the impulse response of the system.
Mathematically an impulse sequence is represented as:

1 n  0
 [ n]  
0 n  0

Graphically an impulse sequence is shown in figure 3.2

Figure 3.2: Impulse Sequence

3.1.3 Ramp Sequence:

Mathematically a ramp sequence is defined as:

n n  0
r[n]  
0 n  0

Graphically a ramp sequence is shown in figure 3.3

3
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems

Figure 3.3: Ramp Sequence

3.1.4 Signum Sequence:


Signum sequence can be mathematically written as:
1 n  0
sgn[n]  
1 n0
Graphically, signum sequence is shown in figure 3.4

Figure 3.4: Signum Sequence

4
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems

3.1.5 Square Wave:


Square wave is very important in communications related aspect. For example all the line coding
techniques like RZ, NRZ etc consists of square waves. For wireline communications the line coded
bits are communicated and for wireless communications the bits are first coded and then
modulated. 5Hz square wave is shown in shown in figure 3.5.

Figure 3.5: Square Wave

3.2 Periodic Sequences in MATLAB:


A discrete-time signal x[n] is said to be periodic if there exist a positive constant N (the period) for
which x[n  N ]  x[n] , for all n . We can easily generate periodic signal in MATLAB. For example,
consider we have a vector x  [1,1,0,0, 1, 1] , and we want to periodically repeat the given vector
four times, following is the MATLAB code to do this

x=[1 1 0 0 -1 -1];
n=1:length(x);
subplot(2,1,1)
stem(n,x,'fill', 'Linewidth',2),grid on
y=repmat(x,1,4);
n1=1:length(y);

5
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems

subplot(2,1,2)
stem(n1,y,'fill', 'Linewidth',2),grid on
repmat is the command which is used to repeat a matrix or a vector.

Figure 3.6: Periodic Sequences

3.3 Energy and Power of Continuous Time Signal in MATLAB:


The term signal energy of a signal is defined as the area under the square of magnitude of the
signal. The signal energy of a continuous time signal x(t ) is given as

Ex  
2
x(t ) dt


Consider the following code to find the every of a signal x(t )  2t over the interval of 0 to  .
t=0:0.0001:10;
x=2*t;
xsq=x.^2;
Ex=trapz(t,abs(xsq))
Ex =
1.3333e+003
Sometimes, there are signals with infinite energy, in those cases it is more convenient to deal with
the average power of the signal. The average power of the periodic signal x(t ) is defined by
1
Px  
2
x(t ) dt
T T

6
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems

Consider the following MATLAB code for finding the power of x(t )  2t over the interval of 0 to  .
t=-5:0.1:5;
x=-3*t;
xsq=x.^2;
Px=(trapz(t,abs(xsq)))/10
Px =
75.0150

3.4 Energy and Power of Discrete Time Sequences in MATLAB:


The signal energy of a discrete time sequence is defined by

Ex  
2
x[n]
n 

Consider the following code, to determine the energy of a signal x[n]  (0.9) sin  2 n 4 
n

n=-100:100;
x=((0.9).^(abs(n))).*sin(2*pi*n/4);
xsq=x.^2;
Ex=sum(xsq)
Ex =
4.7107
Similarly, signal power is defined by the following mathematical relation
1
Px  
2
x[n]
N n N
n=-100:100;
x=((0.9).^(abs(n))).*sin(2*pi*n/4);
xsq=x.^2;
Ex=sum(xsq)/200
Ex =
0.0236

3.5 Deterministic and Stochastic Signals:


A signal is deterministic if no randomness is involved in its value, i.e. its each value can be
determined by some mathematical expression. On the other hand a signal is stochastic or non-
deterministic is there is some randomness in the signal and the values of the signal cannot be
predicted.

3.6 Even and Odd Signals:


A signal x(t ) is even if x(t )  x(t ) and a signal is odd if x(t )   x(t ) for   t   .

7
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems

See the following example:


Find out if the signals x(t )  t 2 and y(t )  t 3 are even or odd.
Of course, we cannot examine these two signals over the time interval  ,   . The symmetry of
the signals is tested in the time interval 4  t  4 .

t1=0:4 t1=0 1.00 2.00 3.00 4.00


t2=0:-1:4 t2=0 -1.00 -2.00 -3.00 -4.00
x1=t1.^2 x1=0 1.00 4.00 9.00 16.00
x2=t2.^2 x2=0 1.00 4.00 9.00 16.00
y1=t1.^3 y1=0 1.00 8.00 27.00 64.00
y2=t2.^3 y2=0 -1.00 -8.00 -27.00 -64.00

From the above example, it is clear that x(t )  x(t ) , so it is an even signal and y(t )   y(t ) so, it is
an odd signal.
A signal is not always even or odd. For example, the signal x(t )  t 2 / (t  5) is neither odd nor even.
But all the signals can be expressed as sum of an even signal xe (t ) and an odd signal xo (t ) ; that is
any signal x(t ) is expressed as x(t )  xe (t )  xo (t ) , where
1
xe (t )   x(t )  x(t )
2
1
xo (t )   x(t )  x(t ) 
2
In discrete-time signals case, same rules are valid. A signal x  n  is even if x  n  x  n and odd if
 x  n  x  n . Moreover, a discrete time signal x  n  can be expressed as the sum of an even signal
xe  n  and an odd signal xo  n , where xe  n  and xo  n are given by

xe  n  
1
2
 x  n   x  n 
xo  n    x  n   x  n 
1
2

8
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems

Figure 3.7: Unit Sequence with its even and odd parts

9
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems

Tasks
In-Lab Task 01: Create a function “impseq”, which performs following operations:
Function [x,n]=impseq(n0,n1,n2)
 Takes three parameters (n0, n1, n2) as input, where „n1‟ and „n2‟ are lower and upper
limits of n-axis, and „n0‟ is the delay.
 Generates a unit-impulse sequence using above mentioned three parameters.
 There should be two output arguments [x, n] of function „impseq‟, where „x‟ is impulse
sequence and „n‟ is its corresponding n-axis.
 Finally, plot unit impulse „x‟ against vector „n‟.
 On the main window, type “[x,n]=impseq(0,-5,5)”
o Unit Sample Sequence
 The resulting plot looks like this

Unit Sample Sequence


2

1.8

1.6

1.4

1.2
x(n)

0.8

0.6

0.4

0.2

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
n

In-Lab Task 02: Make a function to form “stepseq” function which will output unit-step
sequence. Function [x,n]=stepseq(n0,n1,n2)
 Unit Step Sequence
 We can have another elegant way to produce a step function
 Alternatively, we can use the “ones” function
 Type “stepseq[x,n]=(0,-5,5)” we get:

10
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems

Unit Sample Sequence


2

1.8

1.6

1.4

1.2
x(n)

0.8

0.6

0.4

0.2

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
n
In-Lab Task 03: Create a function “rampseq”, which performs following operations:
Function [x,n]=rampseq(n0,n1,n2)
 Takes three parameters (n0, n1, n2) as input, where „n1‟ and „n2‟ are lower and upper
limits of n-axis, and „n0‟ is the delay.
 Generates a ramp sequence using above mentioned three parameters.
 There should be two output arguments [x, n] of function „rampseq‟, where „x‟ is impulse
sequence and „n‟ is its corresponding n-axis.
 Finally, plot ramp impulse „x‟ against vector „n‟.

Post-Lab Task 01: Create a function “sigseq”, which performs following operations:
Function [x,n]=sigpseq(n0,n1,n2)
 Takes three parameters (n0, n1, n2) as input, where „n1‟ and „n2‟ are lower and upper
limits of n-axis, and „n0‟ is the delay.
 Generates a signum sequence using above mentioned three parameters.
 There should be two output arguments [x, n] of function „sigseq‟, where „x‟ is impulse
sequence and „n‟ is its corresponding n-axis.
 Finally, plot signum sequence „x‟ against vector „n‟.

Post-Lab Task 02: Find 𝐸∞ for the following signal

1− 𝑡 𝑡 <1
𝑡𝑟𝑖 𝑡 =
0 𝑡 ≥1

11
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems

Post-Lab Task 03: Find 𝑃∞ for the following signal


𝜋
𝑥 𝑛 = cos⁡
( 𝑛)
4
Post-Lab Task 04: Write a function which plot or stem a unit impulse and unit step signals.
The function takes values for starting and ending value of independent variable, i.e. t and n,
and a character for identification of discrete and continuous signal. Finally t plot or stem the
function or signal. e.g;
function f_name ( arg1 (start) , arg2 (end) , arg3 (D/C) )

12

You might also like