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

Experiment # 2: Communication Signals: Generation and Interpretation Objective

This document describes an experiment on generating and interpreting communication signals using MATLAB. The objectives are to use MATLAB to generate different signals important in communication theory and understand the basics of signals and operations. The document discusses generating sinusoidal, discrete time, unit impulse, unit step, exponential, random, and periodic sequences. It also covers signal addition and multiplication operations through MATLAB code examples. The post lab questions involve generating specified signals using the functions defined in the document.

Uploaded by

Syed F. J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
164 views

Experiment # 2: Communication Signals: Generation and Interpretation Objective

This document describes an experiment on generating and interpreting communication signals using MATLAB. The objectives are to use MATLAB to generate different signals important in communication theory and understand the basics of signals and operations. The document discusses generating sinusoidal, discrete time, unit impulse, unit step, exponential, random, and periodic sequences. It also covers signal addition and multiplication operations through MATLAB code examples. The post lab questions involve generating specified signals using the functions defined in the document.

Uploaded by

Syed F. J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

SYED FURQAN JAVED (2019-EE-280), SECTION : A

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 Analogue 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
SYED FURQAN JAVED (2019-EE-280), SECTION : A

See the output, change the phase shift value and observe the differences.

Input & Output of Example 2.1:

For Phase Shift = 2π:


SYED FURQAN JAVED (2019-EE-280), SECTION : A

For Phase Shift = 2π/3:

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');
SYED FURQAN JAVED (2019-EE-280), SECTION : A

Figure 2.2

Input & Output of Example 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];
end
SYED FURQAN JAVED (2019-EE-280), SECTION : A

Function Code:
t = (-1:0.01:5)';
unitstep = t>=0;
plot(t,unitstep)

Plot:
SYED FURQAN JAVED (2019-EE-280), SECTION : A

Unit Step Sequence:

It is defined as

{
u(n)= 1 n ≥ 0
0 n≤ 0
The MATLAB code for stem sequence function is given below:

function [x, n] = steppes (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 = [n0, n1: n2];
% x = [zeros (1, (n0-n1)), ones (1, (n2-n0+1))];
x = [(n-n0) == 0];
end

Function Code:

Plot:
SYED FURQAN JAVED (2019-EE-280), SECTION : A

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

>> n = [0:10];

>> x = (0.9).^n;

Complex Valued Exponential Sequence:


SYED FURQAN JAVED (2019-EE-280), SECTION : A

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

Result:

Random Sequence:
SYED FURQAN JAVED (2019-EE-280), SECTION : A

Many practical sequences cannot be described by the mathematical expressions like above, these are called
random sequences. They depend upon the parameters like probability density function or their statistical
moments. In MATLAB two types of random sequences are available. See the code below:

>> rand (1,N)

And
>> 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
SYED FURQAN JAVED (2019-EE-280), SECTION : A

fundamental period. Implement code given below and see the periodicity.

% Example 2.4

% Generation of periodic sequences


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
SYED FURQAN JAVED (2019-EE-280), SECTION : A

Signals Operations:
Signal Addition
This is basically sample by sample addition. The definition is given below:
¿
The length of x 1 and x 2 should be equal. See the MATLAB code below:
function [x, 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;
end

% 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;
axis ([-5 10 -5 5]);
xlabel ('n');
ylabel ('y(n)');
title ('Added Signals');
SYED FURQAN JAVED (2019-EE-280), SECTION : A

Figure 2.5
Input & Output on MATLAB:

Signal Multiplication:

The multiplication of two signals is basically sample by sample multiplication or you can say that dot
multiplication. By definition it is
{ x 1 ( n ) } . { x 2 ( n ) }={x 1 ( n ) . x 2(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:
SYED FURQAN JAVED (2019-EE-280), SECTION : A

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)
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');
SYED FURQAN JAVED (2019-EE-280), SECTION : A

Figure 2.6

Input & Output on MATLAB:


SYED FURQAN JAVED (2019-EE-280), SECTION : A

POST LAB

Write MATLAB code to plot these signals:

a. x [n] = 2sin (3n) + 2cos (3n)

Code & Output:

b. x [n] = u[n] + 4cos (3n)

Code & Output:


SYED FURQAN JAVED (2019-EE-280), SECTION : A

c. x [n] = n[u(n) – u(n-10)] + 10e-0.3(n-10)[u(n-10)-u(n-20)]

Input & Output:

You are not allowed to multiply impulse sequences with a number. Implement this by using impseq, stepseq

and sigadd functions.


SYED FURQAN JAVED (2019-EE-280), SECTION : A
SYED FURQAN JAVED (2019-EE-280), SECTION : A
Lab Manual of Analog & Digital Communication
Engr. Iqra Farhat

You might also like