You are on page 1of 30

MANGALORE INSTITUTE OF TECHNOLOGY & ENGINEERING

Accredited by NAAC with A+ Grade, An ISO 9001: 2015 Certified Institution


(A Unit of RajalaxmiEducation Trust®, Mangalore - 575001)
Affiliated to V.T.U., Belagavi, Approved by AICTE, New Delhi.
Mijar, Moodabidri – 574225, Mangalore Tq, D.K Dist., Karnataka

Department of Electronics & Communication Engineering


(Accredited by NBA)

BASIC SIGNAL PROCESSING


LABORATORY
(21EC33)
Sl.no Experiment/Contents Page no
A About SciLab 1-7
1 Program to create and modify a Vector and Matrix 8-9
2 Programs on Basic Operations on Matrix 10-14
3 Programs to solve system of Linear Equations 15
4 Programs for Gram-Schmidt Orthogonalization 16
5 Eigen values and Eigen vectors of a given square matrix 17-18
6 Program to find Singular value decomposition 19
7 Program to generate discrete waveforms 20-21
8 Program to perform basic operation on signals 22-23
Program to perform Linear Convolution of two given
9 24-25
sequence
10 Properties of Convolution 26
Program to compute step response from given impulse
11 27-28
response
12 Program to find Z-Transform and Inverse Z Transform 29-30
Basic Signal Processing Laboratory (21EC33)

ABOUT SCILAB

Overview of Scilab

Scilab is a programming language associated with a rich collection of numerical algorithms


covering many aspects of scientific computing problems. From the software point of view, Scilab
is an interpreted language. This generally allows to get faster development processes, because
the user directly accesses a high-level language, with a rich set of features provided by the
library. The Scilab language is meant to be extended so that user-defined data types can be
defined with possibly overloaded operations. Scilab users can develop their own modules so that
they can solve their particular problems. The Scilab language allows to dynamically compile and
link otherlanguages such as Fortran and C: this way, external libraries can be used as if they werea
part of Scilab built-in features. Scilab also interfaces LabVIEW, a platform and development
environment for a visual programming language from National Instruments. From the license
point of view, Scilab is a free software in the sense that the user does not pay for it and Scilab is
an open source software, provided under the Cecill license. The software is distributed with source
code, so that the user has an access to Scilab’s most internal aspects. Most of the time, the user
downloads and installs a binary version of Scilab, since the Scilab consortium provides Windows,
Linux and Mac OS executable versions. Online help is provided in many local languages. From
the scientific point of view, Scilab comes with many features. At the very beginning of Scilab,
features were focused on linear algebra. But, rapidly, the number of features extended to cover
many areas of scientific computing.
The following is a short list of its capabilities:

• Linear algebra, sparse matrices


• Polynomials and rational functions
• Interpolation, approximation
• Linear, quadratic and non-linear optimization
• Ordinary Differential Equation solver and Differential Algebraic Equations solver
• Classic and robust control, Linear Matrix Inequality optimization
• Differentiable and non-differentiable optimization
• Signal processing
• Statistics
Scilab provides many graphics features including a set of plotting functions which allow us to

Dept. of E&CE, MITE, Moodabidri Page 1


Basic Signal Processing Laboratory (21EC33)

create 2D and 3D plots as well as user interfaces. The Xcos environment provides a hybrid
dynamic systems modeler and simulator.
How to get and install Scilab

Whatever the platform is (i.e. Windows, Linux or Mac), Scilab binaries can be downloaded
directly from the Scilab homepage http://www.scilab.org or from the Download area
http://www.scilab.org/download. Scilab binaries are provided for both 32 and 64-bit platforms so
that they match the target installation machine. Scilab can also be downloaded in source form, so
that we can compile Scilab by ourselves and produce our own binary. Compiling Scilab and
generating a binary is especially interesting when we want to understand or debug an existing
feature, or when we wantto add a new feature. To compile Scilab, some prerequisites binary files
are necessary, which are also provided in the Download center. Moreover, a Fortran and a C
compilerare required.

Become familiar with Scilab

The useful workspace in Scilab consists of several window:

 The console for making calculations


 The editor for writing programs
 The graphics windows for displaying graphics
 The embedded help

