-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathblock_enc_system.c
54 lines (44 loc) · 1.73 KB
/
block_enc_system.c
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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "headers/polarCodes.h"
int main() {
srand(time(NULL));
struct PC_CONFIG pcConfig;
// Polar Code Config
pcConfig.E = 512;
pcConfig.K = 100;
pcConfig.nMax = 10;
pcConfig.iBIL = 0;
pcConfig.iIL = 0;
pcConfig.K_IL_MAX = 164;
pcConfig.UL_DL = 0;
pcConfig.L = 8;
pcConfig.crcLen = 24;
pcConfig.crcPolyID = 1;
pcConfig.decodingMethod = 1;
pcConfig.iter_BP = 1;
pcConfig.LR_PROB_1 = pcConfig.decodingMethod == 1 ? 0:1; // if 0 - output is Likelihood Ratio else Probability of bit being 1
int remLen = 0;
int err = 1;
double SNR_dB = 5;
printf("SNR (dB): %f\n", SNR_dB);
int * dataBits = DATA_GEN(pcConfig.K - pcConfig.crcLen);
int * crcData = NR_CRC_ENCODER(dataBits, &pcConfig);
int * encData = NR_PC_ENCODER(crcData, &pcConfig);
int * rateMatcData = NR_PC_RATE_MATCH(encData, &pcConfig);
double * modData = BPSK_MOD(rateMatcData, pcConfig.E);
double * rxData = AWGN(modData, pcConfig.E, SNR_dB);
double * rxLR = BPSK_DEMOD(rxData, pcConfig.E, pcConfig.LR_PROB_1);
double * rateRecoverData = NR_PC_RATE_RECOVER(rxLR, &pcConfig);
int * decData = NR_PC_DECODER(rateRecoverData, &pcConfig);
int * dataHat = NR_CRC_DECODER(decData, &pcConfig, &err);
printf("Result: ");
if (err == 0) {
printf("Successful Transmission with %d out of %d bits in error\n", bitXORSum(dataHat, dataBits, pcConfig.K - pcConfig.crcLen), pcConfig.K - pcConfig.crcLen);
} else {
printf("Corrupted Reception with %d out of %d bits in error\n", bitXORSum(dataHat, dataBits, pcConfig.K - pcConfig.crcLen), pcConfig.K - pcConfig.crcLen);
}
return 0;
}