From 76dbdfb5261acf3f90d58b10d70d7dbd47752121 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Sun, 16 Oct 2022 18:39:13 +0200 Subject: [PATCH] Working equalizer --- src/lasp/dsp/lasp_avpowerspectra.cpp | 1 + src/lasp/dsp/lasp_rtaps.cpp | 12 ++++++------ src/lasp/dsp/lasp_rtaps.h | 2 +- src/lasp/lasp_octavefilter.py | 21 +++++++++++++++------ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/lasp/dsp/lasp_avpowerspectra.cpp b/src/lasp/dsp/lasp_avpowerspectra.cpp index 7832f66..83c7f05 100644 --- a/src/lasp/dsp/lasp_avpowerspectra.cpp +++ b/src/lasp/dsp/lasp_avpowerspectra.cpp @@ -81,6 +81,7 @@ AvPowerSpectra::AvPowerSpectra(const us nfft, const Window::WindowType w, void AvPowerSpectra::reset() { _timeBuf.reset(); _est.reset(); + n_averages=0; } diff --git a/src/lasp/dsp/lasp_rtaps.cpp b/src/lasp/dsp/lasp_rtaps.cpp index d7d2de1..4f3af10 100644 --- a/src/lasp/dsp/lasp_rtaps.cpp +++ b/src/lasp/dsp/lasp_rtaps.cpp @@ -34,21 +34,21 @@ bool RtAps::inCallback_threaded(const DaqData &data) { if (_filterPrototype) { // Adjust number of filters, if necessary - if (nchannels > _freqWeightingFilter.size()) { - while (nchannels > _freqWeightingFilter.size()) { - _freqWeightingFilter.emplace_back(_filterPrototype->clone()); + if (nchannels > _freqWeightingFilters.size()) { + while (nchannels > _freqWeightingFilters.size()) { + _freqWeightingFilters.emplace_back(_filterPrototype->clone()); } - for (auto &filter : _freqWeightingFilter) { + for (auto &filter : _freqWeightingFilters) { filter->reset(); } } // Apply filtering - #pragma omp parallel for + /* #pragma omp parallel for */ for (us i = 0; i < nchannels; i++) { vd col = fltdata.col(i); - _freqWeightingFilter.at(i)->filter(col); + _freqWeightingFilters.at(i)->filter(col); fltdata.col(i) = col; } } // End of if(_filterPrototype) diff --git a/src/lasp/dsp/lasp_rtaps.h b/src/lasp/dsp/lasp_rtaps.h index 26a0510..9443c75 100644 --- a/src/lasp/dsp/lasp_rtaps.h +++ b/src/lasp/dsp/lasp_rtaps.h @@ -23,7 +23,7 @@ class RtAps : public ThreadedInDataHandler { std::mutex _mtx; std::unique_ptr _filterPrototype; - std::vector> _freqWeightingFilter; + std::vector> _freqWeightingFilters; AvPowerSpectra _ps; diff --git a/src/lasp/lasp_octavefilter.py b/src/lasp/lasp_octavefilter.py index 0cdbe72..632cd78 100644 --- a/src/lasp/lasp_octavefilter.py +++ b/src/lasp/lasp_octavefilter.py @@ -235,12 +235,20 @@ class SosFilterBank: self.fs = fs self.xs = list(range(xmin, xmax + 1)) + + # The number of parallel filters nfilt = len(self.xs) + self.nfilt = nfilt - self._fb = pyxSosFilterBank(nfilt, 5) + + sos = None for i, x in enumerate(self.xs): - sos = self.designer.createSOSFilter(x) - self._fb.setFilter(i, sos) + channel = self.designer.createSOSFilter(x) + if sos is None: + sos = np.empty((channel.size, len(self.xs))) + sos[:, i] = channel.flatten() + + self._fb = BiquadBank(sos) self.xmin = xmin self.xmax = xmax @@ -250,13 +258,14 @@ class SosFilterBank: """ Filter input data """ - assert data.ndim == 2 - assert data.shape[1] == 1, "invalid number of channels, should be 1" + + if data.ndim > 1 and data.shape[1] != 1: + raise RuntimeError("invalid number of channels, should be 1") if data.shape[0] == 0: return {} - filtered_data = self._fb.filter_(data) + filtered_data = self._fb.filter(data) # Output given as a dictionary with nom_txt as the key output = {}