The general environment and the console

After double clicking the icon to launch Scilab, the Scilab environment by default consists of the
following docked windows: The console, files and variables browsers and the command history.
In the console, after the prompt

-->

Just type a command and press the Enter key (Windows and Linux) or the Return key (Mac OS
X) in the keyboard to obtain the corresponding result.

The menu bar


The menus listed below are particularly useful.

Applications

• The command history allows us to find all the commands from previous
sessions to the current session.
Dept. of E&CE, MITE, Moodabidri Page 2
Basic Signal Processing Laboratory (21EC33)

• The variables browser allows us to find all variables previously used during the
current session.

Edit
Preferences (in Scilab menu under Mac OS X) allows us to set and customize colours, fonts and
font size in the console and in the editor, which is very useful for screen projection. Clicking on
Clear Console clears the entire content of the console. In this case, the command history is still
available and calculations made during the session remain in memory. Commands that have been
erased are still available through the keyboard’s arrow keys.

The Editor

Typing directly into the console has two disadvantages: it is not possible to save the commands
and it is not easy to edit multiple lines of instruction. The editor is the appropriate tool to run
multiple instructions.
Opening the Editor

To open the editor from the console, click on the first icon in the toolbar or on Applications 
SciNotes in the menu bar. The editor opens with a default file named “Untitled 1 “.
Saving

Any file can be saved by clicking on File  Save as

The extension “.sce “at the end of a file name will launch automatically Scilab when opening it
(except under Linux and Mac OS X).
Copying into the console, executing a program

In clicking on Execute in the menu bar, three options are available:


• Execute “…file with no echo “(Ctrl+Shift+E under Windows and Linux, Cmd+Shift+ E under
Mac OS X): the file is executed without writing the program in the console (saving the file first
is mandatory).

• Execute “… file with echo “(Ctrl+L under Windows and Linux, Cmd+L under Mac OS X):
rewrites the file into the console and executes it.

• Execute “…until the caret, with echo “(Ctrl+E under Windows and Linux, Cmd+E under
Mac OS X): rewrites the selection chosen with the mouse into the console and executes it or
executes the file data until the caret position defined by the user. Standard copy/paste can also be
used.

Dept. of E&CE, MITE, Moodabidri Page 3


Basic Signal Processing Laboratory (21EC33)

Variables, assignment and display

Variables

Scilab is not a computer algebra system. It calculates only with numbers. All calculations are done
with matrices, although this may go unnoticed. Even if the concept of matrices is unknown, vectors
and sequences of numbers can explain it, as they are, in fact, matrices of dimension 1 × nor n × 1
and a number is itself a matrix of dimension 1 × 1. Variables do not need to be declared in advance,
but any variable must have a value. For example, obtaining the value of a variable which has not
been given a value produces an error.

-->a
! --error 4

Undefined variable: a
If a value is assigned to the variable a, there is no longer an error:

--> a=%pi/4 a =

--> a
a=
0.7853982

0.7853982

Variables may take any name that is not already defined by the system:
--> Piby2=%pi/2 Piby2 =

1.5707963

The result of a calculation that is not assigned to a variable is automatically assigned to the variable
called ans:

-->3*(4-2)
ans =
6.
-->ans ans =
6.

Functions

Functions are the easiest and most natural way to make computations from variables a nd for
obtaining results from variables.
Dept. of E&CE, MITE, Moodabidri Page 4
Basic Signal Processing Laboratory (21EC33)

A function definition begins with function and ends with endfunction.


Requesting the assignment of a variable
Assignment is made easily using the “= “operator.

Display Writing

Typing the name of a variable displays its value, except when there is “; “at the end of the command
line.

Brackets
Matrices are defined using square brackets.
As mentioned before, matrix computation is the basis of calculations in Scilab. A spac e or comma
is used to separate columns and semicolons are used to separate rows.
To define a column vector and obtain a column display:

-->v=[3;-2;5]
v=
3.
- 2.
5.

To define a row vector and obtain a row display:


--> v = [3,-2,5]
v=
3. - 2. 5.

To define a matrix and obtain a tabular display:


