Introduction To Signal Processing Using MATLAB
Introduction To Signal Processing Using MATLAB
• >> x = 17
x = 17
• >> x = 'hat'
x = hat
• >> y = 3*sin(x)
y = -1.6097 3.0000
Vectors and Matrices
• MATLAB provides many convenient ways for
creating vectors, matrices, and multi-
dimensional arrays.
• A vector refers to a one dimensional (1×N or
N×1) matrix.
• A matrix generally refers to a 2-dimensional
array, i.e. an m×n array where m and n are
greater than 1.
• Arrays with more than two dimensions are
referred to as multidimensional arrays.
Vectors and Matrices
• Matrices can be defined by separating the elements of a row with
blank space or comma and using a semicolon to terminate each row
surrounded by square bracket.
• Syntax : [ init : increment : terminator]
>> array = 1: 2 : 9
array = 1 3 5 7 9
it starts at
1 (the init value),
increments with each step from the previous value by
2 (the increment value )
and stops once it reaches
9.
Vectors and Matrices
• >> A = [1 5]
A=1 5
• >> A = [1 , 5]
A= 1 5
• >> A = [1 : 5]
A=1 2 3 4 5
Vectors and Matrices
• Adding a single quote to a vector gives transpose of the matrix
>> A = [1 : 5]'
A=
1
2
3
4
5
• >> A = [1 ; 5]
A= 1
5
Addition of Matrices
• MATLAB is CASE-SENSITIVE
>> A = [1 1 1 ; 1 2 3 ;1 3 6]
A=
1 1 1
1 2 3
1 3 6
>> a+B
??? Undefined function or variable 'a'.
>> A+b
ans =
2 2 2
2 4 10
2 5 11
Vector Products
• A row vector and a column vector of the same length can be multiplied in
either order. The result is either a scalar, the inner product, or a matrix, the
outer product.
u = [3; 1; 4];
v = [2 0 -1];
x = v*u
x=
2
X = u*v
X=
6 0 -3
2 0 -1
8 0 -4
Vector Transpose
• Transposition turns a row vector into a column vector.
• For a complex vector or matrix, z, the quantity z' denotes the complex
conjugate transpose, where the sign of the complex part of each element is
reversed. The unconjugated complex transpose, where the complex part of
each element retains its sign, is denoted by z.'. So if
z = [1+2i 3+4i]
then z' is
1-2i
3-4i
while z.' is
1+2i
3+4i
Positive Integer Powers
• If A is a square matrix and p is a positive integer, then
A ^ p effectively multiplies A by itself p-1 times.
For example
>> A = [1 1 1;1 2 3;1 3 6]
A=
1 1 1
1 2 3
1 3 6
>> X = A^2
X=
3 6 10
6 14 25
10 25 46
Operating Element-by-Element
A=
1 1 1
1 4 9
1 9 36
The simplest way to execute M-code is to
type it in at the prompt, >> in the
Command Window, one of the elements of
the MATLAB Desktop
M-Files