-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChannelAWGN.cpp
47 lines (40 loc) · 1.34 KB
/
ChannelAWGN.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
#include "ChannelAWGN.h"
static float theta(float x) {
if (x > 12) {
return 0.98611 * x - 2.31515;
} else if (3.5 < x && x <= 12) {
return x * (0.0090047 * x + 0.76943) - 0.95068;
} else if (1 < x && x <= 3.5) {
return x * (0.062883 * x + 0.36784) - 0.16267;
} else {
return x * (0.22024 * x + 0.06448);
}
}
static float Q(float x) {
return erfc(x / sqrt(2)) / 2;
}
float finding_E(int lambda, int i, float variability) {
if (lambda == 0 && i == 0) {
return 2 / variability;
}
if ((i & 1) == 0) {
return theta(finding_E(lambda - 1, i >> 1, variability));
} else {
return 2 * finding_E(lambda - 1, i >> 1, variability);
}
}
float finding_error_probability_awgn(int _m, int i, float variability) {
return Q(sqrt(finding_E(_m, i, variability) / 2.0));
}
void ChannelAWGN::find_freezed_channels(int m, int k, float variability) {
F.clear();
error_probability.clear();
for (int i = 0; i < (1 << m); ++i) {
error_probability.emplace_back(finding_error_probability_awgn(m, i, variability), i);
}
auto comparator = [](const auto &a, const auto &b) { return a.first > b.first; };
std::sort(error_probability.begin(), error_probability.end(), comparator);
for (int i = 0; i < k; ++i) {
F.insert(error_probability[i].second);
}
}