Digital Signal Processing Reference
In-Depth Information
M ATLAB also provides a set of functions for decimal numbers. If applied to
integers, these functions do not make any changes. On the other hand, if these
functions are applied to complex numbers, each operation is performed individ-
ually on the real and imaginary component. Below we provide a selected list.
>> x = 2.3 - 4.7*i;
% Initializes x as a complex
% variable
>> x round = round(x);
% rounds to nearest
% integer, (2 - 5i)
>> x fix = fix(x)
% rounds to nearest integer
% towards zero, (2 - 4i)
>> x floor = floor(x)
% rounds down (towards negative
% infinity), (2 - 5i)
>> x ceil = ceil(x)
% rounds up (towards positive
% infinity) (3 - 4i)
We now consider initialization of multidimensional arrays through a series of
examples.
Example E.1
Consider the two row vectors
f
=
1 ,
4 ,
2 ,
(3 2i)
and
g =
3 ,
(5 + 7i) ,
6 ,
2
.
Perform the following mathematical operations in M ATLAB on vectors f and
g :
(i) addition, r 1 = f + g ;
(ii) dot product, r 2 =
f
g ;
4
(iii) mean, r 3 = 1
4
f ( k );
k = 1
4
(iv) average energy, r 4 = 1
4
f ( k ) 2 ;
k = 1
4
(v) variance, r 5 = 1
4
f ( k ) r 3 2 , where r 3 is defined in (iii).
k = 1
Solution
The M ATLAB code to solve part (i) is given below with comments following
the % sign:
Search WWH ::




Custom Search