Thursday, October 11, 2012

Understanding a Singal Processing Block in GNU Radio : Data Types

Data Types

GNU Radio type defines the most commonly used data types to a set of names.
The main purpose of this is to create a common set of conventions for naming of data types. The special data types defined in GNU Radio can be found in gr_types.h and gr_complex.h (both these files are located in /usr/local/include or else you can find them at http://gnuradio.org/doc/doxygen/gr__types_8h.html  & http://gnuradio.org/doc/doxygen/gr__complex_8h.html)


The list of these specialized data types is as follows :




These data types are nothing but new names for built-in c++ data types

gr_types.h has #include and gr_complex.h has #include
Both vector and complex are C++ satndard libraries

To see the size of each data type you can use the following C++ code.



The output will be

sizeof(gr_complex)----8
sizeof(gr_complexd)----16
sizeof(gr_vector_int)----12
sizeof(gr_vector_float)----12
sizeof(gr_vector_double)----12
sizeof(gr_vector_void_star)----12
sizeof(gr_vector_const_void_star)----12
sizeof(gr_int16)----2
sizeof(gr_int32)----4
sizeof(gr_uint16)----2
sizeof(gr_uint32)----4

You can see that the size of complex types are just double of their base types i.e.
size of gr_complex is 8 which is twice of the size of float i.e. 4
size of gr_complexd is 16 which is twice of the size of double i.e. 8

Infact you can see the difference of size between base type and the derived type by just printing
the size of base types also.

Here is the output :

sizeof(gr_complex)----8-----sizeof(float)----4
sizeof(gr_complexd)----16----sizeof(double)----8
sizeof(gr_vector_int)----12----sizeof(int)----4
sizeof(gr_vector_float)----12----sizeof(float)----4
sizeof(gr_vector_double)----12----sizeof(double)----8
sizeof(gr_vector_void_star)----12----sizeof(void *)----4
sizeof(gr_vector_const_void_star)----12----sizeof(const void *)----4
sizeof(gr_int16)----2----sizeof(short)----2
sizeof(gr_int32)----4----sizeof(int)----4
sizeof(gr_uint16)----2----sizeof(unsigned short)----2
sizeof(gr_uint32)----4----sizeof(unsigned int)----4


** In complex type is the size of the variable is x bytes then the size of the real part will be x/2 bytes and same will be for imaginary part. The following cpp file shows it 


#include
#include
using namespace std;

int main()
{
complex fc64 ;
complex fc32 ;

cout << "sizeof fc64 is " << sizeof(fc64) << endl;
cout << "sizeof fc32 is " << sizeof(fc32) << endl;
cout << "sizeof real part of fc64 is " << sizeof(real(fc64)) << endl;
cout << "sizeof imaginary part of fc32 is " << sizeof(imag(fc32)) << endl;
return 0;
}

** real and imag are cpp operators which ,when operated upon complex type data, return their real and imaginary parts respectively




2 comments:

  1. Is the size of vector in C++ 12? How did 12 come as size of gr_vector?

    ReplyDelete
  2. Hmm I dont know why exactly but the program yield so ... shall go to the details sometime :)

    ReplyDelete