Exp 3
Exp 3
Exp 3
Experiment # 3
SUMMARY
SIGNAL OPERATIONS:
1. Scaling:
>> a = 2;
>> y = a*x;
2. Shifting
In this operation, each sample of the signal is shifted by k to get a shifted
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)
% [y,n] = sigshift(x,m,n0)
n = m+n0;
y = x;
%Example 3.1
% This example demonstrate the use of stepseq, sigshift, sidadd & sigmult
stem (n,x);
axis ([-12 12 0
xlabel ('n');
ylabel
('x(n)');
[y1,n1] = sigshift(x,n,2.5);
subplot (3,2,2);
xlabel ('n');
ylabel
('y1(n)');
%
[y2,n2] = sigshift (x,n,-2.5);
subplot (3,2,4);
stem (n2,y2);
grid on;
xlabel ('n');
ylabel ('y2(n)');
[y_add,n_add] = sigadd(y1,n1,y2,n2);
subplot (3,2,6);
stem (n_add,y_add,'r');
grid on;
xlabel ('n');
[y_mul,n_mul] = sigmult(y1,n1,y2,n2);
subplot (3,2,5);
stem (n_mul,y_mul,'k');
grid on;
xlabel ('n');
%
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
% [y,n] = sigfold(x,n)
y = fliplr(x);
n = -fliplr (n);
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:
Or
>> Ex = sum (abs(x).^2);
%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);
subplot (3,1,1);
plot (n,x);
grid on;
subplot (3,1,2);
plot (n,x/2,ne,xe/2);
grid on;
signal xo = -xe;
no = ne;
subplot (3,1,3);
plot (n,x/2,no,xo/2);
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)
% [xe,xo,m] = evenodd(x,n)
% xe = even signal
% xo = odd signal
% m = indexes
% x = original signal
if any(imag(x)~=0)
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.
>> 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)
% [y,ny] = conv_m(x,nx,h,nh)
% x = original signal
% nx = index values
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