Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Lab :03 Operations on Signals

LAB-3: Implementation of signal addition, multiplication, scaling,


shifting, folding, sample summation, even and odd synthesis on
Matlab.
OBJECTIVES:

 To study basic operations on signals and implement them on MATLAB.


 To compute even and odd parts of any signal.

BASIC OPERATIONS

TRANSFORMATION OF THE INDEPENDENT VARIABLE

TIME SHIFT

𝒙[𝒏 − 𝒏𝒐] (3-1)

A simple and very important example of transforming the independent variable of a signal
is a time shift. A time shift discrete time in it we have two signals𝒙[𝒏] and 𝒙[𝒏 − 𝒏𝒐]that
is identical in shape, but are displaced or shifted relative to each other. Eq.1 shows a time
shifted discrete-time signal.

TIME REVERSAL

𝒙[−𝒏] (3-2)

A Time reversal signal x[−n] of x[n]is obtained by reflection about n=0 (i.e by reversing
the signal).

TIME SCALING

𝒙[𝜶𝒏] (3-3)

If we represent three signals x[n] , x[2n], x[3n] , that are related by linear scale changes
in the independent variable. If we think of the example x[n] as tape recording, then x[2n]
Lab :03 Operations on Signals

is that recording played at twice the speed, and x[n/2] is the recording played at half-
speed.

ADDITION AND MULTIPLICATION


Two discrete time signals x1[n]and x2[n] can be added up using standard addition if both
having the same order /or equal in length. Same rule holds for the multiplication in
standard form. But if both have unequal length then in this case we can also solve this
problem, using different strategy as in MATLAB there is no built-in function for solving
such problems so we have to make our own user defined function using function-file code
of such problems is given in the lab tasks. Using that code we can easily solve and get the
desired output.

PERIODIC SEQUENCE
A sequence x[n] is periodic if

𝒙[𝒏] = 𝒙[𝒏 + 𝑵]; ∀𝒏 (3-4)

The smallest integer that satisfies the above relation is called the fundamental period.

EVEN AND ODD SIGNALS


"x[n]"is an even signal if it is identical to its time-reversal counterpart i.e.

𝒙[−𝒏] = 𝒙[𝒏] (3-5)


Similarly the signal is referred to as odd if

𝒙[−𝒏] = −𝒙[𝒏] (3-6)

The even part can be evaluated by the formula given below

𝑬𝑽𝑬𝑵{𝒙[𝒏]} = 𝟏/𝟐[𝒙[𝒏] + 𝒙[−𝒏]] (3-7)

and for odd part the operatoin will be like

𝑶𝑫𝑫{𝒙[𝒏]} = 𝟏/𝟐[𝒙[𝒏] − 𝒙[−𝒏]] (3-8)


Lab :03 Operations on Signals

LAB TASK

TASK1: SIGNAL ADDITION.

Signal addition is implemented in MATLAB by using the arithmetic operator “+”. However, the
length of x1(n) and x2(n) must be same. If sequences are of unequal length, or if the sample
positions are different for equal length sequences; then we can’t directly use the operator “+”.
Implement below code for adding sequences of unequal length:

function [y,n] = sigadd(x1,n1,x2,n2)


%implements y(n)= x1(n)+x2(n)
%y[y,n]=sigadd(x1,n1,x2,n2)
%y=sum sequence over n, which includes n1 and n2
%x1=first sequence over n1
%x2= second sequence over n2 (n2 can be different from n1)
n=min(min(n1),min(n2)):max(max(n1),max(n2));
y1=zeros(1,length(n)); y2=y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1+y2;

end
 Generate x1 and x2 given below
