利用IT++搭建通信仿真平台

IT++ is a C++ library of mathematical, signal processing and communication classes and functions。也就是说有了这个库,用C++编写通信仿真程序的方便程度接近于matlab。具体介绍和文件下载可以上官方网站。Matlab用的好好的,干嘛要用IT++?水木清华论坛里一个帖子说的很清楚,“由于Matlab效率太低(除了可以验证算法外),所以需要更快的仿真平台。最好的平台无非就是自己写的C/C++程序,以及利用这个行业别人已经做好的库it++,非常方便,用它感觉就像是在C++下的Matlab。当然效率跟前者相比是不可同日而语。

1、Windows环境

这个网站,它提供“100% free powerful solution”。因为IT++要用的是MKL的三个libraries:LAPACK BLAS FFTW,这三个库是可以免费下载到的。该网站提供了在VS2005下安装IT++的步骤。只要按照网站说明进行安装,基本没有什么问题。

可参见:http://blog.sina.com.cn/s/blog_4dab1a5a0100sgid.html  

 

2、Linux环境

可参见:http://blog.csdn.net/luotuo818/article/details/6767594

 

下载组件:

0)gfortran

sudo apt-get install gfortran 

1)fftw           ---http://www.fftw.org/       

安装参见http://hi.baidu.com/jerry_916/blog/item/f9fc86428aa78c0e9213c65f.html

sudo apt-get install libfftw3-dev  //安装libfftw3-dev

2)blas          ---http://www.netlib.org/blas/ 

安装参见

sudo apt-get install libblas-dev          //安装libblas-dev

3)lapack       ---http://www.netlib.org/lapack/ 

安装参见

一定要在编译完成BLAS后在编译LAPACK,因为LAPACK的testing包会用到BLAS库

sudo apt-get install liblapack-dev   //安装liblapack-dev

若编译完成,确认生成了三个.a文件(Linux静态库文件),三个.a文件的文件名为,blas_LINUX.a,lapack_LINUX.a,tmglib_LINUX.a;

  1. sudo ln -s */? /usr/local/lib/%  
  2. sudo ln -s */? /usr/lib/%  
  3. # *表示那三个文件的路径,?表示那个.a文件,%表示对应的静态库名(libblas.a,liblapack.a,libtmglib.a)  

3)itpp-4.2         ---http://itpp.sourceforge.net/current/installation.html
sudo apt-get install libitpp-dev
./configure
itpp-4.2 library configuration:
------------------------------------------------------------------------------
Directories:
  - prefix ......... : /usr/local
  - exec_prefix .... : ${prefix}
  - includedir ..... : ${prefix}/include
  - libdir ......... : ${exec_prefix}/lib
  - datarootdir .... : ${prefix}/share
  - docdir ......... : ${datarootdir}/doc/${PACKAGE_TARNAME}
Switches:
  - debug .......... : no
  - exceptions ..... : no
  - html-doc ....... : yes
  - shared ......... : yes
  - static ......... : no
  - explicit deps .. : no
Documentation tools:
  - doxygen ........ : yes
  - latex .......... : yes
  - dvips .......... : yes
  - ghostscript .... : yes
Testing tools:
  - diff ........... : yes
Optional modules:
  - comm ........... : yes
  - fixed .......... : yes
  - optim .......... : yes
  - protocol ....... : yes
  - signal ......... : yes
  - srccode ........ : yes
External libs:
  - BLAS ........... : yes
    * MKL .......... : no
    * ACML ......... : no
    * ATLAS ........ : no
  - LAPACK ......... : yes
  - FFT ............ : yes
    * MKL .......... : no
    * ACML ......... : no
    * FFTW ......... : yes
Compiler/linker flags/libs/defs:
  - CXX ............ : g++
  - F77 ............ : gfortran
  - CXXFLAGS ....... : -DNDEBUG -O3 -pipe
  - CXXFLAGS_DEBUG . : -Wall -ggdb -pipe
  - CPPFLAGS ....... :
  - LDFLAGS ........ :
  - LIBS ........... : -lfftw3 -llapack -lblas
make && make install 
make check  
在主文件夹的.bashrc中加入:export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH   //source一下
其目的是为了使用it-config这个脚本以自动配置你的编译链接选项。然后在编译链接你的程序(my_prog.cpp)时使用以下命令
g++ `it-config --flags` -o my_prog my_prog.cpp `it-config --libs`
为了生成可调试的版本,用如下命令
g++ `it-config –flags --debug` -o my_prog my_prog.cpp `it-config –libs --debug`
体验自己编译好的itpp库

建立一个.cpp文件,将以下内容写入

#include <itpp/itbase.h>
using namespace itpp;
//These lines are needed for use of cout and endl
using std::cout;
using std::endl;

int main()
{
  //Declare vectors and matricies:
  vec a, b, c;
  mat A, B;

  //Use the function linspace to define a vector:
  a = linspace(1.0, 2.0, 10);

  //Use a string of values to define a vector:
  b = "0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0";

  //Add two vectors:
  c = a + b;

  //Print results:
  cout << "a = " << a << endl;
  cout << "b = " << b << endl;
  cout << "c = " << c << endl;

  //Use a string to define a matrix:
  A = "1.0 2.0;3.0 4.0";

  //Calculate the inverse of matrix A:
  B = inv(A);

  //Print results:
  cout << "A = " << A << endl;
  cout << "B = " << B << endl;

  //Exit program:
  return 0;
}

  1. g++ -o *** *.cpp -litpp  
  2. #***为编译生成的文件的文件名,*为你建立的.cpp的名称 

保存为:simple_itpp.cpp
g++ -o example simple_itpp.cpp -litpp
./example

如果一切顺利,会有如下结果

  1. a = [1 1.11111 1.22222 1.33333 1.44444 1.55556 1.66667 1.77778 1.88889 2]  
  2. b = [0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1]  
  3. c = [1.1 1.31111 1.52222 1.73333 1.94444 2.15556 2.36667 2.57778 2.78889 3]  
  4. A = [[1 2]  
  5.  [3 4]]  
  6. B = [[-2 1]  
  7.  [1.5 -0.5]]  

 

FLAGS_DEBUG = `itpp-config --cflags-debug`
FLAGS_OPT   = `itpp-config --cflags-opt`

LIBS_DEBUG  = `itpp-config --libs-debug`
LIBS_OPT    = `itpp-config --libs-opt`

 

itpp::log2 只用于向量和矩阵

原文地址:https://www.cnblogs.com/fickleness/p/3152282.html