0% found this document useful (0 votes)
6 views

DSP Lab 3

Uploaded by

Hafiz Muhammad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

DSP Lab 3

Uploaded by

Hafiz Muhammad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

NATIONAL UNIVERSITY OF TECHNOLOGY

(NUTECH)
DEPARTMENT OF ELECTRICAL
ENGINEERING

EXPERIMENT NO: 3
Operations on Discrete Signals and Periodic Sequences
OBJECTIVE:
The objective of this lab is to understand different operation on signals. How amplitude, time
scaling and signal shifting is done in Matlab, also student will be able to learn how to make
any signal periodic.

1. SIGNAL OPERATIONS:
1.1: SIGNAL SCALING

Description:
In this Operation, each sample is multiplied by a scalar. Use the command “*” for scaling.

1.1.1: AMPLITUDE SCALING


C x [n]is amplitude scaled version of x ¿] whose amplitude is scaled by a factor C.

1.1.2: TIME SCALING


x [An] is time scaled version of the signal X [n ]. Where A is always positive.

|A| > 1 Time Compression of the signal


|A| < 1 Time Expansion of the signal

1.2: SIGNAL SHIFTING

Description:
During a shift operation, a signal changes its position in time where each sample of x[n] is
shifted by an amount k to obtain a shifted sequence y [n]={x (n+ k )}.

In Matlab, this operation is not so simple, both “x” and “n” need to be processed separately in
order to get the shifted signal x [n+k ]. Perform following steps to in Matlab to perform the
signal shift.

i) Check whether k is positive or negative?


ii) If k is positive it means shift is towards right i.e. x [n+k] then do following
● As signal is shifting towards right time axes “n” should be extended towards right side
by “k” samples i.e. if n is ending at n2 then it should now end at n2 + k.
● Since the signal has now moved towards right meaning initial “k” samples in “x” are
empty so concatenate “k” zeroes in the beginning of the sequence x.

iii) If k is negative it means shift is towards left i.e. x [n−k ] then do following|
● As signal is shifting towards left time axes “n” should be extended towards left side
by “k” samples i.e. if n is starting at n1 then it should now start at n 1 - k .
NATIONAL UNIVERSITY OF TECHNOLOGY
(NUTECH)
DEPARTMENT OF ELECTRICAL
ENGINEERING

● Since the signal has now moved towards left meaning last “k” samples in “x” are
empty so concatenate “k” zeroes in the end of the sequence x.

1.3: TIME REVERSAL OR FOLDING

Description:
Folding operation is also termed as flipping a signal. The operation of time reversal is
actually an alteration of the signal values between negative and positive times. Assume that x
is the vector that denotes the signal x ¿]. In this operation each sample of x [n] is flipped
around n=0 to obtain a folded sequence

y [n]=x [−n].

1.4: ADD/SUBTRACT/MULTIPLY SIGNALS

1.4.1: SIGNAL ADDITION


It is implemented in MATLAB by the arithmetic operator “+”. However, the lengths of x 1[n]
and x2[n] must be the same.

1.4.2: SIGNAL SUBTRACTION


It is implemented in MATLAB by the arithmetic operator “-”. However, the lengths of x 1[n]
and x2[n] must be the same.

1.4.3: SIGNAL MULTIPLICATION


It is implemented in MATLAB by the array operator “.*”.

ALGORITHM TO ADD/SUB/MULTIPLY SIGNALS OF DIFFERENT LENGTH

In signal processing, signal elements are added/subtracted or multiplied corresponding to


their time index i.e. a signal element at time -1 will be added to the signal element of the
other signal at the same time.
We know that signals can have different starting and ending times, here we want to modify
time indexes such that both signals start from the lowest time index and end at highest time
index and accordingly concatenate zeros at the start or end of the signal. Suppose we want to
add/multiply two signals x1[n] specified by x1 and n1 in MATLAB and x2 [n] specified by x2
and n2 in MATLAB.

Following two steps can be followed to make the lengths of x 1 & x2 and making n1 and n2
same as well.

Compare the starting points of both signals time index vectors i.e. n1(1) and n2(1).

If n1 (1) is smaller than n2 (1)


● Concatenate n2 (1) – n1(1) number of zeros before x1

Else-If n2 (1) is smaller than n1 (1)


● Concatenate n1(1) – n2(1) number of zeros before x2
NATIONAL UNIVERSITY OF TECHNOLOGY
(NUTECH)
DEPARTMENT OF ELECTRICAL
ENGINEERING

Compare the ending points of both signals time index vectors i.e. n1 (end) and n2 (end).

If n1 (end) is greater than n2 (end)


● Concatenate n1(end) – n2(end) number of zeros at the end of x2

Else-If n2 (end) is greater than n1 (end)


● Concatenate n1(end) – n2(end) number of zeros at the end of x1

Now make a universal time index n = n1 (1):n2 (1)


Add the magnitude vectors by as x = x1+ x2 or multiply them as x = x1.* x2 etc.

2. PERIODIC SEQUENCES:
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.

In Lab Assignment:

1. Write Matlab Code for all discrete signal operations described in section 1 and
provide the output.
2. Run the Matlab code described in section 2 and show the output with explanation.
3. Implement a generic unit step sequence with a shift in MATLAB and plot it, provide
the snapshot.

Post Lab Tasks:

1. Implement the generic codes for signal operations described in section 1.

Comments:

You might also like