0% found this document useful (0 votes)
34 views9 pages

Exp 3

- The document summarizes signal operations in communication signals including scaling, shifting, folding, sample summation, sample product, energy, even and odd sequences, and convolution. It provides MATLAB code examples to demonstrate how to implement these operations on signals.

Uploaded by

Mohammad Hasnain
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)
34 views9 pages

Exp 3

- The document summarizes signal operations in communication signals including scaling, shifting, folding, sample summation, sample product, energy, even and odd sequences, and convolution. It provides MATLAB code examples to demonstrate how to implement these operations on signals.

Uploaded by

Mohammad Hasnain
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/ 9

Lab Manual of Analog & Digital Communication

Experiment # 3

Communication Signals: Operations


Objective

• To learn the use of MATLAB for different operations on signals.


• To develop a thorough understanding of communication signals and their basic
operations as used in Communication.

SUMMARY

• Signal operations (Scaling, Shifting, Folding, Sample Summation, Sample product,


Energy, Even and Odd sequences, Convolution)

SIGNAL OPERATIONS:
1. Scaling:

In this operation the samples of the signal is multiplied by a scalar α. The


mathematical operator * is used for the implementation of the scaling property.
α{x(n)} = { α x(n)}

>> [x,n] = stepseq (-1,-5,5);

>> a = 2;

>> y = a*x;

>> subplot (2,1,1);

>>stem (n,x);grid on;

>> subplot (2,1,2);

>> stem (n,y, 'r');

>> grid on;

2. Shifting
In this operation, each sample of the signal is shifted by k to get a shifted

signal. By definition: y(n) = {x (n-k)}

In this operation there is no change in the array or vector x, that contains the samples of
the signal. Only n is changed be adding k to each element. The function is given below:
function [y,n] = sigshift (x,m,n0)

% implement y(n) = x(n-n0)


Lab Manual of Analog & Digital Communication

% x = samples of original signal

% m = index values of the signal

% n0 = shift amount , may be positive or negative

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

n = m+n0;

y = x;

See the example of above function:

%Example 3.1
% This example demonstrate the use of stepseq, sigshift, sidadd & sigmult

function clc; clear;

[x,n] = stepseq (0,-

10,10); subplot (3,2,1);

stem (n,x);

axis ([-12 12 0

3]); grid on;

xlabel ('n');

ylabel

('x(n)');

title ('Original Signals');

[y1,n1] = sigshift(x,n,2.5);

subplot (3,2,2);

stem (n1,y1); axis ([-12 12 0 3]); grid on;

xlabel ('n');

ylabel

('y1(n)');

title ('Shifted signal,x(n-2.5)');


Lab Manual of Analog & Digital Communication

%
[y2,n2] = sigshift (x,n,-2.5);

subplot (3,2,4);

stem (n2,y2);

axis ([-12 12 0 3]);

grid on;

xlabel ('n');

ylabel ('y2(n)');

title ('Shifted signal,x(n+2.5)');

[y_add,n_add] = sigadd(y1,n1,y2,n2);

subplot (3,2,6);

stem (n_add,y_add,'r');

axis ([-12 12 0 3]);

grid on;

xlabel ('n');

ylabel ('y1(n) + y2(n)');

title ('Added Signal');

[y_mul,n_mul] = sigmult(y1,n1,y2,n2);

subplot (3,2,5);

stem (n_mul,y_mul,'k');

axis ([-12 12 0 3]);

grid on;

xlabel ('n');

ylabel ('y1(n) * y2(n)');

title ('Multiplied Signal');

%
Lab Manual of Analog & Digital Communication

Figure 3.1

3. Folding:

In this operation each sample of x(n) is flipped around n=0 to obtain a folded

signal y(n). y (n) = {x(-n)}

In MATLAB, this function is implemented by using a built-in function fliplr(x) and –


fliplr(x). Its implementation is given below:
function [y,n] = sigfold(x,n)

% implements y(n) = x(-n)

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

% x = samples of the original signal

% n = indexes of the original signal

y = fliplr(x);

n = -fliplr (n);

Do its example by yourself from any example signals.

