-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautogenmat.cpp
101 lines (82 loc) · 2.46 KB
/
autogenmat.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
#include <iostream>
#include "Matrix.h"
#include "GenParityCheck.h"
#include <cstdlib>
#include <fstream>
using namespace std;
int main(int argc, char ** argv)
{
if (argc != 6)
{
cout << "Usage: autogenmat gFilename hFilename wc wr N\n"
<< "\tGenerates a pair of LDPC parity check matrix and a\n"
<< "\tcorresponding systematic generator matrix\n\n";
cout << "\thFilename, gFilename - the files to write the parity\n"
<< "\tcheck matrix and generator matrix to respectively\n\n";
cout << "\twc, wr - The maximum number of ones per column and row\n"
<< "\tresp.\n\n";
cout << "\tN is the width of the parity check matrix. The height is\n"
<< "\tN * wr / wc (as the parity check matrix is generated from\n"
<< "\ta regular matrix)\n";
exit(0) ;
}
string gFilename = argv[1];
string hFilename = argv[2];
int wc = atoi(argv[3]);
int wr = atoi(argv[4]);
int N = atoi(argv[5]);
srand(time(0));
// Generate some regular parity check matrix
Matrix h;
genRegParity(wc, wr, N, h);
cout << "Original Parity\n";
h.print(cout);
cout << endl;
// Remove cycles of length 4
removeShortCycles(h);
cout << "After Short Cycles\n";
h.print(cout);
cout << endl;
// Permute the columns of the parity check to enable an easy
// derivation of a systematic encoder
if (!permuteForSystematic(h, h.width * h.width / 2))
{
cout << "Error in systematic permute\n";
exit(1);
}
cout << "After systematic permute\n";
h.print(cout);
cout << endl;
// Generate a systematic generator matrix
Matrix g;
if (!genSystematicGenerator(h, g))
{
cout << "Error in systematic generation\n";
exit(1);
}
cout << "After systematic generator matrix generation\n";
cout << "H\n";
h.print(cout);
cout << endl;
cout << "G\n";
g.print(cout);
cout << endl;
// Test if g is a valid generator matrix
Matrix tH = h; tH.transpose();
Matrix prod = g.binaryMult(tH);
if (!prod.isZero())
{
cout << "G is not a valid generator!\n";
cout << "GH ^ T is\n";
prod.print(cout);
cout << endl;
}
// Save the matrices
ofstream gout(gFilename.c_str());
g.print(gout);
gout.close();
ofstream hout(hFilename.c_str());
h.print(hout);
hout.close();
return 0;
}