diff --git a/plugins/channelrx/demodchirpchat/chirpchatdemoddecoderft.cpp b/plugins/channelrx/demodchirpchat/chirpchatdemoddecoderft.cpp index 1cabc0361..dbfcbc285 100644 --- a/plugins/channelrx/demodchirpchat/chirpchatdemoddecoderft.cpp +++ b/plugins/channelrx/demodchirpchat/chirpchatdemoddecoderft.cpp @@ -54,16 +54,40 @@ void ChirpChatDemodDecoderFT::decodeSymbols( return; } - float *lls = new float[mags.size()*nbSymbolBits]; // bits log likelihoods (>0 for 0, <0 for 1) - std::fill(lls, lls+mags.size()*nbSymbolBits, 0.0); + // float *lls = new float[mags.size()*nbSymbolBits]; // bits log likelihoods (>0 for 0, <0 for 1) + // std::fill(lls, lls+mags.size()*nbSymbolBits, 0.0); FT8::FT8Params params; - FT8::FT8::soft_decode_mags(params, mags, nbSymbolBits, lls); + // FT8::FT8::soft_decode_mags(params, mags, nbSymbolBits, lls); int r174[174]; std::string comments; payloadParityStatus = (int) ChirpChatDemodSettings::ParityOK; payloadCRCStatus = false; + std::vector> magsp = mags; - if (FT8::FT8::decode(lls, r174, params, 0, comments) == 0) + qDebug("ChirpChatDemodDecoderFT::decodeSymbols: try decode with symbol shift 0"); + int res = decodeWithShift(params, magsp, nbSymbolBits, r174, comments); + + if (res == 0) + { + std::vector> magsn = mags; + int shiftcount = 0; + + while ((res == 0) && (shiftcount < 7)) + { + qDebug("ChirpChatDemodDecoderFT::decodeSymbols: try decode with symbol shift %d", shiftcount + 1); + res = decodeWithShift(params, magsp, nbSymbolBits, r174, comments, 1); + + if (res == 0) + { + qDebug("ChirpChatDemodDecoderFT::decodeSymbols: try decode with symbol shift -%d", shiftcount + 1); + res = decodeWithShift(params, magsn, nbSymbolBits, r174, comments, -1); + } + + shiftcount++; + } + } + + if (res == 0) { if (comments == "LDPC fail") { @@ -108,4 +132,45 @@ void ChirpChatDemodDecoderFT::decodeSymbols( } } +int ChirpChatDemodDecoderFT::decodeWithShift( + FT8::FT8Params& params, + std::vector>& mags, + int nbSymbolBits, + int *r174, + std::string& comments, + int shift +) +{ + if (shift > 0) + { + for (unsigned int si = 0; si < mags.size(); si++) + { + for (int bini = (1< 0; bini--) + { + float x = mags[si][bini - 1]; + mags[si][bini - 1] = mags[si][bini]; + mags[si][bini] = x; + } + } + } + + if (shift < 0) + { + for (unsigned int si = 0; si < mags.size(); si++) + { + for (int bini = 0; bini < (1<0 for 0, <0 for 1) + std::fill(lls, lls+mags.size()*nbSymbolBits, 0.0); + FT8::FT8::soft_decode_mags(params, mags, nbSymbolBits, lls); + return FT8::FT8::decode(lls, r174, params, 0, comments); +} + #endif // HAS_FT8 diff --git a/plugins/channelrx/demodchirpchat/chirpchatdemoddecoderft.h b/plugins/channelrx/demodchirpchat/chirpchatdemoddecoderft.h index a6975d230..f921cf815 100644 --- a/plugins/channelrx/demodchirpchat/chirpchatdemoddecoderft.h +++ b/plugins/channelrx/demodchirpchat/chirpchatdemoddecoderft.h @@ -21,6 +21,10 @@ #include #include +namespace FT8 { + class FT8Params; +} + class ChirpChatDemodDecoderFT { public: @@ -39,10 +43,20 @@ public: std::string& call1, //!< 1st callsign or shorthand std::string& call2, //!< 2nd callsign std::string& loc, //!< locator, report or shorthand - bool& reply , //!< true if message is a reply report + bool& reply, //!< true if message is a reply report int& payloadParityStatus, bool& payloadCRCStatus ); + +private: + static int decodeWithShift( + FT8::FT8Params& params, + std::vector>& mags, + int nbSymbolBits, + int *r174, + std::string& comments, + int shift = 0 + ); };