-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgldpcsim.cpp
More file actions
168 lines (131 loc) · 4.39 KB
/
Copy pathgldpcsim.cpp
File metadata and controls
168 lines (131 loc) · 4.39 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <iostream>
#include <fstream>
#include <getopt.h>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <ctime>
#include <algorithm>
//#include <omp.h>
#include <itpp/itcomm.h>
#include "getopt_pp.h"
#include "gldpc.h"
#include "utils.h"
//#include "sse_mathfun.h"
using namespace std;
using namespace GetOpt;
static void usage() {
cerr << "Usage: gldpc -n <codelength> [-d <leftdegree>] -D <rightdegree> -C <channel> [-p <channel param>] ";
cerr << "\t[-e <erasure>] [-r <erasure range>] [-I <iterations=1>] [-w <graphml file>] [-q] [-x <randomseed>] [-g <stopcond>] [-t <serthresh>] [-o <outputfile>] [-p time] -E erasurefile" << endl;
cerr << "\tuse -w to export the code structure to a graphml file, no simulation" << endl;
cerr << "\t-e <<erasure> , the default value = 1-rate-(1-rate)/5 " << endl;
cerr << "\t-q\tquiet mode, least verbose" << endl;
cerr << "\t-x\trandom seed, if not specified use the system time." << endl;
cerr << "\t-g <stopcond>\tbinary search to find the capacity gap" << endl;
//./simcodes -c st -n 10 -s 128 -d 4 -m 5
//./simcodes -c ex -n 14 -s 256 -d 4 --md1 7 --md2 15 -I 20 -g
exit(EXIT_FAILURE);
}
int main(int argc, char* argv[]) {
int n = 512;
int d=2,D=8;
unsigned int niter = 1;
unsigned int bpiter=50;
double capacity=0.5;
int ch=1;
Channel *channel;
double channelparam=0.23;
bool quiet = false;
string gname = "";
unsigned long int rseed = static_cast<unsigned long int>(std::time(0));
GetOpt_pp ops(argc, argv);
if (ops >> OptionPresent('h', "help") || argc == 1)
usage();
//required args
try {
ops.exceptions(std::ios::failbit | std::ios::eofbit);
ops
>> Option('n',"nvar", n) ;
//>> Option('d', "d1", d1);
//>> Option('m', "md1", md1);
} catch (const GetOptEx& e) {
std::cerr << "Invalid options or format\n";
usage();
}
//optional args
try {
ops.exceptions(std::ios::failbit);
ops
>> Option('d', d)
>> Option('D', D)
>> Option('p', channelparam)
>> Option('c', "channel", ch)
>> Option('i', "bpiter", bpiter)
>> Option('I', "iterations", niter, niter)
>> Option('x', "seed", rseed, rseed);
} catch (const GetOptEx& e) {
std::cerr << e.what();
std::cerr << "Invalid options or format\n";
usage();
}
quiet = ops >> OptionPresent('q', "quiet");
if(!quiet)
cout<<"Random seed is "<<rseed<<endl;
#ifdef USE_PRERAND
string randfile="/home1/masoud/yearly/2010.bin";
unsigned int nr=ptrand.openrandfile(randfile.c_str(),32, 25000000);
if(!nr){
cerr<<"Could not open file "<<randfile<<"..."<<endl;
exit(EXIT_FAILURE);
}
cerr<<"There are "<<nr<<" 32bit random numbers in "<<randfile<<endl;
#endif
setrandseed(rseed);
switch (ch){
case 2:
channel=new AWGN(channelparam);
break;
case 1:
channel=new BSC(channelparam);
break;
case 0:
break;
default:
cerr<<"Unsupported channel"<<endl;
exit(-1);
}
if(ops >> OptionPresent("capacity")){
ops >> Option("capacity", capacity);
channel->setCapacity(capacity);
}
capacity=channel->capacity();
precomputedTables();
/*RandomLinearCode test(6,5);
test.generate();
test.enumerateCodewords();
test.print();*/
//return 0;
GLDPC code(n,D,d);
RateDistribution rates;
code.InstantiateGraph(rates,capacity);
if(!quiet){
channel->print();
code.print();
}
//cout.flush();
vector<LLRType> llrch(code.length(),0.0);
vector<LLRType> llrbp(code.length(),0.0);
vector<bool> decoded(code.length(),1);
itpp::BERC berc;
itpp::bvec bitsin = itpp::zeros_b(code.length());
for(unsigned i=0;i<niter;i++){
channel->transmitzero(llrch);
//PrintVector(cout,llrch,",");
code.bp_decode(llrch,llrbp,bpiter);
PrintVector(cout,llrbp,",");
channel->decode(llrbp,decoded);
}
cout<<endl;
delete channel;
}