From c56f572c1026a774bcec768821e64ac31354ceff Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 30 Dec 2017 10:06:47 +0100 Subject: Clear PAPRStats when config gets changed --- src/OfdmGenerator.cpp | 11 +++++++++++ src/OfdmGenerator.h | 2 ++ src/PAPRStats.cpp | 6 ++++++ src/PAPRStats.h | 2 ++ 4 files changed, 21 insertions(+) (limited to 'src') diff --git a/src/OfdmGenerator.cpp b/src/OfdmGenerator.cpp index 1a819ee..b00d66b 100644 --- a/src/OfdmGenerator.cpp +++ b/src/OfdmGenerator.cpp @@ -187,6 +187,14 @@ int OfdmGenerator::process(Buffer* const dataIn, Buffer* dataOut) // For performance reasons, do not calculate MER for every symbol. myMERCalcIndex = (myMERCalcIndex + 1) % myNbSymbols; + // The PAPRStats' clear() is not threadsafe, do not access it + // from the RC functions. + if (myPaprClearRequest.load()) { + myPaprBeforeCFR.clear(); + myPaprAfterCFR.clear(); + myPaprClearRequest.store(false); + } + for (size_t i = 0; i < myNbSymbols; ++i) { myFftIn[0][0] = 0; myFftIn[0][1] = 0; @@ -358,12 +366,15 @@ void OfdmGenerator::set_parameter(const std::string& parameter, if (parameter == "cfr") { ss >> myCfr; + myPaprClearRequest.store(true); } else if (parameter == "clip") { ss >> myCfrClip; + myPaprClearRequest.store(true); } else if (parameter == "errorclip") { ss >> myCfrErrorClip; + myPaprClearRequest.store(true); } else if (parameter == "clip_stats" or parameter == "papr") { throw ParameterError("Parameter '" + parameter + "' is read-only"); diff --git a/src/OfdmGenerator.h b/src/OfdmGenerator.h index 8374cf9..cccccf5 100644 --- a/src/OfdmGenerator.h +++ b/src/OfdmGenerator.h @@ -37,6 +37,7 @@ #include #include #include +#include typedef std::complex complexf; @@ -105,6 +106,7 @@ class OfdmGenerator : public ModCodec, public RemoteControllable // Measure PAPR before and after CFR PAPRStats myPaprBeforeCFR; PAPRStats myPaprAfterCFR; + std::atomic myPaprClearRequest; size_t myMERCalcIndex = 0; std::deque myMERs; diff --git a/src/PAPRStats.cpp b/src/PAPRStats.cpp index 2e8bca9..1a72238 100644 --- a/src/PAPRStats.cpp +++ b/src/PAPRStats.cpp @@ -100,6 +100,12 @@ double PAPRStats::calculate_papr() const return 10.0 * std::log10(peak / rms2); } +void PAPRStats::clear() +{ + m_squared_peaks.clear(); + m_squared_mean.clear(); +} + #if defined(TEST) /* Test python code: import numpy as np diff --git a/src/PAPRStats.h b/src/PAPRStats.h index 92e5231..86ad8b0 100644 --- a/src/PAPRStats.h +++ b/src/PAPRStats.h @@ -66,6 +66,8 @@ class PAPRStats */ double calculate_papr(void) const; + void clear(void); + private: size_t m_num_blocks_to_accumulate; std::deque m_squared_peaks; -- cgit v1.2.3