Exp 2
Exp 2
Experiment # 2
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
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)
x = [(n-n0) == 0];
Lab Manual of Analog & Digital Communication
u(n) = 1 n ≥ 0
0n≤0
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
% 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)
y1 = zeros(1,length(n)); % initialization
y2 = y1;
y = y1 + y2;
%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
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)
y1 = zeros(1,length(n)); % initialization
y2 = y1;
y = y1 .* y2;
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
You are not allowed to multiply impulse sequences with a number. Implement this by using
impseq, stepseq and sigadd functions.