Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PCS Lab-3

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

PCS Lab # 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 Analogue Communication.
SIGNAL OPERATIONS:
1. Scaling:
In this operation the sample of the signal is multiplied by a scalar α. The mathematical
operator ‘*’ is used for the implementation of the scaling property.
The MATLAB code is given below.

α{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 by adding/ subtracting ‘k’ to each element. The code is
given below:

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


% implement y(n) = x (n - n0)
% 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 demonstrates the use of stepseq, sigshift, sidadd & sigmult function
close all;
clear all;
[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)');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[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');
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.

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

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);
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 concerned. It is mathematically defined 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.
x(n) h(n) y(n)

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