From 15651ab0020ba594bff02491b3d2b6472f5e4fda Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 12 Aug 2017 14:37:45 +0200 Subject: show_spectrum: dump image and try to get upsampled constellation to work --- dpd/show_spectrum.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'dpd') diff --git a/dpd/show_spectrum.py b/dpd/show_spectrum.py index 95dbef9..f23dba2 100755 --- a/dpd/show_spectrum.py +++ b/dpd/show_spectrum.py @@ -169,14 +169,26 @@ def plot_constellation_once(options): num_syms = int(len(frame) / n) print("frame {} has {} symbols".format(len(frame), num_syms)) spectrums = np.array([np.fft.fftshift(np.fft.fft(frame[n*i:n*(i+1)], n)) for i in range(num_syms)]) - #imsave("spectrums.png", np.abs(spectrums)) + + def normalise(x): + """Normalise a real-valued array x to the range [0,1]""" + y = x + np.min(x) + return x / np.max(x) + + imsave("spectrums.png", np.concatenate([ + normalise(np.abs(spectrums)), + normalise(np.angle(spectrums))])) # Only take bins that are supposed to contain energy - #TODO this is only valid for 2048000 sample rate! - spectrums = np.concatenate([spectrums[...,256:1024], spectrums[...,1025:1793]], axis=1) + # i.e. the middle 1536 bins, excluding the bin at n/2 + assert(n % 2 == 0) + n_half = int(n/2) + spectrums = np.concatenate( + [spectrums[...,n_half-768:n_half], + spectrums[...,n_half + 1:n_half + 769]], axis=1) sym_indices = (np.tile(np.arange(num_syms-1).reshape(num_syms-1,1), (1,NbCarriers)) + - np.tile(np.linspace(-0.25, 0.25, NbCarriers), (num_syms-1, 1) ) ) + np.tile(np.linspace(-0.4, 0.4, NbCarriers), (num_syms-1, 1) ) ) sym_indices = sym_indices.reshape(-1) diff_angles = np.mod(np.diff(np.angle(spectrums, deg=1), axis=0), 360) #sym_points = spectrums[:-1].reshape(-1) -- cgit v1.2.3 From a82f72eb04d4b5766f12d94febdf2f989ca7210a Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Thu, 17 Aug 2017 15:25:47 +0200 Subject: Add number of threads setting for MemlessPoly --- dpd/dpd.ini | 4 ++++ src/ConfigParser.cpp | 3 +++ src/ConfigParser.h | 2 +- src/DabMod.cpp | 6 ++++-- src/DabModulator.cpp | 7 +++++-- src/DabModulator.h | 5 ++++- src/MemlessPoly.cpp | 29 ++++++++++++++++++----------- src/MemlessPoly.h | 3 ++- 8 files changed, 41 insertions(+), 18 deletions(-) (limited to 'dpd') diff --git a/dpd/dpd.ini b/dpd/dpd.ini index 08564d9..21d7d45 100644 --- a/dpd/dpd.ini +++ b/dpd/dpd.ini @@ -24,6 +24,10 @@ enabled=1 enabled=1 polycoeffile=dpdpoly.coef +# How many threads to use for the predistorter. +# If not set, detect automatically. +#num_threads=2 + [output] # to prepare a file for the dpd/iq_file_server.py script, # use output=file diff --git a/src/ConfigParser.cpp b/src/ConfigParser.cpp index 459811f..f27eb08 100644 --- a/src/ConfigParser.cpp +++ b/src/ConfigParser.cpp @@ -172,6 +172,9 @@ static void parse_configfile( if (pt.get("poly.enabled", 0) == 1) { mod_settings.polyCoefFilename = pt.get("poly.polycoeffile", "default"); + + mod_settings.polyNumThreads = + pt.get("poly.num_threads", 0); } // Output options diff --git a/src/ConfigParser.h b/src/ConfigParser.h index 22a4fc5..89f0fb7 100644 --- a/src/ConfigParser.h +++ b/src/ConfigParser.h @@ -75,7 +75,7 @@ struct mod_settings_t { std::string filterTapsFilename = ""; std::string polyCoefFilename = ""; - + unsigned polyNumThreads = 0; #if defined(HAVE_OUTPUT_UHD) OutputUHDConfig outputuhd_conf; diff --git a/src/DabMod.cpp b/src/DabMod.cpp index 7c342a2..1f10fb8 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -328,7 +328,8 @@ int launch_modulator(int argc, char* argv[]) mod_settings.normalise, mod_settings.gainmodeVariance, mod_settings.filterTapsFilename, - mod_settings.polyCoefFilename); + mod_settings.polyCoefFilename, + mod_settings.polyNumThreads); if (format_converter) { flowgraph.connect(modulator, format_converter); @@ -433,7 +434,8 @@ int launch_modulator(int argc, char* argv[]) mod_settings.normalise, mod_settings.gainmodeVariance, mod_settings.filterTapsFilename, - mod_settings.polyCoefFilename); + mod_settings.polyCoefFilename, + mod_settings.polyNumThreads); if (format_converter) { flowgraph.connect(modulator, format_converter); diff --git a/src/DabModulator.cpp b/src/DabModulator.cpp index 5282a2d..ccc2085 100644 --- a/src/DabModulator.cpp +++ b/src/DabModulator.cpp @@ -63,7 +63,8 @@ DabModulator::DabModulator( float& digGain, float normalise, float gainmodeVariance, const std::string& filterTapsFilename, - const std::string& polyCoefFilename + const std::string& polyCoefFilename, + unsigned int polyNumThreads ) : ModInput(), myOutputRate(outputRate), @@ -77,6 +78,7 @@ DabModulator::DabModulator( myFlowgraph(NULL), myFilterTapsFilename(filterTapsFilename), myPolyCoefFilename(polyCoefFilename), + myPolyNumThreads(polyNumThreads), myTiiConfig(tiiConfig) { PDEBUG("DabModulator::DabModulator(%u, %u, %u, %zu) @ %p\n", @@ -222,7 +224,8 @@ int DabModulator::process(Buffer* dataOut) shared_ptr cifPoly; if (not myPolyCoefFilename.empty()) { - cifPoly = make_shared(myPolyCoefFilename); + cifPoly = make_shared( + myPolyCoefFilename, myPolyNumThreads); rcs.enrol(cifPoly.get()); } diff --git a/src/DabModulator.h b/src/DabModulator.h index 0c691dd..56a6f91 100644 --- a/src/DabModulator.h +++ b/src/DabModulator.h @@ -56,7 +56,9 @@ public: float& digGain, float normalise, float gainmodeVariance, const std::string& filterTapsFilename, - const std::string& polyCoefFilename); + const std::string& polyCoefFilename, + unsigned int polyNumThreads); + DabModulator(const DabModulator& other) = delete; DabModulator& operator=(const DabModulator& other) = delete; virtual ~DabModulator(); @@ -82,6 +84,7 @@ protected: OutputMemory* myOutput; std::string myFilterTapsFilename; std::string myPolyCoefFilename; + unsigned int myPolyNumThreads; tii_config_t& myTiiConfig; size_t myNbSymbols; diff --git a/src/MemlessPoly.cpp b/src/MemlessPoly.cpp index 71ceac3..b0d950c 100644 --- a/src/MemlessPoly.cpp +++ b/src/MemlessPoly.cpp @@ -53,9 +53,10 @@ static const std::array default_coefficients({{ }}); -MemlessPoly::MemlessPoly(const std::string& coefs_file) : +MemlessPoly::MemlessPoly(const std::string& coefs_file, unsigned int num_threads) : PipelinedModCodec(), RemoteControllable("memlesspoly"), + m_num_threads(num_threads), m_coefs(), m_coefs_file(coefs_file), m_coefs_mutex() @@ -63,6 +64,16 @@ MemlessPoly::MemlessPoly(const std::string& coefs_file) : PDEBUG("MemlessPoly::MemlessPoly(%s) @ %p\n", coefs_file.c_str(), this); + if (m_num_threads == 0) { + const unsigned int hw_concurrency = std::thread::hardware_concurrency(); + etiLog.level(info) << "Polynomial Predistorter will use " << + hw_concurrency << " threads (auto detected)"; + } + else { + etiLog.level(info) << "Polynomial Predistorter will use " << + m_num_threads << " threads (set in config file)"; + } + RC_ADD_PARAMETER(ncoefs, "(Read-only) number of coefficients."); RC_ADD_PARAMETER(coeffile, "Filename containing coefficients. When written to, the new file gets automatically loaded."); @@ -156,12 +167,15 @@ int MemlessPoly::internal_process(Buffer* const dataIn, Buffer* dataOut) std::lock_guard lock(m_coefs_mutex); const unsigned int hw_concurrency = std::thread::hardware_concurrency(); - if (hw_concurrency) { - const size_t step = sizeOut / hw_concurrency; + const unsigned int num_threads = + (m_num_threads > 0) ? m_num_threads : hw_concurrency; + + if (num_threads) { + const size_t step = sizeOut / num_threads; vector > flags; size_t start = 0; - for (size_t i = 0; i < hw_concurrency - 1; i++) { + for (size_t i = 0; i < num_threads - 1; i++) { flags.push_back(async(launch::async, apply_coeff, m_coefs, in, start, start + step, out)); @@ -177,13 +191,6 @@ int MemlessPoly::internal_process(Buffer* const dataIn, Buffer* dataOut) } } else { - static bool error_printed = false; - if (not error_printed) { - etiLog.level(warn) << - "Your platform doesn't seem to have hardware concurrency. " - "MemlessPoly will run single-threaded"; - } - // For some reason we don't have hw concurrency. apply_coeff(m_coefs, in, 0, sizeOut, out); } } diff --git a/src/MemlessPoly.h b/src/MemlessPoly.h index 9fe19d7..b7fd81e 100644 --- a/src/MemlessPoly.h +++ b/src/MemlessPoly.h @@ -52,7 +52,7 @@ typedef std::complex complexf; class MemlessPoly : public PipelinedModCodec, public RemoteControllable { public: - MemlessPoly(const std::string& coefs_file); + MemlessPoly(const std::string& coefs_file, unsigned int num_threads); virtual const char* name() { return "MemlessPoly"; } @@ -67,6 +67,7 @@ private: int internal_process(Buffer* const dataIn, Buffer* dataOut); void load_coefficients(const std::string &coefFile); + unsigned int m_num_threads; std::vector m_coefs; std::string m_coefs_file; mutable std::mutex m_coefs_mutex; -- cgit v1.2.3 From 6a9af4b8ff4f73e01ccb3bd07c0a971ef503c73d Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Thu, 17 Aug 2017 15:35:36 +0200 Subject: Move default poly to dpd/poly.coef --- dpd/dpd.ini | 2 +- dpd/poly.coef | 11 +++++++++++ dpdpoly.coef | 11 ----------- src/ConfigParser.cpp | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 dpd/poly.coef delete mode 100644 dpdpoly.coef (limited to 'dpd') diff --git a/dpd/dpd.ini b/dpd/dpd.ini index 21d7d45..eb221e3 100644 --- a/dpd/dpd.ini +++ b/dpd/dpd.ini @@ -22,7 +22,7 @@ enabled=1 [poly] enabled=1 -polycoeffile=dpdpoly.coef +polycoeffile=dpd/poly.coef # How many threads to use for the predistorter. # If not set, detect automatically. diff --git a/dpd/poly.coef b/dpd/poly.coef new file mode 100644 index 0000000..b29fa26 --- /dev/null +++ b/dpd/poly.coef @@ -0,0 +1,11 @@ +5 +0 +0 +0.8 +0 +0 +0 +0 +0 +0 +0 diff --git a/dpdpoly.coef b/dpdpoly.coef deleted file mode 100644 index b29fa26..0000000 --- a/dpdpoly.coef +++ /dev/null @@ -1,11 +0,0 @@ -5 -0 -0 -0.8 -0 -0 -0 -0 -0 -0 -0 diff --git a/src/ConfigParser.cpp b/src/ConfigParser.cpp index f27eb08..9ac1280 100644 --- a/src/ConfigParser.cpp +++ b/src/ConfigParser.cpp @@ -171,7 +171,7 @@ static void parse_configfile( // Poly coefficients: if (pt.get("poly.enabled", 0) == 1) { mod_settings.polyCoefFilename = - pt.get("poly.polycoeffile", "default"); + pt.get("poly.polycoeffile", "dpd/poly.coef"); mod_settings.polyNumThreads = pt.get("poly.num_threads", 0); -- cgit v1.2.3