diff options
author | andreas128 <Andreas> | 2017-09-02 19:18:01 +0200 |
---|---|---|
committer | andreas128 <Andreas> | 2017-09-02 19:18:01 +0200 |
commit | 719238f0adc19fb3de3b4fd2695b6bb30d4c9dd5 (patch) | |
tree | 05fb049f22a526dd3b2c46b99f7546a84f4938a3 | |
parent | 6907d576b69ae065f25584fd4c6635c0c26beab2 (diff) | |
download | dabmod-719238f0adc19fb3de3b4fd2695b6bb30d4c9dd5.tar.gz dabmod-719238f0adc19fb3de3b4fd2695b6bb30d4c9dd5.tar.bz2 dabmod-719238f0adc19fb3de3b4fd2695b6bb30d4c9dd5.zip |
Cleanup logging and plots
-rwxr-xr-x | dpd/main.py | 8 | ||||
-rw-r--r-- | dpd/src/Adapt.py | 2 | ||||
-rw-r--r-- | dpd/src/Dab_Util.py | 10 | ||||
-rw-r--r-- | dpd/src/MER.py | 5 | ||||
-rw-r--r-- | dpd/src/Model.py | 26 | ||||
-rw-r--r-- | dpd/src/phase_align.py | 6 | ||||
-rwxr-xr-x | dpd/src/subsample_align.py | 4 |
7 files changed, 33 insertions, 28 deletions
diff --git a/dpd/main.py b/dpd/main.py index a466344..57bfed6 100755 --- a/dpd/main.py +++ b/dpd/main.py @@ -66,7 +66,7 @@ parser.add_argument('--rxgain', default=30, help='TX Gain', required=False, type=int) -parser.add_argument('--samps', default='20480', +parser.add_argument('--samps', default='81920', help='Number of samples to request from ODR-DabMod', required=False) parser.add_argument('-i', '--iterations', default='1', @@ -96,9 +96,9 @@ meas = Measure.Measure(samplerate, port, num_req) adapt = Adapt.Adapt(port_rc, coef_path) coefs_am, coefs_pm = adapt.get_coefs() if cli_args.load_poly: - model = Model.Model(coefs_am, coefs_pm) + model = Model.Model(coefs_am, coefs_pm, plot=True) else: - model = Model.Model([1, 0, 0, 0, 0], [0, 0, 0, 0, 0]) + model = Model.Model([1, 0, 0, 0, 0], [0, 0, 0, 0, 0], plot=True) adapt.set_txgain(txgain) adapt.set_rxgain(rxgain) adapt.set_coefs(model.coefs_am, model.coefs_pm) @@ -125,7 +125,7 @@ for i in range(num_iter): off = SA.calc_offset(txframe_aligned) tx_mer = MER.calc_mer(txframe_aligned[off:off + c.T_U]) - rx_mer = MER.calc_mer(rxframe_aligned[off:off + c.T_U]) + rx_mer = MER.calc_mer(rxframe_aligned[off:off + c.T_U], debug=True) logging.info("MER with lag in it. {}: TX {}, RX {}". format(i, tx_mer, rx_mer)) except Exception as e: diff --git a/dpd/src/Adapt.py b/dpd/src/Adapt.py index 2fb596f..7b33851 100644 --- a/dpd/src/Adapt.py +++ b/dpd/src/Adapt.py @@ -24,7 +24,7 @@ class Adapt: """ def __init__(self, port, coef_path): - logging.info("Instantiate Adapt object") + logging.debug("Instantiate Adapt object") self.port = port self.coef_path = coef_path self.host = "localhost" diff --git a/dpd/src/Dab_Util.py b/dpd/src/Dab_Util.py index b0b3ce3..8a53004 100644 --- a/dpd/src/Dab_Util.py +++ b/dpd/src/Dab_Util.py @@ -23,7 +23,7 @@ class Dab_Util: """Collection of methods that can be applied to an array complex IQ samples of a DAB signal """ - def __init__(self, sample_rate): + def __init__(self, sample_rate, plot=False): """ :param sample_rate: sample rate [sample/sec] to use for calculations """ @@ -31,6 +31,8 @@ class Dab_Util: self.dab_bandwidth = 1536000 #Bandwidth of a dab signal self.frame_ms = 96 #Duration of a Dab frame + self.plot=plot + def lag(self, sig_orig, sig_rec): """ Find lag between two signals @@ -41,7 +43,7 @@ class Dab_Util: off = sig_rec.shape[0] c = np.abs(signal.correlate(sig_orig, sig_rec)) - if logging.getLogger().getEffectiveLevel() == logging.DEBUG: + if logging.getLogger().getEffectiveLevel() == logging.DEBUG and self.plot: dt = datetime.datetime.now().isoformat() corr_path = (logging_path + "/" + dt + "_tx_rx_corr.pdf") plt.plot(c, label="corr") @@ -95,7 +97,7 @@ class Dab_Util: Returns an aligned version of sig_tx and sig_rx by cropping and subsample alignment """ - if logging.getLogger().getEffectiveLevel() == logging.DEBUG: + if logging.getLogger().getEffectiveLevel() == logging.DEBUG and self.plot: dt = datetime.datetime.now().isoformat() fig_path = logging_path + "/" + dt + "_sync_raw.pdf" @@ -139,7 +141,7 @@ class Dab_Util: sig_tx = sig_tx[:-1] sig_rx = sig_rx[:-1] - if logging.getLogger().getEffectiveLevel() == logging.DEBUG: + if logging.getLogger().getEffectiveLevel() == logging.DEBUG and self.plot: dt = datetime.datetime.now().isoformat() fig_path = logging_path + "/" + dt + "_sync_sample_aligned.pdf" diff --git a/dpd/src/MER.py b/dpd/src/MER.py index 54ef6c6..2075ef5 100644 --- a/dpd/src/MER.py +++ b/dpd/src/MER.py @@ -75,8 +75,9 @@ class MER: spectrum = self._calc_spectrum(tx) - dt = datetime.datetime.now().isoformat() - fig_path = logging_path + "/" + dt + "_MER.pdf" + if debug: + dt = datetime.datetime.now().isoformat() + fig_path = logging_path + "/" + dt + "_MER.pdf" MERs = [] for i, (x, y) in enumerate(self._split_in_carrier( diff --git a/dpd/src/Model.py b/dpd/src/Model.py index 2aa9feb..dc526c5 100644 --- a/dpd/src/Model.py +++ b/dpd/src/Model.py @@ -20,7 +20,7 @@ class Model: """Calculates new coefficients using the measurement and the old coefficients""" - def __init__(self, coefs_am, coefs_pm): + def __init__(self, coefs_am, coefs_pm, plot=False): self.coefs_am = coefs_am self.coefs_history = [coefs_am, ] self.mses = [0, ] @@ -30,6 +30,8 @@ class Model: self.coefs_pm_history = [coefs_pm, ] self.errs_phase = [0, ] + self.plot=plot + def sample_uniformly(self, txframe_aligned, rxframe_aligned, n_bins=4): """This function returns tx and rx samples in a way that the tx amplitudes have an approximate uniform @@ -144,19 +146,19 @@ class Model: rx_range = rx_range[(rx_range_dpd > 0) & (rx_range_dpd < 2)] rx_range_dpd = rx_range_dpd[(rx_range_dpd > 0) & (rx_range_dpd < 2)] - if logging.getLogger().getEffectiveLevel() == logging.DEBUG: - logging.debug("txframe: min %f, max %f, median %f" % - (np.min(np.abs(txframe_aligned)), - np.max(np.abs(txframe_aligned)), - np.median(np.abs(txframe_aligned)) - )) + logging.debug("txframe: min %f, max %f, median %f" % + (np.min(np.abs(txframe_aligned)), + np.max(np.abs(txframe_aligned)), + np.median(np.abs(txframe_aligned)) + )) - logging.debug("rxframe: min %f, max %f, median %f" % - (np.min(np.abs(rx_choice)), - np.max(np.abs(rx_choice)), - np.median(np.abs(rx_choice)) - )) + logging.debug("rxframe: min %f, max %f, median %f" % + (np.min(np.abs(rx_choice)), + np.max(np.abs(rx_choice)), + np.median(np.abs(rx_choice)) + )) + if logging.getLogger().getEffectiveLevel() == logging.DEBUG and self.plot: dt = datetime.datetime.now().isoformat() fig_path = logging_path + "/" + dt + "_Model.pdf" diff --git a/dpd/src/phase_align.py b/dpd/src/phase_align.py index 7045586..f8e38c4 100644 --- a/dpd/src/phase_align.py +++ b/dpd/src/phase_align.py @@ -15,7 +15,7 @@ import sys import matplotlib.pyplot as plt -def phase_align(sig, ref_sig): +def phase_align(sig, ref_sig, plot=False): """Do phase alignment for sig relative to the reference signal ref_sig. @@ -26,7 +26,7 @@ def phase_align(sig, ref_sig): real_diffs = np.cos(angle_diff) imag_diffs = np.sin(angle_diff) - if logging.getLogger().getEffectiveLevel() == logging.DEBUG: + if logging.getLogger().getEffectiveLevel() == logging.DEBUG and plot: dt = datetime.datetime.now().isoformat() fig_path = logging_path + "/" + dt + "_phase_align.pdf" @@ -66,7 +66,7 @@ def phase_align(sig, ref_sig): )) sig = sig * np.exp(1j * -angle) - if logging.getLogger().getEffectiveLevel() == logging.DEBUG: + if logging.getLogger().getEffectiveLevel() == logging.DEBUG and plot: plt.subplot(515) plt.plot(np.angle(ref_sig[:128]), label="ref_sig") plt.plot(np.angle(sig[:128]), label="sig") diff --git a/dpd/src/subsample_align.py b/dpd/src/subsample_align.py index d0f3dba..cc2b975 100755 --- a/dpd/src/subsample_align.py +++ b/dpd/src/subsample_align.py @@ -29,7 +29,7 @@ def gen_omega(length): return omega -def subsample_align(sig, ref_sig): +def subsample_align(sig, ref_sig, plot=False): """Do subsample alignment for sig relative to the reference signal ref_sig. The delay between the two must be less than sample @@ -68,7 +68,7 @@ def subsample_align(sig, ref_sig): if optim_result.success: best_tau = optim_result.x - if 1: + if plot: corr = np.vectorize(correlate_for_delay) ixs = np.linspace(-1, 1, 100) taus = corr(ixs) |