--> m = [1 2 3;4 5 6;7 8 9]
m=
1. 2. 3.
4. 5. 6.
7. 8. 9.

disp function

The disp must always be used with parentheses. With the vector v previously defined:
-->v(2)
ans =
- 2.

-->disp(v(2))
- 2.

Dept. of E&CE, MITE, Moodabidri Page 5


Basic Signal Processing Laboratory (21EC33)

To display a string (usually a sentence), put it between quotes:


-->disp("The solution is") will display the following The solution is

Additional information on matrices and vectors Accessing elements


Square braces are used to define matrices. A space or a comma is used to switch from one column
to another and semicolons are used to switch from one line to another.

-->m= [1 2 3;4 5 6]
m=
1. 2. 3.
4. 5. 6.

Parentheses are used to access elements or to modify them.

-->m(2,3)
ans =
6.

-->m(2,3)=23
m=
1. 2. 3.
4. 5. 23.

The “ : “ operator is used to designate all the rows or all columns of a matrix. To view the second
row of the matrix m, type:

-->m(2,:)
ans =
4. 5. 23.
To view the third column:
-->m(:,3)
ans = 3.
23.

To obtain the transpose of a matrix or a vector use the single quote symbol “ ' “:
-->m'
ans =
1. 4.
2. 5.
3. 23.

Operations
The operations * “, “/ “are matrix operations. To make element wise operations, we need to put dot
before the operating sign: “.* “, “. / “.
Dept. of E&CE, MITE, Moodabidri Page 6
Basic Signal Processing Laboratory (21EC33)

Solving linear systems


To solve the linear system AX = Y, in which A is a square matrix, use the backslash “\ “
X = A \ Y.
Be cautious, the operation Y / A will give
(only if the dimensions are correct) another result, that is to say the matrix Z for which Z A = Y.

Length
The length function returns the number of coordinates for a vector. The size function returns the
dimensions (rows, columns) for a matrix.

-->U=[1:10]

U=
1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

-->length(U)
ans =
10.

-->m=[1 2 3;4 5 6];

-->size(U) ans =

2. 3.

Dept. of E&CE, MITE, Moodabidri Page 7


Basic Signal Processing Laboratory (21EC33)

1. Program to create and modify a Vector and Matrix

a. To Create/Modify a Vector

Clc; clear; close


V = [1 2 3] // or V = [1, 2, 3] is row vector
disp( ‘row vector is’, V);

V1 = [1; 2; 3] // Column vector


disp(‘Column vector is’ , V1);

V2 = 4+V // Adding a scalar number in vector


disp( ‘adding a number 5’, V2);

V3 = V-3 // subtracting a scalar number in vector


disp(‘ subtracting a number 3’, V3);

V4 = V2 + V3 //Adding two vector


disp(‘addition of two vector’, V4);

V5= V4 * 2 //multiplying a scalar number


disp(‘multiplication by a scalar’, V5);

V6= length(V5) //finding length of a vector


disp(‘length of a vector’, V6);

b. To Create/Modify a Matrix

a = [1 2 3; 4 5 6] // creating a 2x3 matrix


disp(‘matrix is’, a);

disp(‘ a(1,1) element is’ , a(1,1)) // accessing the matrix element

disp( ‘ a(2,3) element is ‘, a(2,3))

disp(‘ all element of row 1 is’, a(1,:)) // accessing all element in row 1

disp(‘ elements of second and third row of each column’, a(: , 2 : 3))

disp(‘ the last element of the matrix a’, a($))

disp(‘the last element of first column is’, a(1,$))

Dept. of E&CE, MITE, Moodabidri Page 8


Basic Signal Processing Laboratory (21EC33)

disp(‘ the last element of each column is’, a(:, $))


a = [a; [3 3 3]] //adding a new row [3 3 3] to the matrix a
disp(‘new matrix a is’, a)

disp(‘ size of new matrix m*n is’, size(a))

b = a^2 // square of matrix a


disp(‘ square of matrix a is’, b)

c = a^3 //cube of matrix a


disp(‘ cube of matrix a is’, b)

d = det(a) // determinant of matrix a


disp(‘determinant of matrix a is’, d)

e = eye(3,3) //identity matrix


