35 #ifndef GNSS_SDR_CONVOLUTIONAL_H 36 #define GNSS_SDR_CONVOLUTIONAL_H 38 #include <volk_gnsssdr/volk_gnsssdr.h> 49 const float MAXLOG = 1e7;
67 for (counter = 0; counter < length; counter++)
69 temp_parity = temp_parity ^ (symbol & 1);
102 state = (input << (KK - 1)) ^ state_in;
105 for (i = 0; i < nn; i++)
112 state_out_p[0] = state >> 1;
129 states = (1 << (KK - 1));
132 for (state = 0; state < states; state++)
134 output_p[state] =
nsc_enc_bit(nextstate, input, state, g, KK, nn);
135 trans_p[state] = nextstate[0];
149 inline float Gamma(
const float rec_array[],
157 for (i = 0; i < nn; i++)
161 rm += rec_array[nn - i - 1];
186 const float input_c[],
191 int i, t, state, mm, states;
200 number_symbols = 1 << nn;
202 std::vector<float> prev_section(states, -MAXLOG);
203 std::vector<float> next_section(states, -MAXLOG);
204 std::vector<int> prev_bit(states * (LL + mm), 0);
205 std::vector<int> prev_state(states * (LL + mm), 0);
206 std::vector<float> rec_array(nn);
207 std::vector<float> metric_c(number_symbols);
209 prev_section[0] = 0.0;
212 for (t = 0; t < LL + mm; t++)
214 rec_array.assign(input_c + nn * t, input_c + nn * t + (nn - 1));
217 for (i = 0; i < number_symbols; i++)
219 metric_c[i] =
Gamma(rec_array.data(), i, nn);
223 for (state = 0; state < states; state++)
226 metric = prev_section[state] + metric_c[out0[state]];
229 if (metric > next_section[state0[state]])
231 next_section[state0[state]] = metric;
232 prev_state[t * states + state0[state]] = state;
233 prev_bit[t * states + state0[state]] = 0;
237 metric = prev_section[state] + metric_c[out1[state]];
240 if (metric > next_section[state1[state]])
242 next_section[state1[state]] = metric;
243 prev_state[t * states + state1[state]] = state;
244 prev_bit[t * states + state1[state]] = 1;
249 volk_gnsssdr_32f_index_max_32u(&max_index, next_section.data(), states);
250 max_val = next_section[max_index];
252 for (state = 0; state < states; state++)
254 prev_section[state] = next_section[state] - max_val;
255 next_section[state] = -MAXLOG;
263 for (t = LL + mm - 1; t >= LL; t--)
265 state = prev_state[t * states + state];
268 for (t = LL - 1; t >= 0; t--)
270 output_u_int[t] = prev_bit[t * states + state];
271 state = prev_state[t * states + state];
278 #endif // GNSS_SDR_CONVOLUTIONAL_H int parity_counter(int symbol, int length)
Determines if a symbol has odd (1) or even (0) parity Output parameters:
float Gamma(const float rec_array[], int symbol, int nn)
Computes the branch metric used for decoding.
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.
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.
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...