-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConvoCodeSim_byte.cpp
128 lines (102 loc) · 2.4 KB
/
ConvoCodeSim_byte.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* ConvoCodeSim_byte.cpp
* new_LT
*
* Created by 刁培倫 on 2011/6/1.
* Copyright 2011 __MyCompanyName__. All rights reserved.
*
*/
#include "ConvoCode.h"
#include "LTCode.h"
#include "randomc.h"
#include <ctime>
#include <cmath>
#define L 100000
#define MAX_BIT 1000000000L
#define MIN_BIT 10000000L
#define START_ERROR_RATE 0.1
#define STEPS_PER_ORDER 1
#define MIN_ERRORS 100
#include <omp.h>
using namespace CodeSim;
using namespace std;
int main(int argn, char **args){
if (argn <= 2) {
cerr << "Usage: ConvoCodeSim_byte.out code_file interleaver_file" << endl;
exit(-1);
}
//string puncher_table = "1";
// if (argn > 2) {
// puncher_table = args[2];
// }
CRandomMersenne r(time(0));
ConvoCode cc( args[1] );
Permutator<Bit> inter(args[2], true);
int Layer = cc.getK();
cout << "Code file: \"" << args[1] << "\" Interleaver file: \""<< args[2] << '"' << endl;
cout << "ChannelErasureRate";
for (int i=0; i<Layer; i++) {
cout << "\tLayer" << i+1;
}
cout << "\tTotalBits\n";
double errRate = START_ERROR_RATE;
while (1) {
vector<unsigned long> err(Layer, 0);
unsigned long total=0;
// for (int i=0; i<Layer; i++) {
// err[i]=0;
// }
while (1) {
#pragma omp parallel for num_threads(6)
for (int i=0; i<6; i++) {
Codeword<Bit> a;
a.reserve(Layer*L);
for (int i=0; i<Layer*L; i++) {
a.push_back(r.IRandomX(0, 1));
}
Codeword<Bit> a2 = cc.encode(a);
a2 = inter.permutate(a2);
Codeword<Byte> b = BitToByteCoverter::convert(a2);
for (int i=0; i< b.size(); i++) {
if (r.Random() < errRate) {
b[i].setErased(true);
}
}
Codeword<Bit> b2 = BitToByteCoverter::revert(b);
b2 = inter.depermutate(b2);
Codeword<Bit> c = cc.decode(b2);
for (int i=0; i<c.size(); i++) {
if (!(a[i] == c[i])) {
#pragma omp atomic
err[i%Layer]++;
}
}
#pragma omp atomic
total += L;
}
// check stop
if (total < MIN_BIT) {
continue;
}
if (total >= MAX_BIT) {
break;
}
bool enough = true;
for (int i=0; i<Layer; i++) {
if (err[i] < MIN_ERRORS) {
enough = false;
}
}
if (enough) {
break;
}
}
// enough # of errors
cout << errRate;
for (int i=0; i<Layer; i++) {
cout << '\t' << err[i]/(double)total;
}
cout << '\t' << total << endl;
errRate *= pow(10, -1.0/STEPS_PER_ORDER);
}
}