File: rec_syst_conv_code_test.cpp

package info (click to toggle)
libitpp 4.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 7,520 kB
  • ctags: 6,341
  • sloc: cpp: 51,608; sh: 9,248; makefile: 636; fortran: 8
file content (74 lines) | stat: -rw-r--r-- 2,608 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*!
 * \file
 * \brief Recursive systematic convolutional codes class test program
 * \author Pal Frenger
 *
 * -------------------------------------------------------------------------
 *
 * IT++ - C++ library of mathematical, signal processing, speech processing,
 *        and communications classes and functions
 *
 * Copyright (C) 1995-2008  (see AUTHORS file for a list of contributors)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * -------------------------------------------------------------------------
 */

#include <itpp/itbase.h>
#include <itpp/itcomm.h>

using namespace itpp;
using namespace std;


int main()
{
  bvec uncoded_bits = "0 1 1 0 1 0 1", tail_bits(4), decoded_bits(11);
  bmat parity_bits(11,1);
  vec received_systematic(11), extrinsic_output(11), L(11), symbols;
  mat received_parity(11,1);

  double Ec = 1.0, N0 = 0.00000000000000000000000000000000000000001, Lc = 4.0*sqrt(Ec)/N0;
  Normal_RNG noise(0.0,N0/2.0);

  BPSK bpsk;
  Rec_Syst_Conv_Code rscc;
  // Fixed by ediap: ivec("string") constructor uses only decimal notation
  // rscc.set_generator_polynomials("031 027",5);
  rscc.set_generator_polynomials("25 23", 5);
  rscc.set_awgn_channel_parameters(Ec, N0);

  rscc.encode_tail(uncoded_bits,tail_bits,parity_bits);
  bpsk.modulate_bits( concat(uncoded_bits, tail_bits), symbols );
  received_systematic = symbols + noise(11);

  bpsk.modulate_bits(parity_bits.get_col(0), symbols);
  received_parity.set_col(0, symbols + noise(11));

  vec extrinsic_input = zeros(11);
  rscc.map_decode(received_systematic, received_parity, extrinsic_input,
		  extrinsic_output);

  L = Lc*received_systematic + extrinsic_output;
  for (int k=0; k<11; k++) {
    (L(k)>0) ? (decoded_bits(k) = bin(0)) : (decoded_bits(k) = bin(1));
  }
  cout << "uncoded_bits = " << uncoded_bits << endl;
  cout << "tail_bits = " << tail_bits << endl;
  cout << "decoded_bits = " << decoded_bits << endl;

  return 0;
}