aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2021-12-05 23:36:10 +0100
committerNao Pross <np@0hm.ch>2021-12-05 23:36:10 +0100
commitf3841a7720eb395b8f6408780e7b540a4d8c4127 (patch)
tree27f0131a1e0e04a1f3bf5b0f9781a3b23e5dbd94 /tests
parentMerge branch 'master' of github.com:NaoPross/Fading (diff)
downloadFading-f3841a7720eb395b8f6408780e7b540a4d8c4127.tar.gz
Fading-f3841a7720eb395b8f6408780e7b540a4d8c4127.zip
Nicer notation in block_phase
Diffstat (limited to '')
-rw-r--r--tests/correlator/correlator.grc56
-rwxr-xr-xtests/correlator/correlator.py10
-rw-r--r--tests/correlator/epy_block_0.py9
3 files changed, 30 insertions, 45 deletions
diff --git a/tests/correlator/correlator.grc b/tests/correlator/correlator.grc
index c34e5a9..ff09a40 100644
--- a/tests/correlator/correlator.grc
+++ b/tests/correlator/correlator.grc
@@ -527,35 +527,33 @@ blocks:
\ - start.offset\n\n # unpack pmt values into start and end phase\n \
\ sphase = pmt.to_python(start.value)\n ephase = pmt.to_python(end.value)\n\
\n # compute frequency offset between start and end\n phasediff\
- \ = ephase - sphase\n\n if phasediff > np.pi:\n phasediff\
- \ -= 2*np.pi\n\n elif phasediff < -np.pi:\n phasediff += 2*np.pi\n\
- \n freq = phasediff / nsamples\n\n # save this one for the last\
- \ block (see variable `end' in self.work)\n self.lastfreq = freq\n\n\
- \ # debugging\n print(f\"Correction for chunk of {nsamples:2d}\
- \ samples is \" \\\n f\"sphase={sphase: .4f} rad and freq={freq*1e3:\
- \ .4f} milli rad / sample\")\n\n # compute chunk values\n return\
- \ sphase * np.ones(nsamples) + freq * np.arange(0, nsamples)\n\n def work(self,\
- \ input_items, output_items):\n counter = self.nitems_written(0)\n\n\
- \ # nicer aliases\n inp = input_items[0]\n out = output_items[0]\n\
- \n # read phase tags\n is_phase = lambda tag: pmt.to_python(tag.key)\
- \ == \"phase_est\"\n tags = list(filter(is_phase, self.get_tags_in_window(0,\
- \ 0, len(inp))))\n\n if not tags:\n print(f\"There were no\
- \ tags in {len(inp)} samples!\")\n out[:] = inp\n return\
- \ len(out)\n\n # debugging\n print(f\"Processing {len(tags)} tags\
- \ = {tags[-1].offset - tags[0].offset} \" \\\n f\"samples out of\
- \ {len(inp)} input samples\")\n\n # compute \"the middle\"\n enough_samples\
- \ = lambda pair: ((pair[1].offset - pair[0].offset) > 0)\n pairs = list(filter(enough_samples,\
- \ zip(tags, tags[1:])))\n chunks = [ self.block_phase(start, end) for\
- \ (start, end) in pairs ]\n middle = np.concatenate(chunks) if chunks\
- \ else []\n\n # compute values at the end, we do not have informations\
- \ about the future\n # but we can use the frequency of the last tag to\
- \ approximate\n nback = len(inp) - (tags[-1].offset - counter)\n \
- \ print(f\"Processing {nback} samples at the back of the buffer\")\n \
- \ end = np.ones(nback) * pmt.to_python(tags[-1].value) \\\n \
- \ + self.lastfreq * np.arange(0, nback)\n\n # compute the \"start\"\
- , using the last tag from the previous call\n nfront = tags[0].offset\
- \ - counter\n print(f\"Processing {nfront} samples at the front of the\
- \ buffer\")\n start = self.block_phase(self.last, tags[0])[-nfront:]\
+ \ = (ephase - sphase) % (2 * np.pi)\n freq = phasediff / nsamples\n\n\
+ \ # save this one for the last block (see variable `end' in self.work)\n\
+ \ self.lastfreq = freq\n\n # debugging\n print(f\"Correction\
+ \ for chunk of {nsamples:2d} samples is \" \\\n f\"sphase={sphase:\
+ \ .4f} rad and freq={freq*1e3: .4f} milli rad / sample\")\n\n # compute\
+ \ chunk values\n return sphase * np.ones(nsamples) + freq * np.arange(0,\
+ \ nsamples)\n\n def work(self, input_items, output_items):\n counter\
+ \ = self.nitems_written(0)\n\n # nicer aliases\n inp = input_items[0]\n\
+ \ out = output_items[0]\n\n # read phase tags\n is_phase\
+ \ = lambda tag: pmt.to_python(tag.key) == \"phase_est\"\n tags = list(filter(is_phase,\
+ \ self.get_tags_in_window(0, 0, len(inp))))\n\n if not tags:\n \
+ \ print(f\"There were no tags in {len(inp)} samples!\")\n out[:]\
+ \ = inp\n return len(out)\n\n # debugging\n print(f\"\
+ Processing {len(tags)} tags = {tags[-1].offset - tags[0].offset} \" \\\n \
+ \ f\"samples out of {len(inp)} input samples\")\n\n # compute\
+ \ \"the middle\"\n enough_samples = lambda pair: ((pair[1].offset - pair[0].offset)\
+ \ > 0)\n pairs = list(filter(enough_samples, zip(tags, tags[1:])))\n\
+ \ chunks = [ self.block_phase(start, end) for (start, end) in pairs ]\n\
+ \ middle = np.concatenate(chunks) if chunks else []\n\n # compute\
+ \ values at the end, we do not have informations about the future\n #\
+ \ but we can use the frequency of the last tag to approximate\n nback\
+ \ = len(inp) - (tags[-1].offset - counter)\n print(f\"Processing {nback}\
+ \ samples at the back of the buffer\")\n end = np.ones(nback) * pmt.to_python(tags[-1].value)\
+ \ \\\n + self.lastfreq * np.arange(0, nback)\n\n # compute\
+ \ the \"start\", using the last tag from the previous call\n nfront =\
+ \ tags[0].offset - counter\n print(f\"Processing {nfront} samples at\
+ \ the front of the buffer\")\n start = self.block_phase(self.last, tags[0])[-nfront:]\
\ \\\n if self.last and nfront else np.zeros(nfront)\n\n \
\ # compute correction\n correction = np.exp(-1j * np.concatenate([start,\
\ middle, end]))\n length = len(correction)\n\n # write outputs\n\
diff --git a/tests/correlator/correlator.py b/tests/correlator/correlator.py
index d9dedb2..fddf8ea 100755
--- a/tests/correlator/correlator.py
+++ b/tests/correlator/correlator.py
@@ -7,7 +7,7 @@
# GNU Radio Python Flow Graph
# Title: Correlator Test
# Author: Naoki Pross
-# GNU Radio version: 3.8.2.0
+# GNU Radio version: 3.8.1.0
from distutils.version import StrictVersion
@@ -37,7 +37,6 @@ from gnuradio import eng_notation
import epy_block_0
import epy_block_1
import numpy as np
-
from gnuradio import qtgui
class correlator(gr.top_block, Qt.QWidget):
@@ -390,7 +389,6 @@ class correlator(gr.top_block, Qt.QWidget):
self.connect((self.epy_block_0, 0), (self.digital_constellation_decoder_cb_0, 0))
self.connect((self.epy_block_0, 0), (self.qtgui_const_sink_x_0_0, 0))
-
def closeEvent(self, event):
self.settings = Qt.QSettings("GNU Radio", "correlator")
self.settings.setValue("geometry", self.saveGeometry())
@@ -471,8 +469,6 @@ class correlator(gr.top_block, Qt.QWidget):
-
-
def main(top_block_cls=correlator, options=None):
if StrictVersion("4.5.0") <= StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
@@ -481,9 +477,7 @@ def main(top_block_cls=correlator, options=None):
qapp = Qt.QApplication(sys.argv)
tb = top_block_cls()
-
tb.start()
-
tb.show()
def sig_handler(sig=None, frame=None):
@@ -499,9 +493,9 @@ def main(top_block_cls=correlator, options=None):
def quitting():
tb.stop()
tb.wait()
-
qapp.aboutToQuit.connect(quitting)
qapp.exec_()
+
if __name__ == '__main__':
main()
diff --git a/tests/correlator/epy_block_0.py b/tests/correlator/epy_block_0.py
index dbdadd1..aa3065a 100644
--- a/tests/correlator/epy_block_0.py
+++ b/tests/correlator/epy_block_0.py
@@ -46,14 +46,7 @@ class blk(gr.sync_block):
ephase = pmt.to_python(end.value)
# compute frequency offset between start and end
- phasediff = ephase - sphase
-
- if phasediff > np.pi:
- phasediff -= 2*np.pi
-
- elif phasediff < -np.pi:
- phasediff += 2*np.pi
-
+ phasediff = (ephase - sphase) % (2 * np.pi)
freq = phasediff / nsamples
# save this one for the last block (see variable `end' in self.work)