summaryrefslogtreecommitdiffstats
path: root/gui/dpd/Capture.py
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2018-08-06 09:10:42 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2018-08-06 09:10:42 +0200
commit7e91c6a59858325593093c046c213c6bd4e7e4f3 (patch)
tree0a5765a048fd3910caf2fc396d113ef2ef5ea753 /gui/dpd/Capture.py
parent08705c0399240f984cf54294a369cb3a896e089a (diff)
downloaddabmod-7e91c6a59858325593093c046c213c6bd4e7e4f3.tar.gz
dabmod-7e91c6a59858325593093c046c213c6bd4e7e4f3.tar.bz2
dabmod-7e91c6a59858325593093c046c213c6bd4e7e4f3.zip
Some GUI changes
Diffstat (limited to 'gui/dpd/Capture.py')
-rw-r--r--gui/dpd/Capture.py57
1 files changed, 32 insertions, 25 deletions
diff --git a/gui/dpd/Capture.py b/gui/dpd/Capture.py
index d6d0307..31fa78d 100644
--- a/gui/dpd/Capture.py
+++ b/gui/dpd/Capture.py
@@ -77,8 +77,12 @@ class Capture:
self.binning_n_bins = 64 # Number of bins between binning_start and binning_end
self.binning_n_per_bin = 128 # Number of measurements pre bin
+ self.target_median = 0.01
+ self.median_max = self.target_median * 1.4
+ self.median_min = self.target_median / 1.4
+
# axis 1: 0=tx, 1=rx
- self.accumulated_samples = np.zeros((0, 2), dtype=np.complex64)
+ self.accumulated_bins = [np.zeros((0, 2), dtype=np.complex64) for i in range(self.binning_n_bins)]
def _recv_exact(self, sock, num_bytes):
"""Receive an exact number of bytes from a socket. This is
@@ -156,42 +160,45 @@ class Capture:
txframe, tx_ts, rxframe, rx_ts = self.receive_tcp()
# Normalize received signal with sent signal
- rx_median = np.median(np.abs(rxframe))
tx_median = np.median(np.abs(txframe))
- rxframe = rxframe / rx_median * tx_median
- txframe_aligned, rxframe_aligned = align_samples(txframe, rxframe)
+ if self.median_max < tx_median:
+ raise ValueError("Median {} too high, decrease digital_gain!".format(tx_median))
+ elif tx_median < self.median_min:
+ raise ValueError("Median {} too low, increase digital_gain!".format(tx_median))
+ else:
+ rx_median = np.median(np.abs(rxframe))
+ rxframe = rxframe / rx_median * tx_median
+
+ txframe_aligned, rxframe_aligned = align_samples(txframe, rxframe)
- self._bin_and_accumulate(txframe_aligned, rxframe_aligned)
+ self._bin_and_accumulate(txframe_aligned, rxframe_aligned)
- return txframe_aligned, tx_ts, tx_median, rxframe_aligned, rx_ts, rx_median
+ return txframe_aligned, tx_ts, tx_median, rxframe_aligned, rx_ts, rx_median
- def num_accumulated(self):
- return self.accumulated_samples.shape[0]
+ def bin_histogram(self):
+ return [b.shape[0] for b in self.accumulated_bins]
def _bin_and_accumulate(self, txframe, rxframe):
"""Bin the samples and extend the accumulated samples"""
bin_edges = np.linspace(self.binning_start, self.binning_end, self.binning_n_bins)
- binned_sample_pairs = {}
-
minsize = self.num_samples_to_request
for i, (tx_start, tx_end) in enumerate(zip(bin_edges, bin_edges[1:])):
- indices = np.bitwise_and(tx_start < txframe, txframe <= tx_end)
- binned_sample_pairs[i] = (txframe[indices], rxframe[indices])
- len_bin = len(txframe[indices])
-
- #TODO this doesn't work, the min is always 0
- if len_bin < minsize:
- minsize = len_bin
-
- # axis 0: bins, axis 1: sample index, axis 2: tx(0) and rx(1)
- samples = np.zeros((self.binning_n_bins, len_bin, 2), dtype=np.complex64)
-
- for i in binned_sample_pairs:
- tx, rx = binned_sample_pairs[i]
- new_samples = np.array((tx[:minsize], rx[:minsize]), dtype=np.complex64)
- self.accumulated_samples = np.concatenate((self.accumulated_samples, new_samples.T))
+ txframe_abs = np.abs(txframe)
+ indices = np.bitwise_and(tx_start < txframe_abs, txframe_abs <= tx_end)
+ txsamples = np.asmatrix(txframe[indices])
+ rxsamples = np.asmatrix(rxframe[indices])
+ binned_sample_pairs = np.concatenate((txsamples, rxsamples)).T
+
+ missing_in_bin = self.binning_n_per_bin - self.accumulated_bins[i].shape[0]
+ num_to_append = min(missing_in_bin, binned_sample_pairs.shape[0])
+ print("Handling bin {} {}-{}, {} available, {} missing".format(i, tx_start, tx_end, binned_sample_pairs.shape[0], missing_in_bin))
+ if num_to_append:
+ print("Appending {} to bin {} with shape {}".format(num_to_append, i, self.accumulated_bins[i].shape))
+
+ self.accumulated_bins[i] = np.concatenate((self.accumulated_bins[i], binned_sample_pairs[:num_to_append,...]))
+ print("{} now has shape {}".format(i, self.accumulated_bins[i].shape))