The itbase
library is the core of IT++
and it contains classes and functions for mathematics with scalars, vectors, and matrices. This document does not cover all the aspects of the itbase
library. It does however explain the most important things you need to know in order to start using IT++. Once you are more familiar with the itbase
library you will find the online reference manual more useful.
Apart from the standard C++ types e.g. char
, short
, int
, long
, double
, float
, and long
long
, the following types are specific for IT++
:
complex<double>
: Contains real and imaginary parts of type double
bin:
Used for binary (0,1) dataA vector can in principle be of arbitrary type (that support addition, subtraction, multiplication and division), since the general vector class Vec<TYPE>
is templated. However, the most commonly used vector types are predefined. These predefined vector types are:
vec:
Basic vector type containing double
cvec:
Vector type containing complex<double>
ivec:
Vector type containing int
bvec:
Vector type containing bin
svec:
Vector type containing short
The general vector class is used to define the specialized classes above. The vec
class is actually a Vec<double>
. We urge you to use these predefined classes instead of Vec<TYPE>
when ever possible.
The general matrix class is called Mat<TYPE>
. These predefined matrix types are:
mat:
Basic matrix type containing doublecmat:
Matrix type containing complex<double>
imat:
Matrix type containing int
bmat:
Matrix type containing bin
smat:
Matrix type containing short
As with vector, the general matrix class is used to define the specialized classes above. The mat
class is thus a Mat<double>
. We urge you to use these predefined classes instead of Mat<TYPE>
whenever possible.
Vectors and matrices in IT++
are very similar. We therefore begin to describe the vector class in detail and then briefly explain the differences regarding matrices in the next section.
A vector containing elements of type double
is defined with:
However, this will not assign a size (memory) to the vector. To assign size 10 to the vector we may use:
or
where the second parameter in the set_size
call (true
or false
) determines if you want to copy the contents of the old data area into the new resized one, or not. This may be useful when down-sizing a vector, but in this case it is not. It is also equivalent to use
instead of set_size
.
Observe that a declared vector (or matrix) is not cleared (the element values are undefined). To clear a vector we simply write
or
To fill the vector with ones we write
It is possible to retrieve the length (size) of a vector in any of the following ways:
To assign values to a vector
A comma or a space character separates the vector elements. When assigning or retrieving a specific vector element use
for element number i. Vector elements are numbered such that a(0) denotes the first element. It is also possible to use square brackets as in the C language, i.e.
Parts or a vector are retrieved by
Alternatively you can use get() methods instead of () or [] operators, e.g.
If you have a vector called index_list containing indexes (ivec) you may write
If you have a bvec
called e.g. bin_list you may write
Have a look at the following example:
When you run this program you will see
Below follows a listing of the most common vector manipulation commands that are available. All examples are given for an ivec
denoted my_ivec, but of course this will work for other vector types as well.
shift_right:
shift_left:
set_subvector:
del:
ins:
split:
elem_mult:
elem_div:
concat
In order to convert e.g an ivec
to a vec
we can write some thing like my_vec
= to_vec(my_ivec)
. The following converters are available:
to_bvec
,to_svec
,to_ivec
,to_vec
,to_cvec
.There are several functions that operate on vectors. Some examples are: max
, max_index
, min
, min_index
, product
, energy
, geometric_mean
, mean
, median
, norm
, round
, variance
, ceil_i
, floor_i
, round_i
, find
.
Examples of functions that generate different kinds of vectors are: linspace
, ones_b
, ones_c
, ones_i
, ones
zeros_b
. There are several more than these. Please refer to the IT++ reference manual for a description of these.
Matrices are two-dimensional arrays, and most of their functionality is similar to that of vectors. The predefined matrix types are:
mat
,cmat
,imat
,smat
,bmat
.Below follows some examples that are specific for matrices only:
Define a matrix of type double
with 3 rows and 4 columns
Define a matrix of type int
with 2 rows and 3 columns. A comma (,) or space is used to separate columns and a semicolon (;) is used to separate rows.
Access to rows and columns with get_row
and get_col
Set rows and columns with set_row
and set_col
The size of a matrix
Access to parts of a matrix
Copy rows and columns
Swap rows and columns
The following converters are available:
to_mat
,to_imat
,to_cmat
,to_bmat
.The itbase
library contains, among other things, the Array
class. An Array
can contain any type of data. Below is an example of an Array
containing vectors (vec
):
Random vectors and matrices are easily obtained by using these predefined functions:
randb:
Generates a random bit vector or matrixrandu:
Generates a random uniform vector or matrixrandi:
Generates a random index vector or matrixrandray:
Generates a random Rayleigh vector or matrixrandrice:
Generates a random Rice vector or matrixrandexp:
Generates a random Exponential vector or matrixrandn:
Generates a random Gaussian vector or matrixrandn_c:
Generates a random complex Gaussian vector or matrixThe following discrete valued random number generators are available. More information about these can be found in the IT++ reference manual.
Bernoulli_RNG
I_Uniform_RNG
The following continuous valued random number generators are available.
Uniform_RNG
Exponential_RNG
Normal_RNG
Complex_Normal_RNG
AR1_Normal_RNG
Weibull_RNG
Rayleigh_RNG
Rice_RNG
The following deterministic sources are available:
Sine_Source
Square_Source
Triangle_Source
Sawtooth_Source
Impulse_Source
Pattern_Source
The following filter classes are available:
AR_Filter
MA_Filter
ARMA_Filter
Freq_Filt
The following filter functions are available:
filter
The following signal processing functions are available:
a2k
, k2a
, a2lar
, k2lar
, lpc
, levinsson
, lerouxguegen
fft
, ifft
, fft_real
, ifft_real
dct
, idct
spectrum
cov
, xcorr
chirp
dht
, dht2
, dwht
, dhwt2
, self_dht
, self_dwht
filter_spectrum
filter_whiteness
The Real_Timer
class can be used to measure execution time of a program as in the following example:
The following example saves the variable a to the file my_file_name.it:
The following example reads the variable a from the file my_file_name.it
and prints it:
Note that *.it
files can be read and written in Matlab/Octave by using the itload.m
and itsave.m
functions.
Also available is the class it_ifile
that can only be used for reading of files.
Generated on Sat May 25 2013 16:32:26 for IT++ by Doxygen 1.8.2