From 6a709fe24b50150c653f7660632fd8d1d9f50be6 Mon Sep 17 00:00:00 2001 From: Paul Colby Date: Sat, 2 Jan 2021 03:11:02 -0800 Subject: [PATCH] Modified ModemAM (#865) Works perfectly :) --- src/modules/modem/analog/ModemAM.cpp | 24 ++++++++++++++++-------- src/modules/modem/analog/ModemAM.h | 12 ++++++------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/modules/modem/analog/ModemAM.cpp b/src/modules/modem/analog/ModemAM.cpp index 8d1d167..e9c49d7 100644 --- a/src/modules/modem/analog/ModemAM.cpp +++ b/src/modules/modem/analog/ModemAM.cpp @@ -4,12 +4,14 @@ #include "ModemAM.h" ModemAM::ModemAM() : ModemAnalog() { - demodAM = ampmodem_create(0.5, LIQUID_AMPMODEM_DSB, 0); + // Create a DC blocker using 25 samples wide window + // and 30dB reduction of the DC level. + mDCBlock = firfilt_rrrf_create_dc_blocker (25,30.0f); useSignalOutput(true); } ModemAM::~ModemAM() { - ampmodem_destroy(demodAM); + firfilt_rrrf_destroy(mDCBlock); } ModemBase *ModemAM::factory() { @@ -26,17 +28,23 @@ int ModemAM::getDefaultSampleRate() { void ModemAM::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput* audioOut) { ModemKitAnalog *amkit = (ModemKitAnalog *)kit; - + initOutputBuffers(amkit,input); - + if (!bufSize) { - + return; } - + + // Implement an AM demodulator. Compute signal + // amplitude followed by a DC blocker to remove + // the DC offset. for (size_t i = 0; i < bufSize; i++) { - ampmodem_demodulate(demodAM, input->data[i], &demodOutputData[i]); + float I = input->data[i].real; + float Q = input->data[i].imag; + firfilt_rrrf_push (mDCBlock,sqrt(I*I+Q*Q)); + firfilt_rrrf_execute (mDCBlock,&demodOutputData[i]); } - + buildAudioOutput(amkit,audioOut,true); } diff --git a/src/modules/modem/analog/ModemAM.h b/src/modules/modem/analog/ModemAM.h index af165b9..fd3496e 100644 --- a/src/modules/modem/analog/ModemAM.h +++ b/src/modules/modem/analog/ModemAM.h @@ -9,15 +9,15 @@ class ModemAM : public ModemAnalog { public: ModemAM(); ~ModemAM(); - + std::string getName(); - + static ModemBase *factory(); - + int getDefaultSampleRate(); void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut); - + private: - ampmodem demodAM; -}; \ No newline at end of file + firfilt_rrrf mDCBlock; +};