1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-11-05 09:43:04 +00:00

Add optional erasure positions to RS decoder

This commit is contained in:
Carles Fernandez
2021-03-26 12:40:35 +01:00
parent 4c51037b14
commit c67ac1247f
3 changed files with 60 additions and 40 deletions

View File

@@ -540,26 +540,24 @@ void ReedSolomon::encode_rs_8(const uint8_t* data, uint8_t* parity) const
}
int ReedSolomon::decode(std::vector<uint8_t>& data_to_decode) const
int ReedSolomon::decode(std::vector<uint8_t>& data_to_decode, const std::vector<int>& erasure_positions) const
{
if (data_to_decode.size() != d_symbols_per_block)
{
std::cerr << "Reed Solomon error: bad input length\n";
return -1;
}
std::vector<uint8_t> decoded_data(d_data_in_block, 0);
int result = decode_rs_8(data_to_decode.data(), nullptr, 0, d_pad);
int result = decode_rs_8(data_to_decode.data(), erasure_positions.data(), erasure_positions.size(), d_pad);
return result;
}
int ReedSolomon::decode_rs_8(uint8_t* data, int* eras_pos, int no_eras, int pad) const
int ReedSolomon::decode_rs_8(uint8_t* data, const int* eras_pos, int no_eras, int pad) const
{
if (pad < 0 || pad > 222)
{
return -1;
}
int retval;
int deg_lambda;
int el;
int deg_omega;
@@ -621,16 +619,7 @@ int ReedSolomon::decode_rs_8(uint8_t* data, int* eras_pos, int no_eras, int pad)
{
// if syndrome is zero, data[] is a codeword and there are no
// errors to correct. So return data[] unmodified
count = 0;
if (eras_pos != nullptr)
{
for (i = 0; i < count; i++)
{
eras_pos[i] = loc[i];
}
}
retval = count;
return retval;
return 0;
}
memset(&lambda[1], 0, d_nroots * sizeof(lambda[0]));
@@ -761,16 +750,7 @@ int ReedSolomon::decode_rs_8(uint8_t* data, int* eras_pos, int no_eras, int pad)
{
// deg(lambda) unequal to number of roots => uncorrectable
// error detected
count = -1;
if (eras_pos != nullptr)
{
for (i = 0; i < count; i++)
{
eras_pos[i] = loc[i];
}
}
retval = count;
return retval;
return -1;
}
// Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo
@@ -821,14 +801,5 @@ int ReedSolomon::decode_rs_8(uint8_t* data, int* eras_pos, int no_eras, int pad)
}
}
if (eras_pos != nullptr)
{
for (i = 0; i < count; i++)
{
eras_pos[i] = loc[i];
}
}
retval = count;
return retval;
return count;
}

View File

@@ -79,11 +79,18 @@ public:
const std::vector<std::vector<uint8_t>>& gen_matrix = std::vector<std::vector<uint8_t>>{});
/*!
* \brief Decode an encoded block. The decoded symbols are at the first
* 255-nroots elements of the input vector. Returns the number of corrected
* errors or -1 if decoding failed.
* \brief Decode an encoded block.
*
* The decoded symbols are at the first 255-nroots elements
* of the input vector.
*
* The second parameter is optional, and contains a vector of erasure
* positions to be passed to the decoding algorithm.
*
* Returns the number of corrected errors or -1 if decoding failed.
*/
int decode(std::vector<uint8_t>& data_to_decode) const;
int decode(std::vector<uint8_t>& data_to_decode,
const std::vector<int>& erasure_positions = std::vector<int>{}) const;
/*!
* \brief Encode data with the generator matrix (for testing purposes)
@@ -98,7 +105,7 @@ public:
private:
static const int d_symbols_per_block = 255; // the total number of symbols in a RS block.
int decode_rs_8(uint8_t* data, int* eras_pos, int no_eras, int pad) const;
int decode_rs_8(uint8_t* data, const int* eras_pos, int no_eras, int pad) const;
int mod255(int x) const;
int rs_min(int a, int b) const;