Page | 62
Lab Manual of Analog & Digital Communication

4. Sample Summation:

This operation is different from sigadd function. In this operation we add all the sample
values of any signal x(n) between any two of its index values. By definition
∑ x(n) = x(n1) +………+x(n2)
In MATLAB it is implemented by the sum(x(n1:n2)) command. See the code below for the
demonstration of above function.
>> [x,n] = stepseq (5,0,10)

>> sum(x(2:7))

5. Sample Product:
This operation also differs from the sigmult function. It implies the sample values over the
range n1:n2. It is implemented by the prod(x(n1:n2)). See the code below.
>> x = [0 1 2 3 4 5]

>> prod(x(2:5))

6. Energy:

The energy of any signal x is computed by the mathematical relation:


Ex = ∑ x(n) x*(n) = ∑│x(n)│2
Where the subscript * is used for complex conjugate of the signal x. The energy of the finite
duration signal is computed in MATLAB as.
>> Ex = sum (x.*conj(x));

Or
>> Ex = sum (abs(x).^2);

7. Even and Odd Sequence:


A real valued sequence xe(n) is called even if the following condition satisfies.
xe(-n) = xe(n)
Similarly a signal is said to be an odd signal if
xo(-n) = -xo(n)

See the example below:

%example 3.2
% Generation of even and odd signals

n1 = [0:0.01:1];
Lab Manual of Analog & Digital Communication

x1 = 2*n1;

n2 = [1:0.01:2];

x2 = -2*n2+4;

n = [n1,n2];

x = [x1,x2];

%Even Signal

[xe,ne] = sigfold(x,n);

%Plotting of original signal

subplot (3,1,1);

plot (n,x);

axis ([-4 4 0 2.5]);

grid on;

%Plotting of original signal + even signal

subplot (3,1,2);

plot (n,x/2,ne,xe/2);

axis ([-4 4 0 2.5]);

grid on;

% Plotting of original signal + odd

signal xo = -xe;

no = ne;

subplot (3,1,3);

plot (n,x/2,no,xo/2);

axis ([-4 4 -2.5 2.5]);

grid on;
Lab Manual of Analog & Digital Communication

Figure 3.2

The above example shows to develop the even and odd signals from a given signal. Now we
are going to develop a function to compute the even and odd signals for ourselves. See the
code of function file below:
function [xe,xo,m] = evenodd (x,n)

% Decomposes a real function into its even and odd parts

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

% xe = even signal

% xo = odd signal

% m = indexes

% x = original signal

% n = indexes for original signal

if any(imag(x)~=0)

error(‘x is not a real sequence’)

end

m = -fliplr(n);

m1 = min([m,n]);

m2 = max([m,n]);

m = m1:m2;

nm = n(1)-m(1);
Lab Manual of Analog & Digital Communication

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));

Now change the example 3.2 code to implement the same example with this
function.
8. Convolution:

The convolution is very important operation as far the system as their impulse responses are
concern. It is mathematically defines as:
y (n) = x(n) * h(n)
Where h(n) is the impulse response of the system. The above definition is best depicted by
the following diagram.

In MATLAB convolution is implemented by the following instructions.


>> x = [1 5 3 9 1 2 3 8 5 -3 0 4];

>> h = [1 0 2 3];

>> y = conv(x,h);

A function is developed which will evaluate convolution in a more precise form and also
calculate the indexes to help us plot the sequences.
function [y,ny] = conv_m(x,nx,h,nh)

% Modified convolution routine for signal processing

% [y,ny] = conv_m(x,nx,h,nh)

% [y,ny] = convolution result

% x = original signal

% nx = index values

% h = impulse response signal

% nh = index values for impulse response

nyb = nx(1) + nh(1);


Lab Manual of Analog & Digital Communication

nye = nx(length(x)) + nh(length(h));

ny = [nyb:nye];

y = conv(x,h);

POST LAB

a. x(n) = u(n) – u(n-5). Decompose into even and odd components and plot them.

b. n = [-2:2]

x1 = [3,2,1,-2,-3];

x2 = [1,1,1,1,1]

Implement y = x1*x2

You might also like