利用IT++搭建通信仿真平臺(C++)

IT++ is a C++ library of mathematical, signal processing and communication classes and functions。也就是說有了這個庫,用C++編寫通信仿真程序的方便程度接近於matlab。具體介紹和文件下載可以上官方網站。“由於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 只用於向量和矩陣

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章