GNSS-SDR  0.0.13
An Open Source GNSS Software Defined Receiver
viterbi_decoder.h
Go to the documentation of this file.
1 /*!
2  * \file viterbi_decoder.h
3  * \brief Interface of a Viterbi decoder class based on the Iterative Solutions
4  * Coded Modulation Library by Matthew C. Valenti
5  * \author Daniel Fehr 2013. daniel.co(at)bluewin.ch
6  *
7  * -----------------------------------------------------------------------------
8  *
9  * Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
10  *
11  * GNSS-SDR is a software defined Global Navigation
12  * Satellite Systems receiver
13  *
14  * This file is part of GNSS-SDR.
15  *
16  * SPDX-License-Identifier: GPL-3.0-or-later
17  *
18  * -----------------------------------------------------------------------------
19  */
20 
21 #ifndef GNSS_SDR_VITERBI_DECODER_H
22 #define GNSS_SDR_VITERBI_DECODER_H
23 
24 #include <cstddef> // for size_t
25 #include <deque>
26 #include <vector>
27 
28 /*!
29  * \brief Class that implements a Viterbi decoder
30  */
32 {
33 public:
34  Viterbi_Decoder(const int g_encoder[], const int KK, const int nn);
35  ~Viterbi_Decoder() = default;
36  void reset();
37 
38  /*!
39  * \brief Uses the Viterbi algorithm to perform hard-decision decoding of a convolutional code.
40  *
41  * \param[in] input_c[] The received signal in LLR-form. For BPSK, must be in form r = 2*a*y/(sigma^2).
42  * \param[in] LL The number of data bits to be decoded (does not include the mm zero-tail-bits)
43  *
44  * \return output_u_int[] Hard decisions on the data bits (without the mm zero-tail-bits)
45  */
46  float decode_block(const double input_c[], int* output_u_int, const int LL);
47 
48  float decode_continuous(const double sym[], const int traceback_depth, int bits[],
49  const int nbits_requested, int& nbits_decoded);
50 
51 private:
52  class Prev
53  {
54  public:
55  int num_states;
56  Prev(int states, int t);
57  Prev(const Prev& prev);
58  Prev& operator=(const Prev& other);
59  ~Prev();
60 
61  int get_anchestor_state_of_current_state(int current_state) const;
62  int get_bit_of_current_state(int current_state) const;
63  float get_metric_of_current_state(int current_state) const;
64  int get_t() const;
65  void set_current_state_as_ancestor_of_next_state(int next_state, int current_state);
66  void set_decoded_bit_for_next_state(int next_state, int bit);
67  void set_survivor_branch_metric_of_next_state(int next_state, float metric);
68 
69  private:
70  std::vector<float> v_metric;
71  std::vector<int> state;
72  std::vector<int> v_bit;
73  int t;
74  int refcount;
75  };
76 
77  // operations on the trellis (change decoder state)
78  void init_trellis_state();
79  int do_acs(const double sym[], int nbits);
80  int do_traceback(std::size_t traceback_length);
81  int do_tb_and_decode(int traceback_length, int requested_decoding_length, int state, int output_u_int[], float& indicator_metric);
82 
83  // branch metric function
84  float gamma(const float rec_array[], int symbol, int nn);
85 
86  // trellis generation
87  void nsc_transit(int output_p[], int trans_p[], int input, const int g[], int KK, int nn);
88  int nsc_enc_bit(int state_out_p[], int input, int state_in, const int g[], int KK, int nn);
89  int parity_counter(int symbol, int length);
90 
91  // trellis state
92  std::deque<Prev> d_trellis_paths;
93  std::vector<float> d_pm_t;
94  std::vector<float> d_metric_c; /* Set of all possible branch metrics */
95  std::vector<float> d_rec_array; /* Received values for one trellis section */
96 
97  // trellis definition
98  std::vector<int> d_out0;
99  std::vector<int> d_state0;
100  std::vector<int> d_out1;
101  std::vector<int> d_state1;
102 
103  // measures
104  float d_indicator_metric;
105 
106  // code properties
107  int d_KK;
108  int d_nn;
109 
110  // derived code properties
111  int d_mm;
112  int d_states;
113  int d_number_symbols;
114  bool d_trellis_state_is_initialised;
115 };
116 
117 #endif // GNSS_SDR_VITERBI_DECODER_H
float decode_block(const double input_c[], int *output_u_int, const int LL)
Uses the Viterbi algorithm to perform hard-decision decoding of a convolutional code.
Class that implements a Viterbi decoder.