PCS Lab-3
PCS Lab-3
PCS Lab-3
α{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:
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.
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]
6. Energy:
Where the subscript * is used for complex conjugate of the signal x. The energy of the
finite duration signal is computed in MATLAB as.
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)
>> 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.
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