From e900a5ddade4fc2c9cd0b26ad659d349b8b47370 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Tue, 4 Oct 2022 09:48:32 +0200 Subject: [PATCH] Updated PPM to give clip indices length same as number of channels. Grouped the real time components to group dsp/rt. --- src/lasp/dsp/lasp_fft.h | 5 +++-- src/lasp/dsp/lasp_ppm.cpp | 20 ++++++++++---------- src/lasp/dsp/lasp_ppm.h | 4 ++++ src/lasp/dsp/lasp_threadedindatahandler.h | 14 ++++++++++++++ src/lasp/pybind11/lasp_pyindatahandler.cpp | 5 +++-- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/lasp/dsp/lasp_fft.h b/src/lasp/dsp/lasp_fft.h index 6e3bcf6..9556dee 100644 --- a/src/lasp/dsp/lasp_fft.h +++ b/src/lasp/dsp/lasp_fft.h @@ -17,8 +17,9 @@ class Fft_impl; /** - * Perform forward FFT's on real time data. Computes single-sided spectra, - * equivalent to Numpy's rfft and irfft functions. + * @brief Perform forward FFT's on real time data. Computes single-sided spectra, + * equivalent to Numpy's rfft and irfft functions. But then faster as it can + * use a fast FFT backend, such as FFTW. */ class Fft { std::unique_ptr _impl; diff --git a/src/lasp/dsp/lasp_ppm.cpp b/src/lasp/dsp/lasp_ppm.cpp index f374d41..8395a55 100644 --- a/src/lasp/dsp/lasp_ppm.cpp +++ b/src/lasp/dsp/lasp_ppm.cpp @@ -10,10 +10,10 @@ using Lck = std::scoped_lock; using rte = std::runtime_error; PPMHandler::PPMHandler(StreamMgr &mgr, const d decay_dBps) - : ThreadedInDataHandler(mgr), _decay_dBps(decay_dBps) { - DEBUGTRACE_ENTER; - start(); - } + : ThreadedInDataHandler(mgr), _decay_dBps(decay_dBps) { + DEBUGTRACE_ENTER; + start(); +} bool PPMHandler::inCallback_threaded(const DaqData &d) { /* DEBUGTRACE_ENTER; */ std::scoped_lock lck(_mtx); @@ -40,7 +40,7 @@ bool PPMHandler::inCallback_threaded(const DaqData &d) { } else if (_clip_time(i) > clip_indication_time) { /// Reset to 'unclipped' _clip_time(i) = -1; - } else if(_clip_time(i) >= 0) { + } else if (_clip_time(i) >= 0) { /// Add a bit of clip time _clip_time(i) += _dt; } @@ -59,10 +59,10 @@ bool PPMHandler::inCallback_threaded(const DaqData &d) { std::tuple PPMHandler::getCurrentValue() const { std::scoped_lock lck(_mtx); - return {20 * arma::log10(_cur_max + arma::datum::eps).as_col(), - arma::find(_clip_time >= 1.0)}; - /* return {(_cur_max + arma::datum::eps).as_col(), */ - /* arma::find(_clip_time >= 1.0)}; */ + arma::uvec clips(_clip_time.size(), arma::fill::zeros); + clips.elem(arma::find(_clip_time >= 0)).fill(1); + + return {20 * arma::log10(_cur_max + arma::datum::eps).as_col(), clips}; } void PPMHandler::reset(const Daq *daq) { @@ -78,7 +78,7 @@ void PPMHandler::reset(const Daq *daq) { DEBUGTRACE_PRINT(fs); _dt = daq->framesPerBlock() / fs; - _alpha = std::max(d_pow(10, -_dt*_decay_dBps / (20)), 0); + _alpha = std::max(d_pow(10, -_dt * _decay_dBps / (20)), 0); DEBUGTRACE_PRINT(_alpha); } } diff --git a/src/lasp/dsp/lasp_ppm.h b/src/lasp/dsp/lasp_ppm.h index a9926fb..cbc7776 100644 --- a/src/lasp/dsp/lasp_ppm.h +++ b/src/lasp/dsp/lasp_ppm.h @@ -12,6 +12,9 @@ /** * \addtogroup dsp * @{ + * + * \addtogroup rt + * @{ */ @@ -82,3 +85,4 @@ class PPMHandler: public ThreadedInDataHandler { }; /** @} */ +/** @} */ diff --git a/src/lasp/dsp/lasp_threadedindatahandler.h b/src/lasp/dsp/lasp_threadedindatahandler.h index 02ef725..6f4f06f 100644 --- a/src/lasp/dsp/lasp_threadedindatahandler.h +++ b/src/lasp/dsp/lasp_threadedindatahandler.h @@ -4,6 +4,16 @@ const us RINGBUFFER_SIZE = 1024; + +/** + * \addtogroup dsp + * @{ + * + * \defgroup rt Real time signal handlers + * @{ + */ + + /** * @brief Threaded in data handler. Buffers inCallback data and calls a * callback with the same signature on a different thread. @@ -46,3 +56,7 @@ class ThreadedInDataHandler: public InDataHandler { virtual bool inCallback_threaded(const DaqData&) = 0; }; + + +/** @} */ +/** @} */ diff --git a/src/lasp/pybind11/lasp_pyindatahandler.cpp b/src/lasp/pybind11/lasp_pyindatahandler.cpp index 7c42fd5..eeaa413 100644 --- a/src/lasp/pybind11/lasp_pyindatahandler.cpp +++ b/src/lasp/pybind11/lasp_pyindatahandler.cpp @@ -1,6 +1,6 @@ /* #define DEBUGTRACE_ENABLED */ -#include #include "debugtrace.hpp" +#include #include "lasp_ppm.h" #include "lasp_streammgr.h" #include "lasp_threadedindatahandler.h" @@ -149,6 +149,7 @@ void init_datahandler(py::module &m) { ppm.def("getCurrentValue", [](const PPMHandler &ppm) { auto [level, clip] = ppm.getCurrentValue(); - return py::make_tuple(carma::col_to_arr(level), carma::col_to_arr(clip)); + return py::make_tuple(carma::col_to_arr(std::move(level)), + carma::col_to_arr(std::move(clip))); }); }