Digital Signal Processing Reference
In-Depth Information
which returns
r4 =
8.5000
(v) To compute part (v), we can modify the code in part (iv) by preceding it
with the following instruction:
>> f zero mean = f
-
mean(f);% mean(f) computes the
% average value of f
>> r5 = sum(f zero mean.*conj(f zero mean))/length
(f zero mean)
which returns
r5 =
6
As a final note to our introduction on vectors, the second element of vector
f
can be accessed by the instruction
>> f(2)
which returns
ans =
4
A range of elements within a vector can be accessed by specifying the integer
index numbers of the elements. To access elements 1 and 2 of row vector
f
, for
example, we can type the instruction
>> f(1:1:2);
Similarly, the odd number elements in
f
can be accessed by the instruction
>> x = f(1:2:length(f));
where we have assigned the returned value to a new variable
x
. Code
1:2:length(f)
is referred to as a range-generating statement that generates
a row vector. The first element of the row vector is specified by the left-most
number (1 in our example). The next element in the row vector is obtained by
adding the middle element (2 in our example) to the first element and proceed-
ing all the way till the limit (
length(f)
) is reached. The middle element (2 in
our example) specifies the increment, while the third element
(length(f))
is the ending index. If the increment is missing, M
ATLAB
assigns a default
value of 1 to it. As another example, the range-generating statement
1:11
pro-
duces the row vector
[1234567891011].
Further, the start-
ing index, increment, or ending index can also be real-valued numbers. The
range-generating statement [
0.1:0.1:0.9
] produces the row vector
[0.1
0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9].
Search WWH ::
Custom Search