38 #ifndef GNSS_SDR_CONVOLUTIONAL_H 39 #define GNSS_SDR_CONVOLUTIONAL_H 41 #include <volk_gnsssdr/volk_gnsssdr.h> 45 const float MAXLOG = 1e7;
63 for (counter = 0; counter < length; counter++)
65 temp_parity = temp_parity ^ (symbol & 1);
98 state = (input << (KK - 1)) ^ state_in;
101 for (i = 0; i < nn; i++)
108 state_out_p[0] = state >> 1;
125 states = (1 << (KK - 1));
128 for (state = 0; state < states; state++)
130 output_p[state] =
nsc_enc_bit(nextstate, input, state, g, KK, nn);
131 trans_p[state] = nextstate[0];
145 inline float Gamma(
const float rec_array[],
153 for (i = 0; i < nn; i++)
157 rm += rec_array[nn - i - 1];
182 const float input_c[],
187 int i, t, state, mm, states;
196 number_symbols = 1 << nn;
198 std::vector<float> prev_section(states, -MAXLOG);
199 std::vector<float> next_section(states, -MAXLOG);
200 std::vector<int> prev_bit(states * (LL + mm), 0);
201 std::vector<int> prev_state(states * (LL + mm), 0);
202 std::vector<float> rec_array(nn);
203 std::vector<float> metric_c(number_symbols);
205 prev_section[0] = 0.0;
208 for (t = 0; t < LL + mm; t++)
210 rec_array.assign(input_c + nn * t, input_c + nn * t + (nn - 1));
213 for (i = 0; i < number_symbols; i++)
215 metric_c[i] =
Gamma(rec_array.data(), i, nn);
219 for (state = 0; state < states; state++)
222 metric = prev_section[state] + metric_c[out0[state]];
225 if (metric > next_section[state0[state]])
227 next_section[state0[state]] = metric;
228 prev_state[t * states + state0[state]] = state;
229 prev_bit[t * states + state0[state]] = 0;
233 metric = prev_section[state] + metric_c[out1[state]];
236 if (metric > next_section[state1[state]])
238 next_section[state1[state]] = metric;
239 prev_state[t * states + state1[state]] = state;
240 prev_bit[t * states + state1[state]] = 1;
245 volk_gnsssdr_32f_index_max_32u(&max_index, next_section.data(), states);
246 max_val = next_section[max_index];
248 for (state = 0; state < states; state++)
250 prev_section[state] = next_section[state] - max_val;
251 next_section[state] = -MAXLOG;
259 for (t = LL + mm - 1; t >= LL; t--)
261 state = prev_state[t * states + state];
264 for (t = LL - 1; t >= 0; t--)
266 output_u_int[t] = prev_bit[t * states + state];
267 state = prev_state[t * states + state];
int nsc_enc_bit(int state_out_p[], int input, int state_in, const int g[], int KK, int nn)
Convolutionally encodes a single bit using a rate 1/n encoder. Takes in one input bit at a time...
void nsc_transit(int output_p[], int trans_p[], int input, int g[], int KK, int nn)
Function that creates the transit and output vectors.
float Gamma(const float rec_array[], int symbol, int nn)
Computes the branch metric used for decoding.
int parity_counter(int symbol, int length)
Determines if a symbol has odd (1) or even (0) parity Output parameters:
void Viterbi(int output_u_int[], const int out0[], const int state0[], const int out1[], const int state1[], const float input_c[], int KK, int nn, int LL)
Uses the Viterbi algorithm to perform hard-decision decoding of a convolutional code.