2022-10-12 13:23:12 +00:00
|
|
|
/* #define DEBUGTRACE_ENABLED */
|
2022-10-06 19:13:21 +00:00
|
|
|
#include "lasp_rtaps.h"
|
2023-06-06 14:05:24 +00:00
|
|
|
#include "lasp_daqdata.h"
|
|
|
|
#include "lasp_daq.h"
|
2022-10-06 19:13:21 +00:00
|
|
|
#include "debugtrace.hpp"
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
using std::cerr;
|
|
|
|
using std::endl;
|
2022-10-16 19:26:06 +00:00
|
|
|
using Lck = std::scoped_lock<std::mutex>;
|
2022-10-06 19:13:21 +00:00
|
|
|
|
2023-06-07 19:49:07 +00:00
|
|
|
RtAps::RtAps(SmgrHandle mgr, const Filter *freqWeightingFilter,
|
2022-10-17 17:37:31 +00:00
|
|
|
const us nfft,
|
|
|
|
const Window::WindowType w,
|
|
|
|
const d overlap_percentage, const d time_constant)
|
|
|
|
: ThreadedInDataHandler(mgr),
|
|
|
|
_ps(nfft, w, overlap_percentage, time_constant) {
|
|
|
|
|
|
|
|
if (freqWeightingFilter != nullptr) {
|
|
|
|
_filterPrototype = freqWeightingFilter->clone();
|
|
|
|
}
|
2022-10-11 12:50:44 +00:00
|
|
|
|
2023-06-06 14:05:24 +00:00
|
|
|
startThread();
|
2022-10-17 17:37:31 +00:00
|
|
|
}
|
2022-10-11 12:50:44 +00:00
|
|
|
RtAps::~RtAps() {
|
2023-06-06 14:05:24 +00:00
|
|
|
stopThread();
|
2022-10-11 12:50:44 +00:00
|
|
|
}
|
2023-06-09 08:43:04 +00:00
|
|
|
void RtAps::inCallback(const DaqData &data) {
|
2022-10-06 19:13:21 +00:00
|
|
|
|
2022-10-11 12:50:44 +00:00
|
|
|
DEBUGTRACE_ENTER;
|
2022-10-06 19:13:21 +00:00
|
|
|
|
2022-10-17 17:37:31 +00:00
|
|
|
Lck lck(_ps_mtx);
|
2022-10-16 19:26:06 +00:00
|
|
|
|
2022-10-06 19:13:21 +00:00
|
|
|
dmat fltdata = data.toFloat();
|
2022-10-12 13:23:12 +00:00
|
|
|
const us nchannels = fltdata.n_cols;
|
2022-10-17 17:37:31 +00:00
|
|
|
if(nchannels != _sens.size()) {
|
|
|
|
cerr << "**** Error: sensitivity size does not match! *****" << endl;
|
2023-06-09 08:43:04 +00:00
|
|
|
return;
|
2022-10-17 17:37:31 +00:00
|
|
|
}
|
|
|
|
fltdata.each_row() %= _sens.as_row();
|
2022-10-12 13:23:12 +00:00
|
|
|
|
|
|
|
if (_filterPrototype) {
|
|
|
|
|
|
|
|
// Adjust number of filters, if necessary
|
2022-10-16 16:39:13 +00:00
|
|
|
if (nchannels > _freqWeightingFilters.size()) {
|
|
|
|
while (nchannels > _freqWeightingFilters.size()) {
|
|
|
|
_freqWeightingFilters.emplace_back(_filterPrototype->clone());
|
2022-10-12 13:23:12 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 16:39:13 +00:00
|
|
|
for (auto &filter : _freqWeightingFilters) {
|
2022-10-12 13:23:12 +00:00
|
|
|
filter->reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply filtering
|
2022-10-17 17:37:31 +00:00
|
|
|
#pragma omp parallel for
|
2022-10-12 13:23:12 +00:00
|
|
|
for (us i = 0; i < nchannels; i++) {
|
|
|
|
vd col = fltdata.col(i);
|
2022-10-16 16:39:13 +00:00
|
|
|
_freqWeightingFilters.at(i)->filter(col);
|
2022-10-12 13:23:12 +00:00
|
|
|
fltdata.col(i) = col;
|
|
|
|
}
|
|
|
|
} // End of if(_filterPrototype)
|
2022-10-06 19:13:21 +00:00
|
|
|
|
2022-10-11 12:50:44 +00:00
|
|
|
_ps.compute(fltdata);
|
2022-10-06 19:13:21 +00:00
|
|
|
|
|
|
|
}
|
2022-10-17 17:37:31 +00:00
|
|
|
void RtAps::reset(const Daq *daq) {
|
2022-10-06 19:13:21 +00:00
|
|
|
|
|
|
|
DEBUGTRACE_ENTER;
|
2022-10-16 19:26:06 +00:00
|
|
|
Lck lck(_ps_mtx);
|
2022-10-17 17:37:31 +00:00
|
|
|
for (auto &filter : _freqWeightingFilters) {
|
|
|
|
filter->reset();
|
|
|
|
}
|
|
|
|
if(daq) {
|
|
|
|
_sens.resize(daq->neninchannels());
|
|
|
|
us i = 0;
|
|
|
|
for(const auto& ch: daq->enabledInChannels()) {
|
|
|
|
_sens[i] = ch.sensitivity;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-06 19:13:21 +00:00
|
|
|
_ps.reset();
|
|
|
|
}
|
|
|
|
|
2022-10-16 19:26:06 +00:00
|
|
|
ccube RtAps::getCurrentValue() const {
|
2022-10-06 19:13:21 +00:00
|
|
|
|
2022-10-17 17:37:31 +00:00
|
|
|
DEBUGTRACE_ENTER;
|
2022-10-16 19:26:06 +00:00
|
|
|
Lck lck(_ps_mtx);
|
|
|
|
return _ps.get_est();
|
2022-10-06 19:13:21 +00:00
|
|
|
|
|
|
|
}
|