Professional Documents
Culture Documents
(EE-223)
LABORATORY MANUAL
(LAB # 05)
Engr. Fakhar Abbas
Signum Function:
else
y = NaN*n; % Return a
vector of NaN’s
disp('In impND, the period
parameter N is not a positive
integer');
end
stem(n,y,'filled','r')
Signal Operations:
1) Time Reversal
Flipping the signal about the y axis.
function y = g(n)
y = sin(3*pi*n/10).*(n>=0)+3.*((n>=5)&(n<7));
y((round(n) ~= n)) = NaN;
2) Time Shifting
Delaying or advancing a signal.
function y = g(n)
y = sin(3*pi*n/10).*usD(n);
y((round(n) ~= n)) = NaN;
Time shifting for g(n):
n=-5:5;
n0 = input('Enter a number to shift the signal:\n')
x=g(n);
subplot(2,1,1);
stem(n,x,'r','filled');
title('Signal g(n)');
axis([-10 10 0 3])
grid on
shifted_axis=n-n0 ;
y=x;
subplot(2,1,2);
stem(shifted_axis,y,'r','filled');
title('Delayed signal with a factor of n0');
axis([-10 10 0 3])
grid on
3) Time Scaling
Compressing or Expanding a signal.
function y = g(n)
y = sin(3*pi*n/10).*usD(n);
y((round(n) ~= n)) = NaN;
stem(n,g0,'r','filled');
ylabel('g[n]');
subplot(3,1,2);
stem(n,g1,'r','filled');
ylabel('g[2n]');
subplot(3,1,3);
stem(n,g2,'r','filled') ;
xlabel('Discrete time, n');
ylabel('g[n/3]');
4) Amplitude Scaling
Increasing the amplitude of the signal, multiplication with a scalar.
function y = g(n)
y = sin(3*pi*n/10).*usD(n);
y((round(n) ~= n)) = NaN;
Amplitude Scaling:
G1 = 2*g(n)
G2 = g(n) / 5
>> A=1:10
A=
1 2 3 4 5 6 7 8 9 10
>> B = diff(A)
B=
1 1 1 1 1 1 1 1 1
>> C = cumsum(A)
C=
1 3 6 10 15 21 28 36 45 55
Book Example:
Using MATLAB find the signal energy or power of the signals:
Code:
%Program to compute the signal energy and power of a signal
n = -100:100 ; %Set up a vector of discrete times at which to compute the value %of
the function
% Compute the value of the function and its square
x = (0.9).^abs(n).*sin(2*pi*n/4) ;
xsq = x.^2 ;
Energy = sum(xsq) %Use the sum function in MATLAB to find the total energy and
N0 = 35; % The fundamental period is 35
Power = sum(xsq)/N0 % Use the sum function in MATLAB to find the average power % and
display the result.
Output:
The output of this program is
Energy = 4.7107
Power = 0.1346
TASKS:
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
Q. No. 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:
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
Q. No. 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’.
Q.No. 04:
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’.
Q. No 05: Write a function which plot or stem a 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) )