-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConvoCodeTest.cpp
63 lines (52 loc) · 1.18 KB
/
ConvoCodeTest.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
/*
* ConvoCode.cpp
* new_LT
*
* Created by 刁培倫 on 2010/9/6.
* Copyright 2010 __MyCompanyName__. All rights reserved.
*
*/
#include "ConvoCode.h"
#include "LTCode.h"
#include "randomc.h"
#include<time.h>
#define L 10000000
using namespace std;
using namespace CodeSim;
int main(){
CRandomMersenne r(time(0));
int startTime = time(0);
cout << octToDec(19) << "\n";
ConvoCode cc("convo.txt");
cc.showInfo();
cout << "K: " << cc.getK()<< " N: " << cc.getN() << endl;
Codeword<Bit> a;
for (int i=0; i<2*L; i++) {
a.push_back(r.IRandomX(0, 1));
}
// cout << "input: ";
// for (int i = 0; i<a.size(); i++) {
// cout << a[i].toString();
// }
// cout << '\n';
cout << "encoding...\n";
Codeword<Bit> b = cc.encode(a);
for (int i = 0; i<b.size(); i++) {
if (r.Random() < 0.1) {
b[i].setErased(true);
}
//cout << b[i].toString();
}
cout << "decoding...\n";
Codeword<Bit> b2 = cc.decode(b);
int sum[2] = {0,0};
for (int i = 0; i<b2.size(); i++) {
if (b2[i].getValue() != a[i].getValue()) {
sum[i%2]++;
}
}
cout << '\n';
cout << sum[0] / (double)L << ' ' << sum[1] / (double)L << '\n';
cout << "Time: " << time(0) - startTime << '\n';
return 0;
}