From c92bf12fbdd8cd3b02cfe6be66c3abc263370058 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Thu, 27 Aug 2015 09:49:14 -0700 Subject: [PATCH] Extract ChannelDecimator into separate files. --- firmware/baseband/Makefile | 1 + firmware/baseband/channel_decimator.cpp | 74 +++++++++++++++++ firmware/baseband/channel_decimator.hpp | 83 +++++++++++++++++++ firmware/baseband/main.cpp | 103 +----------------------- 4 files changed, 160 insertions(+), 101 deletions(-) create mode 100644 firmware/baseband/channel_decimator.cpp create mode 100644 firmware/baseband/channel_decimator.hpp diff --git a/firmware/baseband/Makefile b/firmware/baseband/Makefile index 10b327ca..ee221a64 100755 --- a/firmware/baseband/Makefile +++ b/firmware/baseband/Makefile @@ -129,6 +129,7 @@ CPPSRC = main.cpp \ gpdma.cpp \ baseband_dma.cpp \ portapack_shared_memory.cpp \ + channel_decimator.cpp \ dsp_decimate.cpp \ dsp_demodulate.cpp \ clock_recovery.cpp \ diff --git a/firmware/baseband/channel_decimator.cpp b/firmware/baseband/channel_decimator.cpp new file mode 100644 index 00000000..89d1af4a --- /dev/null +++ b/firmware/baseband/channel_decimator.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc. + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "channel_decimator.hpp" + +buffer_c16_t ChannelDecimator::execute_decimation(buffer_c8_t buffer) { + /* 3.072MHz complex[2048], [-128, 127] + * -> Shift by -fs/4 + * -> 3rd order CIC: -0.1dB @ 0.028fs, -1dB @ 0.088fs, -60dB @ 0.468fs + * -0.1dB @ 86kHz, -1dB @ 270kHz, -60dB @ 1.44MHz + * -> gain of 256 + * -> decimation by 2 + * -> 1.544MHz complex[1024], [-32768, 32512] */ + const auto stage_0_out = translate.execute(buffer, work_baseband_buffer); + + //if( fs_over_4_downconvert ) { + // // TODO: + //} else { + // Won't work until cic_0 will accept input type of buffer_c8_t. + // stage_0_out = cic_0.execute(buffer, work_baseband_buffer); + //} + + /* 1.536MHz complex[1024], [-32768, 32512] + * -> 3rd order CIC: -0.1dB @ 0.028fs, -1dB @ 0.088fs, -60dB @ 0.468fs + * -0.1dB @ 43kHz, -1dB @ 136kHz, -60dB @ 723kHz + * -> gain of 8 + * -> decimation by 2 + * -> 768kHz complex[512], [-8192, 8128] */ + auto cic_1_out = cic_1.execute(stage_0_out, work_baseband_buffer); + if( decimation_factor == DecimationFactor::By4 ) { + return cic_1_out; + } + + /* 768kHz complex[512], [-32768, 32512] + * -> 3rd order CIC decimation by 2, gain of 1 + * -> 384kHz complex[256], [-32768, 32512] */ + auto cic_2_out = cic_2.execute(cic_1_out, work_baseband_buffer); + if( decimation_factor == DecimationFactor::By8 ) { + return cic_2_out; + } + + /* 384kHz complex[256], [-32768, 32512] + * -> 3rd order CIC decimation by 2, gain of 1 + * -> 192kHz complex[128], [-32768, 32512] */ + auto cic_3_out = cic_3.execute(cic_2_out, work_baseband_buffer); + if( decimation_factor == DecimationFactor::By16 ) { + return cic_3_out; + } + + /* 192kHz complex[128], [-32768, 32512] + * -> 3rd order CIC decimation by 2, gain of 1 + * -> 96kHz complex[64], [-32768, 32512] */ + auto cic_4_out = cic_4.execute(cic_3_out, work_baseband_buffer); + + return cic_4_out; +} diff --git a/firmware/baseband/channel_decimator.hpp b/firmware/baseband/channel_decimator.hpp new file mode 100644 index 00000000..9ec773f8 --- /dev/null +++ b/firmware/baseband/channel_decimator.hpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc. + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __CHANNEL_DECIMATOR_H__ +#define __CHANNEL_DECIMATOR_H__ + +#include "buffer.hpp" +#include "complex.hpp" + +#include "dsp_decimate.hpp" + +#include + +class ChannelDecimator { +public: + enum class DecimationFactor { + By4, + By8, + By16, + By32, + }; + + ChannelDecimator( + DecimationFactor f + ) : decimation_factor { f } + { + } + + void set_decimation_factor(const DecimationFactor f) { + decimation_factor = f; + } + + buffer_c16_t execute(buffer_c8_t buffer) { + auto decimated = execute_decimation(buffer); + + return decimated; + } + +private: + std::array work_baseband; + + const buffer_c16_t work_baseband_buffer { + work_baseband.data(), + work_baseband.size() + }; + const buffer_s16_t work_audio_buffer { + (int16_t*)work_baseband.data(), + sizeof(work_baseband) / sizeof(int16_t) + }; + + //const bool fs_over_4_downconvert = true; + + dsp::decimate::TranslateByFSOver4AndDecimateBy2CIC3 translate; + //dsp::decimate::DecimateBy2CIC3 cic_0; + dsp::decimate::DecimateBy2CIC3 cic_1; + dsp::decimate::DecimateBy2CIC3 cic_2; + dsp::decimate::DecimateBy2CIC3 cic_3; + dsp::decimate::DecimateBy2CIC3 cic_4; + + DecimationFactor decimation_factor { DecimationFactor::By32 }; + + buffer_c16_t execute_decimation(buffer_c8_t buffer); +}; + +#endif/*__CHANNEL_DECIMATOR_H__*/ diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp index 75974d75..51d7f3ea 100755 --- a/firmware/baseband/main.cpp +++ b/firmware/baseband/main.cpp @@ -51,6 +51,8 @@ #include "channel_stats_collector.hpp" #include "audio_stats_collector.hpp" +#include "channel_decimator.hpp" + #include "block_decimator.hpp" #include "clock_recovery.hpp" #include "access_code_correlator.hpp" @@ -76,107 +78,6 @@ constexpr auto baseband_thread_priority = NORMALPRIO + 20; constexpr auto rssi_thread_priority = NORMALPRIO + 10; -class ChannelDecimator { -public: - enum class DecimationFactor { - By4, - By8, - By16, - By32, - }; - - ChannelDecimator( - DecimationFactor f - ) : decimation_factor { f } - { - } - - void set_decimation_factor(const DecimationFactor f) { - decimation_factor = f; - } - - buffer_c16_t execute(buffer_c8_t buffer) { - auto decimated = execute_decimation(buffer); - - return decimated; - } - -private: - std::array work_baseband; - - const buffer_c16_t work_baseband_buffer { - work_baseband.data(), - work_baseband.size() - }; - const buffer_s16_t work_audio_buffer { - (int16_t*)work_baseband.data(), - sizeof(work_baseband) / sizeof(int16_t) - }; - - //const bool fs_over_4_downconvert = true; - - dsp::decimate::TranslateByFSOver4AndDecimateBy2CIC3 translate; - //dsp::decimate::DecimateBy2CIC3 cic_0; - dsp::decimate::DecimateBy2CIC3 cic_1; - dsp::decimate::DecimateBy2CIC3 cic_2; - dsp::decimate::DecimateBy2CIC3 cic_3; - dsp::decimate::DecimateBy2CIC3 cic_4; - - DecimationFactor decimation_factor { DecimationFactor::By32 }; - - buffer_c16_t execute_decimation(buffer_c8_t buffer) { - /* 3.072MHz complex[2048], [-128, 127] - * -> Shift by -fs/4 - * -> 3rd order CIC: -0.1dB @ 0.028fs, -1dB @ 0.088fs, -60dB @ 0.468fs - * -0.1dB @ 86kHz, -1dB @ 270kHz, -60dB @ 1.44MHz - * -> gain of 256 - * -> decimation by 2 - * -> 1.544MHz complex[1024], [-32768, 32512] */ - const auto stage_0_out = translate.execute(buffer, work_baseband_buffer); - - //if( fs_over_4_downconvert ) { - // // TODO: - //} else { - // Won't work until cic_0 will accept input type of buffer_c8_t. - // stage_0_out = cic_0.execute(buffer, work_baseband_buffer); - //} - - /* 1.536MHz complex[1024], [-32768, 32512] - * -> 3rd order CIC: -0.1dB @ 0.028fs, -1dB @ 0.088fs, -60dB @ 0.468fs - * -0.1dB @ 43kHz, -1dB @ 136kHz, -60dB @ 723kHz - * -> gain of 8 - * -> decimation by 2 - * -> 768kHz complex[512], [-8192, 8128] */ - auto cic_1_out = cic_1.execute(stage_0_out, work_baseband_buffer); - if( decimation_factor == DecimationFactor::By4 ) { - return cic_1_out; - } - - /* 768kHz complex[512], [-32768, 32512] - * -> 3rd order CIC decimation by 2, gain of 1 - * -> 384kHz complex[256], [-32768, 32512] */ - auto cic_2_out = cic_2.execute(cic_1_out, work_baseband_buffer); - if( decimation_factor == DecimationFactor::By8 ) { - return cic_2_out; - } - - /* 384kHz complex[256], [-32768, 32512] - * -> 3rd order CIC decimation by 2, gain of 1 - * -> 192kHz complex[128], [-32768, 32512] */ - auto cic_3_out = cic_3.execute(cic_2_out, work_baseband_buffer); - if( decimation_factor == DecimationFactor::By16 ) { - return cic_3_out; - } - - /* 192kHz complex[128], [-32768, 32512] - * -> 3rd order CIC decimation by 2, gain of 1 - * -> 96kHz complex[64], [-32768, 32512] */ - auto cic_4_out = cic_4.execute(cic_3_out, work_baseband_buffer); - - return cic_4_out; - } -}; - static constexpr iir_biquad_config_t audio_hpf_config { { 0.93346032f, -1.86687724f, 0.93346032f }, { 1.0f , -1.97730264f, 0.97773668f }