aboutsummaryrefslogtreecommitdiffstats
path: root/tests/correlator/correlator.grc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/correlator/correlator.grc')
-rw-r--r--tests/correlator/correlator.grc56
1 files changed, 27 insertions, 29 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\