-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPolarCode.cpp
31 lines (26 loc) · 1.22 KB
/
PolarCode.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
#include <algorithm>
#include <iostream>
#include "PolarCode.h"
bool AscSecondElement(const std::pair<int, double> &left, const std::pair<int, double> &right) {
return left.second > right.second;
}
PolarCode::PolarCode(unsigned int length, unsigned int codeDimension, const Channel &channel) : channel(channel) {
this->frozenBits = std::vector<int>(length - codeDimension);
this->length = length;
std::vector<std::pair<int, double >> symmetricCapacities(length);
for (int i = 0; i < length; ++i) {
symmetricCapacities[i] = std::make_pair(i, channel.symmetricCapacity(length, i));
}
std::sort(symmetricCapacities.begin(), symmetricCapacities.end(), AscSecondElement);
this->informationSet = std::vector<int>(codeDimension);
for (int i = 0; i < codeDimension; ++i) {
this->informationSet[i] = symmetricCapacities[i].first;
}
std::sort(this->informationSet.begin(), this->informationSet.end());
}
std::vector<int> PolarCode::SuccessiveCancellationDecode(const std::vector<int> &y) const {
return GnCosetCode::SuccessiveCancellationDecode(y, channel);
}
std::vector<int> PolarCode::LlrSCDecode(const std::vector<int> &y) const {
return GnCosetCode::LlrSCDecode(y, channel);
}