Lab Manual of Analog & Digital Communication
Experiment # 2
Communication Signals: Generation and Interpretation
Objective
• To the use of MATLAB for generation of different signals important in
communication theory.
• Learn the basics of signals and its operations as used in Communication.
• To develop understanding of communication signals and their properties.
Generation of Signals
Signals are represented mathematically as a function of one or more independent variables.
We will generally refer to the independent variable as time. Therefore we can say a signal is
a function of time. Write these instructions in m-file as execute to see the result.
Sinusoidal Sequence:
% Example 2.1
% Generation of sinusoidal signals
% 2sin( 2πτ-π/2)
t=[-5:0.01:5];
x=2*sin((2*pi*t)-(pi/2));
plot(t,x)
grid on;
axis([-6 6 -3 3])
ylabel ('x(t)')
xlabel ('Time(sec)')
title ('Figure 2.1')
Figure 2.1
See the output, change the phase shift value and observe the differences.
Lab Manual of Analog & Digital Communication
Discrete Time Sequences:
See the example below:
% Example 2.2
% Generation of discrete time signals
n = [-5:5];
x = [0 0 1 1 -1 0 2 -2 3 0 -1];
stem (n,x);
axis ([-6 6 -3 3]);
xlabel ('n'); ylabel
('x[n]'); title
('Figure 2.2');
Figure 2.2
Unit Impulse Sequence:
A unit impulse sequence is defined as
Delta (n) = 1 n = 0
=0 n≠0
We are making a function named imseq and we further use this function in next experiments
of this lab. The MATLAB code is given below:
function [x,n] = impseq(n0,n1,n2)
% Generates x(n) = delta (n-n0); n1<=n,n0 <= n2
% x[x,n] = imseq(n0,n1,n2)
% n0 = impulse position, n1 = starting index, n2 = ending index
If ((n0 < n1) | (n0 > n2) | (n1 > n2))
Error('arguments must satisfy n1 <= n0 <=
n2') end
n = [n1:n2];
% x = [zeros(1,(n0-n1)),1,zeros(1,(n2-n0))];
x = [(n-n0) == 0];
Lab Manual of Analog & Digital Communication
Unit Step Sequence:
It is defined as
u(n) = 1 n ≥ 0
0n≤0
The MATLAB code for stem sequence function is given below:
function [x,n] = stepseq(n0,n1,n2)
% Generates x(n) = u(n-n0); n1 <= n, n0<=n2
% [x,n] = stepseq(n0,n1,n2)
if ((n0 < n1) | (n0 > n2) | (n1 > n2))
error('arguments must satisfy n1 <= n0 <= n2')
end
n = [n1:n2];
% x = [zeros(1,(n0-n1)),ones(1,(n2-n0+1))];
x = [(n-n0) >= 0];
Real Valued Exponential Sequence:
It is define as:
x (n) = an, for all n; a € Real numbers
We require an array operator “ .^ ” to implement a real exponential sequence. See the
MATLAB code below
>> n = [0:10];
>>x = (0.9).^n;
Observe the result
Complex Valued Exponential Sequence:
It is define as:
x(n) = e (a + jb) n , for all n
Where a is called the attenuation and b is the frequency in radians. It can be implemented by
following MATLAB script.
>> n = [0:10];
>> x = exp ((2+3j)*n);
Random Sequence:
Many practical sequences cannot be described by the mathematical expressions like above,
these are called random sequences. In MATLAB two types of random sequences are
available. See the code below:
>>rand (1,N)
Lab Manual of Analog & Digital Communication
>> randn (1,N)
The above instruction generates a length N random sequence whose elements are uniformly
distributed between [0,1]. And the last instruction, randn generates a length N Gaussian
random sequence with mean 0 and variance 1. Plot these sequences.
% example 2.3
%Generation of random sequence
n = [0:10];
x = rand (1, length (n));
y = randn (1, length (n));
plot (n,x) ;
grid on;
hold on;
plot(n,y,'r');
ylabel ('x & y')
xlabel ('n')
title ('Figure 2.3')
Figure 2.3
Periodic Sequences:
A sequence is periodic if it repeats itself after equal interval of time. The smallest interval is
called the fundamental period. Implement code given below and see the periodicity.
%Example 2.4
% Generation of periodic sequences
Lab Manual of Analog & Digital Communication
n = [0:4];
x = [1 1 2 -1 0];
subplot (2,1,1);
stem (n,x);
grid on;
axis ([0 14 -1 2]);
xlabel ('n');
ylabel ('x(n)');
title ('Figure 2.4(a)');
xtilde = [x,x,x];
length_xtilde = length (xtilde);
n_new = [0:length_xtilde-1];
subplot (2,1,2);
stem (n_new,xtilde,'r');
grid on;
xlabel ('n');
ylabel ('perodic x(n)');
title ('Figure 2.4(b)');
Figure 2.4
SIGNALS OPERATIONS:
Signal Addition
This is basically sample by sample addition. The definition is given below:
{x1(n)} + {x2(n)} = {x1(n) + x2(n)}
Lab Manual of Analog & Digital Communication
The length of x1 and x2 should be equal. See the MATLAB code below:
function [y,n] = sigadd(x1,n1,x2,n2)
% implement y(n) = x1(n) + x2 (n)
% [y,n] = sigadd (x1,n1,x2,n2)
% y = sum sequence over n, which include 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)); %duration of y(n)
y1 = zeros(1,length(n)); % initialization
y2 = y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % x1 with duration of y
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % x2 with duration of y
y = y1 + y2;
See example of signal addition below
%Example 2.5
% signal addition using sigadd function
clear;
clc;
n1 = [0:10];
x1 = sin (n1);
n2 = [-5:7];
x2 = 4*sin(n2);
[y,n] = sigadd(x1,n1,x2,n2);
subplot (3,1,1);
stem (n1,x1);
grid on;
axis ([-5 10 -5 5]);
xlabel ('n1'); ylabel ('x1(n)');
title ('1st signal');
subplot (3,1,2);
stem (n2,x2);
grid on; hold on;
axis ([-5 10 -5 5]);
xlabel ('n2'); ylabel ('x2(n)');
title ('2nd signal');
subplot (3,1,3); stem (n,y,'r');
grid on;
Lab Manual of Analog & Digital Communication
axis ([-5 10 -5 5]);
xlabel ('n'); ylabel ('y(n)');
title ('Added Signals');
Figure 2.5
Signal Multiplication:
The multiplication of two signals is basically sample by sample multiplication or you can say
dot multiplication. By definition it is
{x1(n)} . {x2(n)} = {x1(n)x2(n)}
It is implemented by the array operator ‘ .* ‘ that we studied in last lab. A signal
multiplication function is developed that is similar to the sigadd function. See the code
below:
function [y,n] = sigmult (x1,n1,x2,n2)
% implement y(n) = x1(n) * x2 (n)
% [y,n] = sigmult (x1,n1,x2,n2)
% y = product sequence over n, which include 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)): 0.1 : max(max(n1),max(n2)); %duration of y(n)
Lab Manual of Analog & Digital Communication
y1 = zeros(1,length(n)); % initialization
y2 = y1;
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1; % x1 with duration of y
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2; % x2 with duration of y
y = y1 .* y2;
See the example below:
%Example 2.6
% signal multiplication using sigmult function
clear;
clc;
n1 = [0:0.1:10];
x1 = sin (n1);
n2 = [-5:0.1:7];
x2 = 4*sin (n2);
[y,n] = sigmult(x1,n1,x2,n2);
subplot (3,1,1);
stem (n1,x1);
grid on;
axis ([-5 10 -5 5]);
xlabel ('n1');
ylabel ('x1(n)');
title ('1st signal');
subplot (3,1,2);
stem (n2,x2);
grid on;
hold on;
axis ([-5 10 -5 5]);
xlabel ('n2');
ylabel ('x2(n)');
title ('2nd signal');
subplot (3,1,3);
stem (n,y,'r');
grid on;
axis ([-5 10 -5 5]);
xlabel ('n');
ylabel ('y(n)');
title ('Multiplied Signals');
Lab Manual of Analog & Digital Communication
Figure 2.6
POST LAB
Write MATLAB code to plot these signals:
a. x [n] = 2sin (3n) + 2cos (3n)
b. x [n] = u[n] + 4cos (3n)
c. x [n] = n[u(n) – u(n-10)] + 10e-0.3(n-10)[u(n-10)-u(n-20)]
You are not allowed to multiply impulse sequences with a number. Implement this by using
impseq, stepseq and sigadd functions.