summaryrefslogtreecommitdiffstats
path: root/dpd
diff options
context:
space:
mode:
Diffstat (limited to 'dpd')
-rwxr-xr-xdpd/main.py35
-rw-r--r--dpd/src/Const.py84
2 files changed, 106 insertions, 13 deletions
diff --git a/dpd/main.py b/dpd/main.py
index ddbbfc4..921afb2 100755
--- a/dpd/main.py
+++ b/dpd/main.py
@@ -12,8 +12,6 @@ predistortion module of ODR-DabMod."""
import datetime
import os
-import time
-import sys
import matplotlib
matplotlib.use('GTKAgg')
@@ -46,10 +44,10 @@ import src.ExtractStatistic as ExtractStatistic
import src.Adapt as Adapt
import src.Agc as Agc
import src.TX_Agc as TX_Agc
-import src.Symbol_align
-import src.const
-import src.MER
-import src.Measure_Shoulders
+from src.Symbol_align import Symbol_align
+from src.Const import Const
+from src.MER import MER
+from src.Measure_Shoulders import Measure_Shoulders
import argparse
parser = argparse.ArgumentParser(
@@ -91,6 +89,13 @@ parser.add_argument('-i', '--iterations', default=1, type=int,
parser.add_argument('-L', '--lut',
help='Use lookup table instead of polynomial predistorter',
action="store_true")
+parser.add_argument('--n_bins', default='64', type=int,
+ required=False)
+parser.add_argument('--n_per_bin', default='128', type=int,
+ required=False)
+parser.add_argument('--n_meas', default='20', type=int,
+ help='Number of samples to request from ODR-DabMod',
+ required=False)
cli_args = parser.parse_args()
logging.info(cli_args)
@@ -106,10 +111,14 @@ target_median = cli_args.target_median
rxgain = cli_args.rxgain
txgain = cli_args.txgain
-c = src.const.const(samplerate, target_median)
-SA = src.Symbol_align.Symbol_align(c)
-MER = src.MER.MER(c)
-MS = src.Measure_Shoulders.Measure_Shoulder(c)
+n_bins = cli_args.n_bins
+n_per_bin = cli_args.n_per_bin
+n_meas = cli_args.n_meas
+
+c = Const(samplerate, target_median, n_bins, n_per_bin, n_meas)
+SA = Symbol_align(c)
+MER = MER(c)
+MS = Measure_Shoulders(c)
meas = Measure.Measure(samplerate, port, num_req)
extStat = ExtractStatistic.ExtractStatistic(c)
@@ -181,7 +190,7 @@ while i < num_iter:
tx, rx, phase_diff, n_per_bin = extStat.extract(txframe_aligned, rxframe_aligned)
- if extStat.n_meas >= 100:
+ if extStat.n_meas >= c.n_meas:
state = "model"
else:
state = "measure"
@@ -212,8 +221,8 @@ while i < num_iter:
rx_gain = adapt.get_rxgain()
digital_gain = adapt.get_digital_gain()
tx_median = np.median(np.abs(txframe_aligned))
- rx_shoulder_tuple = MS.average_shoulders(rxframe_aligned)
- tx_shoulder_tuple = MS.average_shoulders(txframe_aligned)
+ rx_shoulder_tuple = MS.average_shoulders(rxframe_aligned) if c.MS_enable else None
+ tx_shoulder_tuple = MS.average_shoulders(txframe_aligned) if c.MS_enable else None
logging.info(list((name, eval(name)) for name in
['i', 'tx_mer', 'tx_shoulder_tuple', 'rx_mer',
diff --git a/dpd/src/Const.py b/dpd/src/Const.py
new file mode 100644
index 0000000..2504c1e
--- /dev/null
+++ b/dpd/src/Const.py
@@ -0,0 +1,84 @@
+# DAB Frame constants
+# Sources:
+# - etsi_EN_300_401_v010401p p145
+# - Measured with USRP B200
+
+import numpy as np
+
+class Const:
+ def __init__(self, sample_rate, target_median, n_bins, n_per_bin, n_meas):
+ self.sample_rate = sample_rate
+ self.n_meas = n_meas
+
+ # Time domain
+ self.T_F = sample_rate / 2048000 * 196608 # Transmission frame duration
+ self.T_NULL = sample_rate / 2048000 * 2656 # Null symbol duration
+ self.T_S = sample_rate / 2048000 * 2552 # Duration of OFDM symbols of indices l = 1, 2, 3,... L;
+ self.T_U = sample_rate / 2048000 * 2048 # Inverse of carrier spacing
+ self.T_C = sample_rate / 2048000 * 504 # Duration of cyclic prefix
+
+ # Frequency Domain
+ # example: np.delete(fft[3328:4865], 768)
+ self.FFT_delete = 768
+ self.FFT_delta = 1536 # Number of carrier frequencies
+ if sample_rate == 2048000:
+ self.FFT_start = 256
+ self.FFT_end = 1793
+ elif sample_rate == 8192000:
+ self.FFT_start = 3328
+ self.FFT_end = 4865
+ else:
+ raise RuntimeError("Sample Rate '{}' not supported".format(
+ sample_rate
+ ))
+
+ # Calculate sample offset from phase rotation
+ # time per sample = 1 / sample_rate
+ # frequency per bin = 1kHz
+ # phase difference per sample offset = delta_t * 2 * pi * delta_freq
+ self.phase_offset_per_sample = 1. / sample_rate * 2 * np.pi * 1000
+
+ # Constants for ExtractStatistic
+ self.ES_plot = False
+ self.ES_start = 0.0
+ self.ES_end = 1.0
+ self.ES_n_bins = n_bins
+ self.ES_n_per_bin = n_per_bin
+
+ # Constants for TX_Agc
+ self.TAGC_max_txgain = 89
+ self.TAGC_tx_median_target = target_median
+ self.TAGC_tx_median_max = self.TAGC_tx_median_target*1.4
+ self.TAGC_tx_median_min = self.TAGC_tx_median_target/1.4
+
+
+ self.RAGC_min_rxgain = 25
+ self.RAGC_rx_median_target = self.TAGC_tx_median_target
+
+ # Constants for Model
+ self.MDL_plot = False
+
+ # Constants for MER
+ self.MER_plot = False
+
+ # Constants for Model_PM
+ self.MPM_tx_min = 0.1
+
+ # Constants for Measure_Shoulder
+ self.MS_enable = False
+ self.MS_plot = False
+ assert sample_rate==8192000
+ meas_offset = 976 # Offset from center frequency to measure shoulder [kHz]
+ meas_width = 100 # Size of frequency delta to measure shoulder [kHz]
+ shoulder_offset_edge = np.abs(meas_offset - self.FFT_delta)
+ self.MS_shoulder_left_start = self.FFT_start - shoulder_offset_edge - meas_width / 2
+ self.MS_shoulder_left_end = self.FFT_start - shoulder_offset_edge + meas_width / 2
+ self.MS_shoulder_right_start = self.FFT_end + shoulder_offset_edge - meas_width / 2
+ self.MS_shoulder_right_end = self.FFT_end + shoulder_offset_edge + meas_width / 2
+ self.MS_peak_start = self.FFT_start + 100 # Ignore region near edges
+ self.MS_peak_end = self.FFT_end - 100
+
+ self.MS_FFT_size = 8192
+ self.MS_averaging_size = 4 * self.MS_FFT_size
+ self.MS_n_averaging = 40
+ self.MS_n_proc = 4