Updated PPM to give clip indices length same as number of channels. Grouped the real time components to group dsp/rt.

This commit is contained in:
Anne de Jong 2022-10-04 09:48:32 +02:00
parent 5f1a207104
commit e900a5ddad
5 changed files with 34 additions and 14 deletions

View File

@ -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<Fft_impl> _impl;

View File

@ -10,10 +10,10 @@ using Lck = std::scoped_lock<std::mutex>;
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<std::mutex> 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<vd, arma::uvec> PPMHandler::getCurrentValue() const {
std::scoped_lock<std::mutex> 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>(d_pow(10, -_dt*_decay_dBps / (20)), 0);
_alpha = std::max<d>(d_pow(10, -_dt * _decay_dBps / (20)), 0);
DEBUGTRACE_PRINT(_alpha);
}
}

View File

@ -12,6 +12,9 @@
/**
* \addtogroup dsp
* @{
*
* \addtogroup rt
* @{
*/
@ -82,3 +85,4 @@ class PPMHandler: public ThreadedInDataHandler {
};
/** @} */
/** @} */

View File

@ -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;
};
/** @} */
/** @} */

View File

@ -1,6 +1,6 @@
/* #define DEBUGTRACE_ENABLED */
#include <carma>
#include "debugtrace.hpp"
#include <carma>
#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)));
});
}