Lab 3 SP18
Lab 3 SP18
LAB # 03
1
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems
1 n 0
u[n]
0 n 0
2
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems
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
n n 0
r[n]
0 n 0
3
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems
4
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems
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.
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
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
7
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems
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
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
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‟.
1− 𝑡 𝑡 <1
𝑡𝑟𝑖 𝑡 =
0 𝑡 ≥1
11
[SIGNAL CHARACTERISTICS USING MATLAB] Signals and Systems
12