𝟏; 𝟏 ≤ 𝒏𝟏 ≤ 𝟗
𝒙𝟏 [𝒏𝟏] = {
𝟎; 𝒐𝒕𝒉𝒆𝒓𝒘𝒊𝒔𝒆
𝟏; 𝟑 ≤ 𝒏𝟐 ≤ 𝟏𝟎
𝒙𝟐 [𝒏𝟐] = {
𝟎; 𝒐𝒕𝒉𝒆𝒓𝒘𝒊𝒔𝒆
 Add x1[n] and x2[n] using function “sigadd”.

TASK 2: SIGNAL MULTIPLICATION.

Signal multiplication is implemented in MATLAB by using the array operator “.*”. However, the
length of x1(n) and x2(n) must be same. If sequences are of unequal length, or if the sample
positions are different for equal length sequences; then we can’t directly use the operator “.*”.
Implement below code for multiplying sequences of unequal length:

function [ y,n ] = sigmult(x1,n1,x2,n2 )


%implements y(n)= x1(n) *x2(n)
%-------------------------------------------
%y[y,n]=sigmult(x1,n1,x2,n2)
%y=product sequence over n, which includes n1 and n2
%x1=first sequence over n1
%x2= second sequence over n2 (n2 can be different from all)
Lab :03 Operations on Signals

%
n=min(min(n1),min(n2)):max(max(n1), max(n2)); % duration of y(n)
y1=zeros(1,length(n)); y2=y1; % initiallization
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
y=y1.*y2;
end

 Multiply both the signals defined in task 1 x1 [n] and x2 [n] using the function “sigmult”.

TASK 3: SCALING

In this operation each sample is multiplied by a scalar α.

𝛂{𝐱(𝐧)} = {𝛂𝐱(𝐧)} (3-9)

An arithmetic operator “*” is used to implement the scaling operation In MATLAB.

 Scale both the signals defined in task 1 x1 [n] and x2 [n] such that we get 2x1 [n] ,5x2 [n].
 Show the results to the instructor.

TASK 4: SHIFTING

In this each sample of “x(n)” is shifted by an amount “k” to obtain a shifted sequence “y(n)”

𝒚(𝒏) = {𝒙(𝒏 − 𝒌)} (3-10)

function [y,n]= sigshift(x,m,n0)


%implements y(n)= x(n-n0)
%------------------------------------------
%[y,n] = sigshift (x,m,n0)
%
n=m+n0; y=x;

 Using function “sigshift”, shift x1 [n] in task 1 such that x1 [n − 4].


Lab :03 Operations on Signals

TASK 5: FOLDING

In this operation each sample of “x(n)” is flipped around n=0, to obtain a folded sequence “y(n)”

𝒚(𝒏) = {𝒙(−𝒏)} (3-11)

In MATLAB this operation is implemented by “fliplr(x)” function for sample values and by
“flipper(n)” function for sample positions as shown in the “sigfold” function.

function [y,n]= sigfold(x,n)


%implements y(n)= x(-n)
%------------------------------------------
%[y,n] = sigfold(x,n)
%
Y= fliplr(x); n= -fliplr(n)

 Fold the signal obtained in the task 1 and show to the instructor.

TASK 6: SAMPLE SUMMATION.

This operation differs from signal addition operation. It adds all sample values of x(n) between
x(n1) and x(n2).

𝐧𝟐
(3-12)
∑ 𝐱(𝐧) = 𝐱(𝐧𝟏) + ⋯ + 𝐱(𝐧𝟐)
𝐧=𝐧𝟏

ss = sum(x(n1:n2));

It is implemented by the sum(x(n1:n2)) function.

Using function “sum”, add samples of x1 [n] at 2,3,4,5 sample positions.


Lab :03 Operations on Signals

Using function “sum”, add samples of x1 [n] at 7,8,9,10 sample positions.

What result you have concluded from the functions “sigadd” and “sum”

TASK 7: SAMPLE PRODUCTS

This operation also differs from the signal multiplication operation. It multiplies all sample values
of x(n) between n1 and n2.
𝐧𝟐
(3-13)
∏ 𝐱(𝐧) = 𝐱(𝐧𝟏 ) × … × 𝐱(𝐧𝟐 )
𝐧𝟏

sp = prod(x(n1:n2));

 Using function “prod”, multiply samples of 𝒙𝟏 [𝒏] at 3,4,5 sample positions.


 Using function “prod”, multiply samples of 𝒙𝟏 [𝒏] at 8,9,10 sample positions.
 What result have you concluded from the functions “sigmult” and “prod”

TASK 8: EVEN AND ODD SYNTHESIS

function [xe, xo, m]= evenodd(x,n)


%Real signal decomposition into even and odd parts
%------------------------------------------------------------------
%[xe,xo,m]= evenodd(x,n)
%
m= -fliplr(n);
m1=min([m,n]); m2=max([m,n]); m= m1:m2;
nm=n(1)-m(1); n1= 1:length(n);
x1=zeros(1,length(m));
x1(n1+nm)= x; x=x1;
xe= 0.5*(x + fliplr(x));
xo= 0.5*(x- fliplr(x));
Lab :03 Operations on Signals

 Split the signal X1[n] obtained in the task 1 into its even and odd parts and show to the
instructor.
 Use stem function and plot ye , yo , and compare it to the 𝐲[𝐧]
Lab :03 Operations on Signals

LAB ASSIGNMENT
P.1

Generate
𝒙(𝒏) = 𝒆(−𝒋𝟒𝝅𝒏) , 𝟎 ≤ 𝒏 ≤ 𝟏𝟎

𝒚(𝒏) = 𝒆(−𝟒𝒏) 𝒙(𝒏) + 𝒙(𝒏 − 𝟒)𝟎 ≤ 𝒏 ≤ 𝟏𝟎


Solve this by calling , signal add, signal shift functions, and show the result graphically.

P.2

Generate the complex-valued signal

𝒙(𝒏) = 𝒆(−𝟒𝝅𝒏) , 𝟎 ≤ 𝒏 ≤ 𝟏𝟎

Plot its even and odd part, and show the graph in which all x(n), xe(n) and xo(n) are given using
subplot command.

You might also like