disp(‘identity matrix 3*3 is ‘, e);

Dept. of E&CE, MITE, Moodabidri Page 9


Basic Signal Processing Laboratory (21EC33)

2. Programs on Basic Operations on Matrix


a. Matrix Addition
clc
m=input("enter number of rows of the Matrix: ");
n=input("enter number of columns of the Matrix: ");
disp('enter the first Matrix')
for i=1:m
for j=1:n
A(i,j)=input('\');
end
end
disp('enter the second Matrix')
for i=1:m
for j=1:n
B(i,j)=input('\');
end
end
for i=1:m
for j=1:n
C(i,j)=A(i,j)+B(i,j);
end
end
disp('The first matrix is')
disp(A)
disp('The Second matrix is')
disp(B)
disp('The sum of the two matrices is')
disp(C)

Result

Dept. of E&CE, MITE, Moodabidri Page 10


Basic Signal Processing Laboratory (21EC33)

Matrix Addition using Function


clc
function []=addition(m, n, A, B)
C=zeros(m,n);
C=A+B;
disp('The first matrix is')
disp (A)
disp('The Second matrix is')
disp (B)
disp('The sum of two matrices is')
disp (C)
endfunction

Result:

b. Matrix Multiplication
clc
m=input("Enter number of rows of the first Matrix: ");
n=input("Enter number of columns of the first Matrix: ");
p=input("Enter number of rows of the second Matrix: ");
q=input("Enter number of columns of the second Matrix: ");if
n==p
disp('Matrices are conformable for multiplication')else
disp('Matrices are not conformable for multiplication')
break;
end
disp('enter the first Matrix')
for i=1:m
for j=1:n
A(i,j)=input('\');
end

Dept. of E&CE, MITE, Moodabidri Page 11


Basic Signal Processing Laboratory (21EC33)

end
disp('enter the second Matrix')
for i=1:p
for j=1:q
B(i,j)=input('\');
end
end
C=zeros(m,q);
for i=1:m
for j=1:q for
k=1:n
C(i,j)=C(i,j)+A(i,k)*B(k,j);end
end
end
disp('The first matrix is')
disp(A)
disp('The Second matrix is')
disp(B)
disp('The product of the two matrices is')
disp(C)

Result:

Matrix Multiplication using Function


clc
function [ ] = multiplication(m, n, p, q, A, B)
C=zeros(m,n);
if n==p
disp('Matrices are conformable for multiplication')else
Dept. of E&CE, MITE, Moodabidri Page 12
Basic Signal Processing Laboratory (21EC33)

disp('Matrices are not conformable for multiplication')


break;
end
C=A*B
disp('The first matrix is')
disp (A)
disp('The Second matrix is')
disp (B)
disp('The multiplication of two matrices is')
disp (C)
endfunction

C. Matrix Transpose
clc
m=input("Enter number of rows of the Matrix: ");
n=input("Enter number of columns of the Matrix: ");
disp('Enter the Matrix')
for i=1:m
for j=1:n
A(i,j)=input(' ');
end
end
B=zeros(n,m);
for i=1:n
for j=1:m
B(i,j)=A(j,i)
end
end
disp('Entered matrix is')
disp(A)
disp('Transposed matrix is')
Dept. of E&CE, MITE, Moodabidri Page 13
Basic Signal Processing Laboratory (21EC33)

disp(B)

// Matrix Transpose function file


function []=transpose(m, n, A)
B=zeros(m,n);
B=A'
disp('The matrix is')
disp (A)
disp('Transposed matrix is')
disp (B)
endfunction

Result:

Dept. of E&CE, MITE, Moodabidri Page 14


Basic Signal Processing Laboratory (21EC33)

3. Programs to solve system of Linear Equations

clc
A=input("Enter the value of A in Matrix Form: ");
Y=input("Enter the value of Y in Matrix form: ");
disp('Matrix A is ')
disp(A)
disp('Matrix Y is ')
disp(Y)

Yt = Y’;
disp(‘Transposed Matrix Yt is)
disp(Yt)

X = A\Yt;

disp(‘ Solution of the given linear equation is : ‘)


disp(X)

Result:

Dept. of E&CE, MITE, Moodabidri Page 15


Basic Signal Processing Laboratory (21EC33)

4. Programs for Gram-Schmidt Orthogonalization


Apply the Gram – Schmidt process to the vectors ( 1, 0, 1 ) , ( 1, 0, 0, ) and ( 2, 1, 0 ) to produce a
set of orthonormal vectors.

clc; clear; close;

A= [1 0 1;1 0 0; 2 1 0];

//independent of vectors stored in columns of A)

disp(A, ‘A=’);
[m,n] = size(a);

for k=1:n
V(: , k) = A(:,k);
for j =1:k-1;
R(j , k) = V(: , j)’ * A(: , k);

V(: , k) = V(: , k) –R(j , k) * V(: , j);


end

R(k , k) = norm (V(: , k));


V(: , k) = V(: , k)/R(k,k);
End

Disp(v, ‘Q=’);

Result:

Dept. of E&CE, MITE, Moodabidri Page 16


Basic Signal Processing Laboratory (21EC33)

5. Eigen values and Eigen vectors of a given square matrix


Procedure:

Given a square matrix A, we find the characteristic polynomial of A by expanding the matrix
equation | A – λ I |. The Eigen values of A are obtained solving the characteristic equation
| A – λ I | = 0. The corresponding Eigen vectors are obtained by solving the system of equations
Ax = λx.

Clc;clear;close;

A = [3 -2 5; -2 3 6; 5 6 4];
lam = poly(0, ‘lam’);
lam=lam;

Char_Mat = A – lam*eye(3,3);
Disp(Char_Mat, ‘The characteristic Maatrix is’)
Char_Poly = poly(A, ‘lam’)
Disp(Char_Poly, ‘The characteristic polynomial is’)
Lam = spec(A)
Disp(lam, ‘ The eigen value of A are’)

Function[x,lam] = eigenvectors(A)
[n,n] = size(A);
lam = spec(A)’ ;
x = [ ];

for k =1 : 3
B = A –lam(k) * eye(3 , 3); // characteristic matrix
C = B (1 : n-1 , 1: n-1); // coeff matrix for the reduced system
b = -B(1 : n-1 , n); // RHS vector for the reduced system
y = C \ b; // solution for the reduced system
y = [y ; 1];
y = y / norm(y) ; // make unit eigen vector
x = [x y];
end
endfuction

get f(‘eigenvectors’)

[x lam] = eignvectors (A)


disp (x, ‘The eigen vectors of A are’);

Dept. of E&CE, MITE, Moodabidri Page 17


Basic Signal Processing Laboratory (21EC33)

Results:

Dept. of E&CE, MITE, Moodabidri Page 18


Basic Signal Processing Laboratory (21EC33)

6.Program to find Singular value decomposition

clear;
close;
clc;
A=[-1 2 2] ' ;
disp('A=', A );
[U diagnol V]= svd(A);
disp('U=', U );
disp('diagnol=',diagnol );
disp ('V = ',V');
disp ('U*diagnol*V =A = ', U*diagnol*V')

clear;
close;
clc;
A=[-1 2 2 ; 1 1 2];
disp('A=', A );
[U diagnol V]= svd(A);
disp('U=', U );
disp('diagnol=',diagnol );
disp ('V = ',V');
disp ('U*diagnol*V =A = ', U*diagnol*V')

Result

Dept. of E&CE, MITE, Moodabidri Page 19


Basic Signal Processing Laboratory (21EC33)

7.Program to generate discrete waveforms


clc; clear; close;

//Cosine wave in discrete form:


f =0.2;
t =0:0.1:10;
x = cos (2* %pi * t * f ) ;
subplot(3,3,1)
plot2d3 (t ,x )
title ( ' cosine wave ' ) ;
xlabel ( ' sample(n) ' ) ;
ylabel ( ' Amplitude ' ) ;

//Sinc function in discrete form:


t = -10:0.2:10
x = sinc ( t ) ;
subplot(3,3,2)
plot2d3 (t ,x )
title ( ' sinc wave ' ) ;
xlabel ( ' sample(n) ' ) ;
ylabel ( ' Amplitude ' ) ;

//Square wave in discrete form:


t = linspace(0,10,50);
vm = 5*squarewave(t);
subplot(3,3,3)
plot2d3(t,vm)
title ( ' square wave ' ) ;
xlabel ( ' sample(n) ' ) ;
ylabel ( ' Amplitude ' ) ;

//Exponential function in discrete form:


t = -2:0.1:2;
x = exp (t ) ;
subplot(3,3,4)
plot2d3 (t ,x )
title ( ' exponential wave ' ) ;
title ( ' sinc wave ' ) ;
xlabel ( ' sample(n) ' ) ;
ylabel ( ' Amplitude ' ) ;

Dept. of E&CE, MITE, Moodabidri Page 20


Basic Signal Processing Laboratory (21EC33)

//Impulse function:
l = 5;
n = -l:l;
x = [zeros(1,l), ones(1,1), zeros(1,l)];
subplot(3,3,5)
plot2d3(n,x);
title ( ' Impluse Signal ' ) ;
xlabel ( ' sample(n) ' ) ;
ylabel ( ' Amplitude ' ) ;

//Ramp function:
n = 0:10;
x = n;
subplot(3,3,6)
plot2d3(n,x);
title ( ' Ramp Signal ' ) ;
xlabel ( ' sample(n) ' ) ;
ylabel ( ' Amplitude ' ) ;

//Step function:
t=0:4;
y=ones(1,5);
subplot(3,3,7);
plot2d3 (t,y);
xlabel('time');
ylabel('amplitude');
title('Unit Step Discrete Signal');

Results:

Dept. of E&CE, MITE, Moodabidri Page 21


Basic Signal Processing Laboratory (21EC33)

8. Program to perform basic operation on signals


clc ;
clear all;
close ;

// amplification
x= input ( ’ Enter input sequence x : ’ );
a= input ( ’ Enter amplification factor a : ’ );
b= input ( ’ Enter attenuation factor b : ’ );
c= input ( ’ Enter amplitude reversal factor c : ’ );
y1=a*x;
y2=b*x;
y3=c*x;
n= length (x);

// Input signals plot


subplot (2 ,3 ,1);
plot2d3 (0:n -1,x);
xlabel ( ’ t ime ’ );
ylabel ( ’ amplitude ’ );
title ( ’ Input signal ’ );

// Amplification
subplot (2 ,3 ,2);
plot2d3 (0:n -1, y1);
xlabel ( ’ t ime ’ );
ylabel ( ’ Amplitude ’ );
title ( ’ Amplified signal ’ );

// attenuation
subplot (2 ,3 ,3);
plot2d3 (0:n -1, y2);
xlabel ( ’ time ’ );
ylabel ( ’ Amplitude ’ );
title ( ’ Attenuated signal ’ );

// Amplitude Reversal
subplot (2 ,3 ,4);
plot2d3 (0:n -1, y3);
xlabel ( ’ time ’ );
ylabel ( ’ Amplitude ’ );
title ( ’ Amplitude reverse signal ’ );

// folding and Shifting

Dept. of E&CE, MITE, Moodabidri Page 22


Basic Signal Processing Laboratory (21EC33)

n0= input ( ’ Enter the +ve shift : ’ );


n1= input ( ’ Enter the −ve shift : ’ );
l= length (x);
i=n0:l+n0 -1;
j=n1:l+n1 -1;
subplot (2 ,3 ,5);
plot2d3 (i,x);
xlabel ( ’ t ime ’ );
ylabel ( ’ Amplitude ’ );
title ( ’ Positiveshift signal ’ );

subplot (2 ,3 ,6);
plot2d3 (j,x);
xlabel ( ’ t ime ’ );
ylabel ( ’ Amplitude ’ );
title ( ’ Negative Shifted Signal ’ );

Result:

Dept. of E&CE, MITE, Moodabidri Page 23


Basic Signal Processing Laboratory (21EC33)

9.Program to perform Linear Convolution of two given sequence

clc;
clear all;
close ;
x = input(' enter x seq = ' );
h = input(' enter h seq = ');
SIx = input ('enter starting index of input x = ');
EIx = input ('enter ending index of input x = ');
SIh = input ('enter starting index of input h = ');
EIh = input ('enter ending index of input h = ');
SIy = SIx+SIh;
EIy = EIx+EIh;

m = length(x);
n = length(h);

subplot(3,1,1)
m1= SIx:1:EIx;
plot2d3(m1,x)
xlabel('sample ');
ylabel('amplitude');
title(' input signal x[n] ');
n1=SIh:1:EIh;

subplot(3,1,2)
plot2d3(n1,h)
xlabel('sample ');
ylabel('amplitude');
title(' input signal h[n]');

//Method : Using Direct Convolution Sum Formula


for i = 1:1:n+m-1
conv_sum(i) = 0;
for j = 1:1:m
if (((i-j+1) >= 1)&(i-j+1 <= n))
conv_sum(i) = conv_sum(i) + x(j)*h(i-j+1);
end;
//y(i) = conv_sum;
end;
end;

disp('Linear Convolution of the given sequence is y=', conv_sum);

Dept. of E&CE, MITE, Moodabidri Page 24


Basic Signal Processing Laboratory (21EC33)

N1=SIy:1:EIy;
subplot(3,1,3)
plot2d3(N1,conv_sum)
xlabel('sample ');
ylabel('amplitude');
title(' output convoluted signal y[n]');

Re
sul
t:

Dept. of E&CE, MITE, Moodabidri Page 25


Basic Signal Processing Laboratory (21EC33)

10. Properties of Convolution


clc;
clear all;
n=input('first sequence x(n)');
h=input('second sequence h(n');
g=input('third sequence g(n)');
y1=conv(n,h);
y2=conv(h,n);
y3=conv(h,g);
if(y1==y2)
disp('commutative property is verified');
else
disp('commutative property not verified');
end
n1=conv(y1,g);
n2=conv(n,y3);
if(n1==n2)
disp('associative property is verified');
end
y4=h+g;
y5=conv(n,h);
y6=conv(n,g);
y7=conv(n,y4);
y8=y5+y6;
if(y7==y8)
disp('distrubutive property is verified');
end

Result

Dept. of E&CE, MITE, Moodabidri Page 26


Basic Signal Processing Laboratory (21EC33)

12.Program to find Z-Transform and Inverse Z Transform


Z-Transform and ROC of Causal Sequence

//Z - transform of [ 1 0 3 -1 2 ]
clear ;
clc ;
close ;
function [za ]= ztransfer ( sequence ,n)
z= poly (0, ' z ' , ' r ' )
za= sequence*(1/ z)^n'
endfunction

x1 =[1 0 3 -1 2];
n =0: length (x1) -1;
zz= ztransfer (x1 ,n);

// Display the results in command window


disp (zz ,"Z transform of sequence is : ");
disp ( 'ROC is the entire plane except = 0 ' );

Z Transform and ROC of Anticausal Sequence

//Z transform of [-3 -2 -1 0 1 ]


clear ;
clc ;
close ;
function [za ]= ztransfer ( sequence ,n)
z= poly (0, ' z ' , ' r ' )
za= sequence *(1/ z)^n'
endfunction
x1 =[ -3 -2 -1 0 1];
n=-( length (x1) -1) :0;
zz= ztransfer (x1 ,n);
// Display the results in command window
disp (zz ,"Z-transform of sequence i s : ");
disp ( 'ROC is the entire plane except Z = %inf ' );

Dept. of E&CE, MITE, Moodabidri Page 27


Basic Signal Processing Laboratory (21EC33)

Z Transform of the Sequence


//Z- transform of [ 2 -1 3 2 1 0 2 3 -1]
clear ;
clc ;
close ;
function [za ]= ztransfer ( sequence ,n)
z= poly (0, ' z ' , ' r ' )
za= sequence *(1/ z)^n'
endfunction
x1 =[2 -1 3 2 1 0 2 3 -1];
n = -4:4;
zz= ztransfer (x1 ,n);
// Display the results in command window
disp (zz ,"Z-transform of sequence is : ");
disp ( 'ROC i s the e n t i r e plane except = 0 and z =%inf ' );

Dept. of E&CE, MITE, Moodabidri Page 28

You might also like