From 45e954f3aeca322bd6e9f0c165e6c99aaf52f740 Mon Sep 17 00:00:00 2001 From: Marek Blok <Marek.Blok@pg.edu.pl> Date: Wed, 14 Jun 2023 09:21:31 +0200 Subject: [PATCH] fixed gray coding in DSP::u::SymbolMapper --- .vscode/launch.json | 2 +- CHANGELOG | 4 +++- src/Main.cpp | 11 ++++++----- src/cpp/DSP_modules2.cpp | 28 ++++++++++++++++------------ src/include/DSP_lib.h | 2 +- 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 38a0e83..4644648 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,7 +16,7 @@ "externalConsole": false, "MIMode": "gdb", // "miDebuggerPath": "d:/CodeBlocks_20_03/MinGW/bin/gdb.exe", - "miDebuggerPath": "c:/msys64/usr/bin/gdb.exe", + "miDebuggerPath": "c:/msys64/mingw64/bin/gdb.exe", "setupCommands": [ { "description": "WĹÄ cz formatowanie kodu dla gdb", diff --git a/CHANGELOG b/CHANGELOG index 0587b15..5c69245 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,8 +8,10 @@ TODO:: LAST DONE: CHANGES: +- ver. 0.20.028 - <b>2023.06.14</b> Fixed: + - fixed gray coding in DSP::u::SymbolMapper - ver. 0.20.027 - <b>2022.04.21</b> Fixed: - - not Main.o is not included in libDSPE.a + - now Main.o is not included in libDSPE.a - ver. 0.20.026 - <b>2022.04.21</b> Fixed: - fixed DSP::TMorseTable::LoadFromFile - DSP::TMorseTable::LoadFromFile and DSP::u::MORSEkey::LoadFromFile now read file based on full path to *.mct file diff --git a/src/Main.cpp b/src/Main.cpp index 7c01e03..ca3bf3e 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -2526,7 +2526,8 @@ int test_SymbolMapper() { blocks["binary_stream"]->Output("out") >> blocks["file_bin"]->Input("in"); blocks["SPconv"] = std::make_shared<DSP::u::Serial2Parallel>(BitClock, bits_per_symbol); - blocks["mapper"] = std::make_shared<DSP::u::SymbolMapper>(DSP::e::ModulationType::ASK, bits_per_symbol); + //blocks["mapper"] = std::make_shared<DSP::u::SymbolMapper>(DSP::e::ModulationType::ASK, bits_per_symbol); + blocks["mapper"] = std::make_shared<DSP::u::SymbolMapper>(DSP::e::ModulationType::PSK, bits_per_symbol); blocks["binary_stream"]->Output("out") >> blocks["SPconv"]->Input("in"); blocks["SPconv"]->Output("out") >> blocks["mapper"]->Input("in"); SymbolClock = blocks["mapper"]->GetOutputClock(); @@ -2953,6 +2954,10 @@ int main(int argc, char*argv[]) DSP::log.SetLogState(DSP::e::LogState::console | DSP::e::LogState::file); DSP::log.SetLogFileName("DSPElib_test_log.txt"); + DSP::log << "Starting SymbolMapper test" << std::endl; + test_SymbolMapper(); + DSP::log << DSP::e::LogMode::pause << "Finished SymbolMapper test" << std::endl; + DSP::log << "test MORSEkey" << std::endl; { DSP::TMorseTable MorseTable; @@ -2997,10 +3002,6 @@ int main(int argc, char*argv[]) #endif // INCLUDE_DSPE_EXAMPLES - DSP::log << "Starting SymbolMapper test" << std::endl; - test_SymbolMapper(); - DSP::log << DSP::e::LogMode::pause << "Finished SymbolMapper test" << std::endl; - DSP::log << "Starting test_ZPSTC_cw_3" << std::endl; test_ZPSTC_cw_3(); DSP::log << "Finished test_ZPSTC_cw_3" << DSP::e::LogMode::pause << std::endl; diff --git a/src/cpp/DSP_modules2.cpp b/src/cpp/DSP_modules2.cpp index bba270b..8a37568 100644 --- a/src/cpp/DSP_modules2.cpp +++ b/src/cpp/DSP_modules2.cpp @@ -1788,10 +1788,11 @@ unsigned int getConstellation( // constellation[n].re = static_cast<DSP::Float>(cos(constellation_phase_offset+(DSP::M_PIx2*n)/M)); // constellation[n].im = static_cast<DSP::Float>(sin(constellation_phase_offset+(DSP::M_PIx2*n)/M)); // } - // Gray codding (start from LSB) - uint16_t mask = 0x0001; - uint16_t n = 0; + // // Gray codding (start from LSB) + // uint16_t mask = 0x0001; + unsigned int n = 0; for (unsigned int ind=0; ind < M; ind++) { + n = ind ^ (ind >> 1); // convert to gray coding constellation[ind].re = static_cast<DSP::Float>(cos(constellation_phase_offset+(DSP::M_PIx2*n)/DSP::Float(M))); constellation[ind].im = static_cast<DSP::Float>(sin(constellation_phase_offset+(DSP::M_PIx2*n)/DSP::Float(M))); @@ -1799,12 +1800,13 @@ unsigned int getConstellation( // ss << "constellation[" << ind << "]={" << std::setprecision(2) << constellation[ind].re << "," << constellation[ind].im << "}; n=" << n; // DSP::f::InfoMessage(ss.str()); - n ^= mask; - //mask <<= 1u; - mask = uint16_t(mask << 1); - if (mask == M) { - mask = 0x0001; - } + // n ^= mask; + // //mask <<= 1u; + // mask = uint16_t(mask << 1); + // if (n >= M) { + // n = 0; + // mask = 0x0001; + // } } } //! \TODO is_real should be set based on analysis of all constellation points @@ -1818,9 +1820,11 @@ unsigned int getConstellation( case DSP::e::ModulationType::ASK: { constellation.resize(M); - for (unsigned int n=0; n < M; n++) { - constellation[n].re = static_cast<DSP::Float>(n)/static_cast<DSP::Float>(M-1); - constellation[n].im = 0; + unsigned int n; + for (unsigned int ind=0; ind < M; ind++) { + n = ind ^ (ind >> 1); // convert to gray coding + constellation[ind].re = static_cast<DSP::Float>(n)/static_cast<DSP::Float>(M-1); + constellation[ind].im = 0; } if (constellation_phase_offset != 0.0) { for (unsigned int ind=0; ind < M; ind++) { diff --git a/src/include/DSP_lib.h b/src/include/DSP_lib.h index 15ca7d7..f462cf2 100644 --- a/src/include/DSP_lib.h +++ b/src/include/DSP_lib.h @@ -11,7 +11,7 @@ #define DSP_VER_MAJOR 0 #define DSP_VER_MINOR 20 -#define DSP_VER_BUILD 27 // !!! without zeroes before, else this will be treated as octal number +#define DSP_VER_BUILD 28 // !!! without zeroes before, else this will be treated as octal number #define DSP_VER_YEAR 2023 #define DSP_VER DSP_VER_MAJOR.DSP_VER_MINOR.DSP_VER_BUILD -- GitLab