-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added polar code reliability sequence constructor
- Loading branch information
Ahmet Inan
committed
Jul 7, 2023
1 parent
b9d074a
commit cb7271c
Showing
4 changed files
with
78 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
Construct reliability sequences for polar codes | ||
Copyright 2023 Ahmet Inan <[email protected]> | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <algorithm> | ||
|
||
namespace CODE { | ||
|
||
template <int MAX_M> | ||
class PolarSeqConst0 | ||
{ | ||
void compute(double pe, int i, int h) | ||
{ | ||
if (h) { | ||
compute(pe * (2-pe), i, h/2); | ||
compute(pe * pe, i+h, h/2); | ||
} else { | ||
prob[i] = pe; | ||
} | ||
} | ||
double prob[1<<MAX_M]; | ||
int index[1<<MAX_M]; | ||
public: | ||
void operator()(int *sequence, int level, double erasure_probability = std::exp(-1.)) | ||
{ | ||
assert(level <= MAX_M); | ||
int length = 1 << level; | ||
compute(erasure_probability, 0, length / 2); | ||
for (int i = 0; i < length; ++i) | ||
sequence[i] = i; | ||
std::sort(sequence, sequence+length, [this](int a, int b){ return prob[a] > prob[b]; }); | ||
} | ||
}; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ Copyright 2020 Ahmet Inan <[email protected]> | |
#include "polar_helper.hh" | ||
#include "polar_list_decoder.hh" | ||
#include "polar_encoder.hh" | ||
#include "polar_freezer.hh" | ||
#include "polar_sequence.hh" | ||
#include "crc.hh" | ||
#include "sequence.h" | ||
|
||
|
@@ -52,35 +52,33 @@ int main() | |
typedef std::default_random_engine generator; | ||
typedef std::uniform_int_distribution<int> distribution; | ||
auto data = std::bind(distribution(0, 1), generator(rd())); | ||
auto frozen = new uint32_t[(N+31)/32]; | ||
auto frozen = new uint32_t[N/32]; | ||
auto codeword = new code_type[N]; | ||
auto temp = new simd_type[N]; | ||
|
||
long double erasure_probability = 0.5; | ||
const int *reliability_sequence; | ||
double erasure_probability = 0.5; | ||
int K = (1 - erasure_probability) * N; | ||
double design_SNR = 10 * std::log10(-std::log(erasure_probability)); | ||
std::cerr << "design SNR: " << design_SNR << std::endl; | ||
#if 0 | ||
if (0) { | ||
CODE::PolarFreezer freeze; | ||
long double freezing_threshold = 0 ? 0.5 : std::numeric_limits<float>::epsilon(); | ||
K = freeze(frozen, M, erasure_probability, freezing_threshold); | ||
} else { | ||
auto freeze = new CODE::PolarCodeConst0<M>; | ||
std::cerr << "sizeof(PolarCodeConst0<M>) = " << sizeof(CODE::PolarCodeConst0<M>) << std::endl; | ||
auto construct = new CODE::PolarSeqConst0<M>; | ||
std::cerr << "sizeof(PolarSeqConst0<M>) = " << sizeof(CODE::PolarSeqConst0<M>) << std::endl; | ||
double better_SNR = design_SNR + 1.59175; | ||
std::cerr << "better SNR: " << better_SNR << std::endl; | ||
long double probability = std::exp(-pow(10.0, better_SNR / 10)); | ||
double probability = std::exp(-pow(10.0, better_SNR / 10)); | ||
std::cerr << "prob: " << probability << std::endl; | ||
(*freeze)(frozen, M, K, probability); | ||
delete freeze; | ||
auto rel_seq = new int[N]; | ||
(*construct)(rel_seq, M, probability); | ||
delete construct; | ||
reliability_sequence = rel_seq; | ||
} else { | ||
reliability_sequence = sequence; | ||
} | ||
#else | ||
for (int i = 0; i < N / 32; ++i) | ||
frozen[i] = 0; | ||
for (int i = 0; i < N - K; ++i) | ||
frozen[sequence[i]/32] |= 1 << (sequence[i]%32); | ||
#endif | ||
frozen[reliability_sequence[i]/32] |= 1 << (reliability_sequence[i]%32); | ||
std::cerr << "Polar(" << N << ", " << K << ")" << std::endl; | ||
auto message = new code_type[K]; | ||
auto decoded = new simd_type[K]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ Copyright 2020 Ahmet Inan <[email protected]> | |
#include "polar_decoder.hh" | ||
#include "polar_encoder.hh" | ||
#include "polar_freezer.hh" | ||
#include "polar_sequence.hh" | ||
|
||
bool get_bit(const uint32_t *bits, int idx) | ||
{ | ||
|
@@ -39,26 +40,33 @@ int main() | |
typedef std::default_random_engine generator; | ||
typedef std::uniform_int_distribution<int> distribution; | ||
auto data = std::bind(distribution(0, 1), generator(rd())); | ||
auto frozen = new uint32_t[(N+31)/32]; | ||
auto frozen = new uint32_t[N/32]; | ||
auto codeword = new code_type[N]; | ||
auto temp = new code_type[N]; | ||
|
||
long double erasure_probability = 1. / 3.; | ||
double erasure_probability = 1. / 3.; | ||
int K = (1 - erasure_probability) * N; | ||
double design_SNR = 10 * std::log10(-std::log(erasure_probability)); | ||
std::cerr << "design SNR: " << design_SNR << std::endl; | ||
if (0) { | ||
CODE::PolarFreezer freeze; | ||
long double freezing_threshold = 0 ? 0.5 : std::numeric_limits<float>::epsilon(); | ||
K = freeze(frozen, M, erasure_probability, freezing_threshold); | ||
} else { | ||
double better_SNR = design_SNR + 0.5;//1.59175; | ||
std::cerr << "better SNR: " << better_SNR << std::endl; | ||
double probability = std::exp(-pow(10.0, better_SNR / 10)); | ||
if (1) { | ||
auto freeze = new CODE::PolarCodeConst0<M>; | ||
std::cerr << "sizeof(PolarCodeConst0<M>) = " << sizeof(CODE::PolarCodeConst0<M>) << std::endl; | ||
double better_SNR = design_SNR + 0.5;//1.59175; | ||
std::cerr << "better SNR: " << better_SNR << std::endl; | ||
long double probability = std::exp(-pow(10.0, better_SNR / 10)); | ||
(*freeze)(frozen, M, K, probability); | ||
delete freeze; | ||
} else { | ||
auto sequence = new int[N]; | ||
auto construct = new CODE::PolarSeqConst0<M>; | ||
std::cerr << "sizeof(PolarSeqConst0<M>) = " << sizeof(CODE::PolarSeqConst0<M>) << std::endl; | ||
(*construct)(sequence, M, probability); | ||
delete construct; | ||
for (int i = 0; i < N / 32; ++i) | ||
frozen[i] = 0; | ||
for (int i = 0; i < N - K; ++i) | ||
frozen[sequence[i]/32] |= 1 << (sequence[i]%32); | ||
delete[] sequence; | ||
} | ||
std::cerr << "Polar(" << N << ", " << K << ")" << std::endl; | ||
auto message = new code_type[K]; | ||
|