You are on page 1of 9

# Digital Signal Processing lab

Group member names: Sabit Hussain Khiyal Hussain Habib-ur-Rehman bsee01093024 bsee01093026 bsee01093109

## Q1: Implement the following commands in matlabs? Ans: (1) Zeros(m,n)

>>a=zeros(2,2) a= 0 0 0 0

(2) Ones(m,n)
>>b=ones(2,2) b= 1 1 1 1

(3) eye(n)
>>c= eye(4) b= 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1

## Ans: Row vector:

The preceding statements create row vectors. For example >> x = 1:5 x= 1 2 3 4 5

Column vector:
To create a column vector, append the transpose operator to the end of the vector-creating expression >> y = (1:5)' y= 1 2 3 4 5

Vectors:
In MATLAB a vector is a matrix with either one row or one column. The distinction between row vectors and column vectors is essential. Many programming errors are caused by using a row vector where a column vector is required, and vice versa.

MATLAB vectors are used in many situations, e.g., creating x-y plots, that do not fall under the rubric of linear algebra. In these contexts a vector is just a convenient data structure. MATLAB still enforces the rules of linear algebra so paying attention to the details of vector creation and manipulation is always important. Scalars In MATLAB a scalar is a variable with one row and one column. Scalars are the simple variables that we use and manipulate in simple algebraic equations.

Creating scalars
To create a scalar you simply introduce it on the left hand side of an equal sign. >> x = 1; >> y = 2; >> z = x + y;

Scalar operations
MATLAB supports the standard scalar operations using an obvious notation. The following statements demonstrate scalar addition, subtraction, multiplication and division. >> u = 5; >> v = 3; >> w = u + v >> x = u - v >> y = u * v >> z = u/v

## Introduction to Matrices in Matlab

A basic introduction to defining and manipulating matrices is given here. It is assumed that you know the basics on how to define and manipulate vectors using matlab.

Defining Matrices
Defining a matrix is similar to defining a vector. To define a matrix, you can treat it like a column of row vectors (note that the spaces are required!): >> A = [ 1 2 3; 3 4 5; 6 7 8] A= 1 3 6 2 4 7 3 5 8

You can also treat it like a row of column vectors: >> B = [ [1 2 3]' [2 4 7]' [3 5 8]']

B= 1 2 3 2 4 7 3 5 8

Array multiplication(.*):
Array multiplication. A.*B is the element-by-element product of the arrays A and B. A and B must have the same size, unless one of them is a scalar. A =1 2 3 456

789; B= 10 20 30 40 50 60 70 80 90

## Array right division(./):

Array right division. A./B is the matrix with elements A(i,j)/B(i,j). A and B must have the same size, unless one of them is a scalar. A = [1 2 3;4 5 6]; B = ones(2, 3); A.\B ans = 1.0000 0.5000 0.3333 0.2500 0.2000 0.1667

Matrix transpose():
Matrix transpose. A' is the linear algebraic transpose of A. For complex matrices, this is the complex conjugate transpose.

A = [1 2 0; 2 5 -1; 4 10 -1] A=

1 2

5 -1

4 10 -1

## We can easily find the transpose of the matrix A. B = A' B=

1 2

5 10

0 -1 -1

Array transpose(.):
Array transpose. A.' is the array transpose of A. For complex matrices, this does not involve conjugation.

A= [1 2 3] A >>A=1 2 3

## Q3: Plot the following function? X= 1/k sin(2kt) Solution:

t= 0:0.01:1; k=1:1:3; x= (1./k)*(sin(2*pi*k*t)); plot (t,x,r); xlabel(----- x-axis time---) ylabel(-----y-axis: function of x---) title(graph of function of x vs time)