GNSS-SDR  0.0.19
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 Class that implements a Viterbi decoder
4  * \author Carles Fernandez, 2021. cfernandez(at)cttc.es
5  *
6  * -----------------------------------------------------------------------------
7  *
8  * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
9  * This file is part of GNSS-SDR.
10  *
11  * Copyright (C) 2010-2021 (see AUTHORS file for a list of contributors)
12  * SPDX-License-Identifier: GPL-3.0-or-later
13  *
14  * -----------------------------------------------------------------------------
15  */
16 
17 #ifndef GNSS_SDR_VITERBI_DECODER_H
18 #define GNSS_SDR_VITERBI_DECODER_H
19 
20 #include <array>
21 #include <cstdint>
22 #include <vector>
23 
24 /** \addtogroup Telemetry_Decoder
25  * \{ */
26 /** \addtogroup Telemetry_Decoder_libs
27  * Utilities for the decoding of GNSS navigation messages.
28  * \{ */
29 
30 
31 /*!
32  * \brief Class that implements a Viterbi decoder
33  */
35 {
36 public:
37  /*!
38  * \brief Constructor of a Viterbi decoder
39  * \param[in] KK Constraint length
40  * \param[in] nn Coding rate 1/n
41  * \param[in] LL Data length
42  * \param[in] g Polynomial G1 and G2
43  */
44  Viterbi_Decoder(int32_t KK, int32_t nn, int32_t LL, const std::array<int32_t, 2>& g);
45 
46  /*!
47  * \brief Uses the Viterbi algorithm to perform hard-decision decoding of a convolutional code.
48  * \param[out] output_u_int Hard decisions on the data bits
49  * \param[in] input_c The received signal in LLR-form. For BPSK, must be in form r = 2*a*y/(sigma^2).
50  *
51  */
52  void decode(std::vector<int32_t>& output_u_int, const std::vector<float>& input_c);
53 
54  /*!
55  * \brief Reset internal status
56  */
57  void reset();
58 
59 private:
60  /*
61  * Function that creates the transit and output vectors
62  */
63  void nsc_transit(std::vector<int32_t>& output_p,
64  std::vector<int32_t>& trans_p,
65  int32_t input) const;
66 
67  /*
68  * Computes the branch metric used for decoding.
69  * \return (returned float) The metric between the hypothetical symbol and the received vector
70  * \param[in] symbol The hypothetical symbol
71  *
72  */
73  float Gamma(int32_t symbol) const;
74 
75  /*
76  * Determines if a symbol has odd (1) or even (0) parity
77  * Output parameters:
78  * \return (returned int): The symbol's parity = 1 for odd and 0 for even
79  *
80  * \param[in] symbol The integer-valued symbol
81  * \param[in] length The highest bit position in the symbol
82  *
83  * This function is used by nsc_enc_bit()
84  */
85  int32_t parity_counter(int32_t symbol, int32_t length) const;
86 
87  /*
88  * Convolutionally encodes a single bit using a rate 1/n encoder.
89  * Takes in one input bit at a time, and produces a n-bit output.
90  *
91  * \return (returned int): Computed output
92  *
93  * \param[in] input The input data bit (i.e. a 0 or 1).
94  * \param[in] state_in The starting state of the encoder (an int from 0 to 2^m-1).
95  * \param[out] state_out_p[] An integer containing the final state of the encoder
96  * (i.e. the state after encoding this bit)
97  *
98  * This function is used by nsc_transit()
99  */
100  int32_t nsc_enc_bit(int32_t* state_out_p,
101  int32_t input,
102  int32_t state_in) const;
103 
104  std::vector<float> d_prev_section{};
105  std::vector<float> d_next_section{};
106 
107  std::vector<float> d_rec_array{};
108  std::vector<float> d_metric_c{};
109  std::vector<int32_t> d_prev_bit{};
110  std::vector<int32_t> d_prev_state{};
111  std::array<int32_t, 2> d_g{};
112 
113  std::vector<int32_t> d_out0;
114  std::vector<int32_t> d_out1;
115  std::vector<int32_t> d_state0;
116  std::vector<int32_t> d_state1;
117 
118  float d_MAXLOG = 1e7; // Define infinity
119  int32_t d_KK{};
120  int32_t d_nn{};
121  int32_t d_LL{};
122 
123  int32_t d_mm{};
124  int32_t d_states{};
125  int32_t d_number_symbols{};
126 };
127 
128 /** \} */
129 /** \} */
130 #endif // GNSS_SDR_VITERBI_DECODER_H
Viterbi_Decoder(int32_t KK, int32_t nn, int32_t LL, const std::array< int32_t, 2 > &g)
Constructor of a Viterbi decoder.
void decode(std::vector< int32_t > &output_u_int, const std::vector< float > &input_c)
Uses the Viterbi algorithm to perform hard-decision decoding of a convolutional code.
void reset()
Reset internal status.
Class that implements a Viterbi decoder.