-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConvoCodeSim.cpp
120 lines (96 loc) · 2.18 KB
/
ConvoCodeSim.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
/*
* ConvoCodeSim.cpp
* new_LT
*
* Created by 刁培倫 on 2011/5/7.
* 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 START_ERROR_RATE 0.1
#define STEPS_PER_ORDER 3
#define MIN_ERRORS 100
#include <omp.h>
using namespace CodeSim;
using namespace std;
int main(int argn, char **args){
if (argn == 1) {
cerr << "Usage: ConvoCodeSim.out code_file [punchering_table_string]" << endl;
exit(-1);
}
string puncher_table = "1";
if (argn > 2) {
puncher_table = args[2];
}
CRandomMersenne r(time(0));
ConvoCode cc( args[1] );
int Layer = cc.getK();
cout << "Code file: \"" << args[1] <<"\" Punchering table: " << puncher_table << endl;
cout << "ChannelErasureRate";
for (int i=0; i<Layer; i++) {
cout << "\tLayer" << i+1;
}
cout << "\tTotalBits\n";
double errRate = 0.1;
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> b = cc.encode(a);
for (int i=0; i< b.size(); i++) {
if (puncher_table[i%puncher_table.size()] == '0') {
b[i].setErased(true);
}
else if (r.Random() < errRate) {
b[i].setErased(true);
}
}
Codeword<Bit> c = cc.decode(b);
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 >= 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);
}
}