-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapping.h
119 lines (95 loc) · 2.22 KB
/
Mapping.h
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
/*
* Mapping.h
*
* Created on: 22 Dec, 2014
* Author: Mehrdad Tahernia
* User: mehrdad
*/
#ifndef MAPPING_H_
#define MAPPING_H_
#include "GFq.h"
/***************************************************************************
*
* mapping
*
***************************************************************************/
class mapping {
public:
int q;
double vals[MAX_Q];
public:
mapping(int p_q = -1, double *p_vals = NULL) {
if (p_q != -1)
Set_Q(p_q);
if (p_vals != NULL)
std::copy(p_vals, p_vals+q, vals);
} // end of constructor
void Set_Q(int p_q) {
if (p_q > MAX_Q) {
cout << "Exceeded MAX_Q in mapping (simply increase)\n";
exit(1);
}
q = p_q;
}
// Copy mapping from p_MapInUse
mapping(mapping &p_MapInUse) :
q(p_MapInUse.q) {
std::copy(p_MapInUse.vals, p_MapInUse.vals+q, vals);
}
// Determine whether the mapping is a binary mapping or not!
bool IsBinary() {
if (q != 2)
return false;
if (((vals[0] != 0) && (vals[0] != 1)) || ((vals[1] != 0) && (vals[1] != 1)))
return false;
return true;
}
// Read mapping from input file
void GetFromFile(std::ifstream &file);
// Average signal power assuming all constellation points are equiprobable
double Average_E() {
double sum_E = 0;
for (int i = 0; i < q; i++)
sum_E += pow(vals[i], 2);
return sum_E / (double) q;
}
void Normalize() {
// Normalize average energy to 1
double factor = sqrt(Average_E());
for (int i = 0; i < q; i++)
vals[i] /= factor;
}
// Operator overload for division of a mapping
void operator/=(double d) {
for (int i = 0; i < q; i++)
vals[i] /= d;
}
// Operator overload for multiplication of a mapping
void operator*=(double d) {
for (int i = 0; i < q; i++)
vals[i] *= d;
}
// Returns the mapping point for a integer x
double map(int x) {
return vals[x];
}
// Returns the mapping point for g in GF(q)
double map(GFq &g) {
return map(g.val);
}
// Return q of mapping
int GetQ() {
return q;
}
};
inline std::ostream &operator<<(std::ostream &s, mapping &MapInUse) { // for writing MapInUse to s
s << "[";
for (int i = 0; i < MapInUse.GetQ(); i++) {
if (i != 0)
s << " ";
s << MapInUse.vals[i];
}
s << "]";
return s;
}
#endif /* MAPPING_H_ */