aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gui/dpd/Capture.py26
-rw-r--r--gui/dpd/__init__.py4
-rwxr-xr-xgui/run.py10
-rw-r--r--gui/static/dpd/index.txt1
-rw-r--r--gui/static/js/odr-predistortion.js4
-rw-r--r--gui/templates/predistortion.html13
6 files changed, 47 insertions, 11 deletions
diff --git a/gui/dpd/Capture.py b/gui/dpd/Capture.py
index 3b2988b..7d95f90 100644
--- a/gui/dpd/Capture.py
+++ b/gui/dpd/Capture.py
@@ -25,7 +25,7 @@
import socket
import struct
-import os
+import os.path
import logging
import numpy as np
from scipy import signal
@@ -68,11 +68,12 @@ def align_samples(sig_tx, sig_rx):
class Capture:
"""Capture samples from ODR-DabMod"""
- def __init__(self, samplerate, port, num_samples_to_request):
+ def __init__(self, samplerate, port, num_samples_to_request, plot_dir):
self.samplerate = samplerate
self.sizeof_sample = 8 # complex floats
self.port = port
self.num_samples_to_request = num_samples_to_request
+ self.plot_dir = plot_dir
# Before we run the samples through the model, we want to accumulate
# them into bins depending on their amplitude, and keep only n_per_bin
@@ -161,6 +162,19 @@ class Capture:
return txframe, tx_ts, rxframe, rx_ts
+ def _plot_spectrum(self, signal, filename, title):
+ fig = plt.figure()
+ ax = plt.subplot(1, 1, 1)
+
+ fft = np.fft.fftshift(np.fft.fft(signal))
+ fft_db = 20 * np.log10(np.abs(fft))
+
+ ax.plot(fft_db)
+ ax.set_title(title)
+ fig.tight_layout()
+ fig.savefig(os.path.join(self.plot_dir, filename))
+ plt.close(fig)
+
def calibrate(self):
txframe, tx_ts, rxframe, rx_ts = self.receive_tcp()
@@ -172,6 +186,9 @@ class Capture:
rxframe = rxframe * self.rx_normalisation
txframe_aligned, rxframe_aligned, coarse_offset = align_samples(txframe, rxframe)
+ self._plot_spectrum(rxframe[:8192], "rxframe.png", "RX Frame")
+ self._plot_spectrum(txframe[:8192], "txframe.png", "RX Frame")
+
return tx_ts, tx_median, rx_ts, rx_median, np.abs(coarse_offset), correlation_coefficient(txframe_aligned, rxframe_aligned)
def get_samples(self):
@@ -208,12 +225,9 @@ class Capture:
ax.set_xlim(0, 1.1)
ax.legend(loc=4)
fig.tight_layout()
- buf = io.BytesIO()
- fig.savefig(buf)
+ fig.savefig(os.path.join(self.plot_dir, "pointcloud.png"))
plt.close(fig)
- return buf.getvalue()
-
def _bin_and_accumulate(self, txframe, rxframe):
"""Bin the samples and extend the accumulated samples"""
diff --git a/gui/dpd/__init__.py b/gui/dpd/__init__.py
index 2c7649b..9009436 100644
--- a/gui/dpd/__init__.py
+++ b/gui/dpd/__init__.py
@@ -26,7 +26,7 @@ from . import Capture
import numpy as np
class DPD:
- def __init__(self, samplerate=8192000):
+ def __init__(self, plot_dir, samplerate=8192000):
self.samplerate = samplerate
oversample = int(self.samplerate / 2048000)
@@ -40,7 +40,7 @@ class DPD:
port = 50055
samples_to_capture = 81920
- self.capture = Capture.Capture(self.samplerate, port, samples_to_capture)
+ self.capture = Capture.Capture(self.samplerate, port, samples_to_capture, plot_dir)
def status(self):
r = {}
diff --git a/gui/run.py b/gui/run.py
index 7162d70..b83dd14 100755
--- a/gui/run.py
+++ b/gui/run.py
@@ -75,9 +75,9 @@ class Root:
return tmpl.render(tab='predistortion', js=js, is_login=False)
class DPDRunner:
- def __init__(self):
+ def __init__(self, static_dir):
self.web_end, self.dpd_end = Pipe()
- self.dpd = dpd.DPD()
+ self.dpd = dpd.DPD(static_dir)
def __enter__(self):
self.p = Process(target=self._handle_messages)
@@ -134,10 +134,14 @@ if __name__ == '__main__':
staticdir = os.path.realpath(config.config['global']['static_directory'])
- with DPDRunner() as dpd_pipe:
+ with DPDRunner(os.path.join(staticdir, "dpd")) as dpd_pipe:
cherrypy.tree.mount(
Root(cli_args.config, dpd_pipe), config={
'/': { },
+ '/dpd': {
+ 'tools.staticdir.on': True,
+ 'tools.staticdir.dir': os.path.join(staticdir, u"dpd/")
+ },
'/css': {
'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(staticdir, u"css/")
diff --git a/gui/static/dpd/index.txt b/gui/static/dpd/index.txt
new file mode 100644
index 0000000..f8b8874
--- /dev/null
+++ b/gui/static/dpd/index.txt
@@ -0,0 +1 @@
+This folder contains plots generated by the DPDCE
diff --git a/gui/static/js/odr-predistortion.js b/gui/static/js/odr-predistortion.js
index 6c5f4d3..73c3b94 100644
--- a/gui/static/js/odr-predistortion.js
+++ b/gui/static/js/odr-predistortion.js
@@ -33,6 +33,10 @@ function calibraterefresh() {
$(function(){
$('#calibraterefreshbtn').click(calibraterefresh);
+ $('#refreshframesbtn').click(function() {
+ $('#txframeimg').src("dpd/txframe.png");
+ $('#rxframeimg').src("dpd/rxframe.png");
+ });
$('#calibratebtn').click(function() {
doApiRequestPOST("/api/calibrate", {}, function(data) {
diff --git a/gui/templates/predistortion.html b/gui/templates/predistortion.html
index 398b4b7..6d2f738 100644
--- a/gui/templates/predistortion.html
+++ b/gui/templates/predistortion.html
@@ -41,6 +41,19 @@ along with ODR-DabMod. If not, see <http://www.gnu.org/licenses/>.
<div>Calibration results:<span id="calibrationresults">N/A<span></div>
</div>
</div>
+ <div class="panel panel-default">
+ <div class="panel-heading">Capture TX and RX frames</div>
+ <div class="panel-body">
+ <div>
+ <img id="txframeimg" src="dpd/txframe.png" />
+ <img id="rxframeimg" src="dpd/rxframe.png" />
+ </div>
+ <div>
+ <button type="button" class="btn btn-sm btn-info" id="refreshframesbtn">
+ Refresh</button>
+ </div>
+ </div>
+ </div>
<!--
<div class="panel panel-default">