-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconv_enc.h
182 lines (121 loc) · 4.38 KB
/
conv_enc.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#pragma once
# define I_M_PI 0.3183098862 /* pi */
#include <stdio.h>
#include <malloc.h>
#include <random>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <float.h>
#include <errno.h>
#include <fenv.h>
#include <math.h>
#include <chrono>
#include <iomanip>
#include <ctime>
struct conv_encoder {
int size; // output size, R = 1/size
std::vector <std::string> gen_polys; //there are |size| gen_polys
};
struct sdl {
bool R1;
std::string op;
std::string to;
std::string from;
};
struct sdn {
std::string state;
sdl R1l;
sdl R0l;
};
struct sdiag {
std::vector <sdn> states;
std::vector <sdl> Links;
};
struct tl {
//Trellis link
bool R1; // R1 true then 1/...
std::string prev; // contains previous state -- as current node has tl in vector
std::string op; // /op
double gamma = 0; // gamma
double AYB = 0.0; // A_k-1 + Y_k + B_k
};
struct tn {
// Trellis node and vector of edges connected to node
std::string state; //string containing state
double a = 0; //alpha
double b = 0; //beta
std::vector <tl> edges; // vector containing edges into this node
};
struct trellis_stage {
int stage;
std::vector <tn> nodes;
double L = 0; // likelihood -- used by all but 0th stage to generate uk
};
struct trellis {
int length;
bool terminated = true;
std::vector <trellis_stage> stages;
};
struct a_state { // this is just helpful for states
std::string state;
int a;
};
struct LLR_Decoder {
trellis* Trellis; // This will be used for L(uk|y) calculation -- Stores aswell in trellis stages giving hard estimate
std::vector <double> Luk; //Also used in L(uk|y) calculation (counts as input)
std::vector <double> ydec; // This will contain the yk1 and y(1/2)kp used for input -- assign by make_ys(y, &ydec1, &ydec2)
std::vector <double> Lue; // output used for soft estimate -- Lue = L(uk|y) - Lcyk1 - Luk
double Ebn0; //Channel value used to calculate Lc
double Lc; //Assign from Ebn0 when initiating decoder
};
int c2i(char c);
char i2c(int i);
std::string conv_encode_symbol(int insymb, conv_encoder* encoder, std::string state);
std::string conv_enc_list(std::string inlist, conv_encoder* encoder, bool terminated = true);
int b2n(std::string num, int base);
std::string n2b(int num, int length, int base = 2, bool nl = false);
std::string b2b(std::string num, int ib, int nb);
void print_link(sdl* link);
void print_sys_state_diag(sdiag* sys_state_diag);
sdiag make_systematic_sdaig(conv_encoder* encoder);
int test_encoding();
tl sdl2tl(sdl* sdl_link);
void print_trellis_node(tn* node);
void print_trellis_stage(trellis_stage* stage);
void print_trellis(trellis* Trellis);
trellis_stage make_next_stage(trellis_stage* prev_stage, sdiag* state_diag, int s_dash);
trellis make_trellis(int length, sdiag* sys_state_diag);
int test_trellis();
void terminate_trellis(trellis* Trellis);
void print_v(std::vector <double>* v);
double maxs(double a, double b);
double maxsv(std::vector <double> v);
std::vector <double> edge_bin2double(tl* edge);
void compute_y(trellis* Trellis, std::vector <double> y, double Ebn0_dB, std::vector<double> L_ip);
void compute_a(trellis* Trellis);
void compute_b(trellis* Trellis);
void compute_L(trellis* Trellis);
std::string gen_uest(trellis* Trellis);
void BCJR(trellis* Trellis, std::vector <double> y_vec, double Ebn0_dB);
void AWGN(std::vector <double>* x, double sigma);
int gen_sys_results();
int testing_conv_stuff();
std::string rec_conv_enc_list(std::string inlist, conv_encoder* encoder);
std::string rec_conv_symbol_andVk(int i, conv_encoder* encoder, std::string state);
sdiag make_rec_sdaig(conv_encoder* encoder);
void print_vi(std::vector <int>* v);
std::vector <int> make_I(int L);
void interleave(std::vector <double>* v, std::vector<int>* P);
void deinterleave(std::vector <double>* v, std::vector<int>* P);
void print_dec(LLR_Decoder* dec);
double sumv(std::vector <double>* v);
void comp_norm_L(trellis* Trellis);
void comp_norm_b(trellis* Trellis);
void comp_norm_a(trellis* Trellis);
void norm_y_Luk(LLR_Decoder* decoder);
void round_Lue(LLR_Decoder* decoder);
void init_LLR_Decoder(LLR_Decoder* dec, trellis* Trellis, double Ebn0);
void equate_encoder_polys(conv_encoder* encoder);