From 8e6e1d62ef9beb978879bfd156b3ff51940c8725 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Thu, 2 Dec 2021 12:50:55 +0100 Subject: Implement phase correction in test file with embedded python block --- tests/correlator/correlator.grc | 424 +++++++++++----------------------------- 1 file changed, 110 insertions(+), 314 deletions(-) (limited to 'tests/correlator/correlator.grc') diff --git a/tests/correlator/correlator.grc b/tests/correlator/correlator.grc index 9deec54..aa21770 100644 --- a/tests/correlator/correlator.grc +++ b/tests/correlator/correlator.grc @@ -1,7 +1,6 @@ options: parameters: author: Naoki Pross - catch_exceptions: 'True' category: '[GRC Hier Blocks]' cmake_opt: '' comment: '' @@ -23,6 +22,7 @@ options: sizing_mode: fixed thread_safe_setters: '' title: Correlator Test + window_size: '' states: bus_sink: false bus_source: false @@ -72,7 +72,6 @@ blocks: comment: '' const_points: '[-1-1j, -1+1j, 1+1j, 1-1j]' dims: '1' - normalization: digital.constellation.AMPLITUDE_NORMALIZATION precision: '8' rot_sym: '4' soft_dec_lut: None @@ -184,42 +183,6 @@ blocks: coordinate: [224, 1068.0] rotation: 0 state: enabled -- name: blocks_burst_tagger_0 - id: blocks_burst_tagger - parameters: - affinity: '' - alias: '' - comment: '' - false_key: nothing - false_value: '0' - maxoutbuf: '0' - minoutbuf: '0' - true_key: peak - true_value: 'True' - type: float - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [944, 1580.0] - rotation: 0 - state: disabled -- name: blocks_char_to_short_0 - id: blocks_char_to_short - parameters: - affinity: '' - alias: '' - comment: '' - maxoutbuf: '0' - minoutbuf: '0' - vlen: '1' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [752, 1624.0] - rotation: 0 - state: disabled - name: blocks_complex_to_magphase_0 id: blocks_complex_to_magphase parameters: @@ -235,7 +198,7 @@ blocks: bus_structure: null coordinate: [1048, 696.0] rotation: 0 - state: enabled + state: disabled - name: blocks_complex_to_magphase_0_0 id: blocks_complex_to_magphase parameters: @@ -249,25 +212,9 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1048, 1104.0] + coordinate: [1048, 1128.0] rotation: 0 state: enabled -- name: blocks_complex_to_magphase_0_1 - id: blocks_complex_to_magphase - parameters: - affinity: '' - alias: '' - comment: '' - maxoutbuf: '0' - minoutbuf: '0' - vlen: '1' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [256, 1592.0] - rotation: 0 - state: disabled - name: blocks_multiply_const_vxx_0 id: blocks_multiply_const_vxx parameters: @@ -285,7 +232,7 @@ blocks: bus_structure: null coordinate: [1288, 724.0] rotation: 0 - state: enabled + state: disabled - name: blocks_multiply_const_vxx_0_0 id: blocks_multiply_const_vxx parameters: @@ -301,41 +248,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1336, 1180.0] - rotation: 0 - state: disabled -- name: blocks_null_sink_0 - id: blocks_null_sink - parameters: - affinity: '' - alias: '' - bus_structure_sink: '[[0,],]' - comment: '' - num_inputs: '1' - type: byte - vlen: '1' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [1504, 1696.0] - rotation: 0 - state: disabled -- name: blocks_null_sink_2 - id: blocks_null_sink - parameters: - affinity: '' - alias: '' - bus_structure_sink: '[[0,],]' - comment: '' - num_inputs: '1' - type: float - vlen: '1' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [528, 1720.0] + coordinate: [1336, 1204.0] rotation: 0 state: disabled - name: blocks_null_sink_3 @@ -352,7 +265,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1336, 1232.0] + coordinate: [1336, 1256.0] rotation: 0 state: true - name: blocks_null_source_0 @@ -374,24 +287,6 @@ blocks: coordinate: [96, 344.0] rotation: 0 state: enabled -- name: blocks_peak_detector2_fb_0 - id: blocks_peak_detector2_fb - parameters: - affinity: '' - alias: '' - alpha: '0.001' - comment: '' - look_ahead: '1000' - maxoutbuf: '0' - minoutbuf: '0' - threshold_factor_rise: '7' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [528, 1620.0] - rotation: 0 - state: disabled - name: blocks_stream_mux_0 id: blocks_stream_mux parameters: @@ -449,6 +344,22 @@ blocks: coordinate: [1272, 404.0] rotation: 0 state: enabled +- name: blocks_vector_sink_x_0 + id: blocks_vector_sink_x + parameters: + affinity: '' + alias: '' + comment: '' + reserve_items: '1024' + type: byte + vlen: '1' + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [840, 1392.0] + rotation: 0 + state: true - name: blocks_vector_source_x_0 id: blocks_vector_source_x parameters: @@ -457,7 +368,7 @@ blocks: comment: '' maxoutbuf: '0' minoutbuf: '0' - repeat: 'False' + repeat: 'True' tags: '[]' type: byte vector: testvec * 1600 @@ -497,7 +408,7 @@ blocks: block_tags: 'False' comment: '' epsilon: '1.0' - freq_offset: '0.000001' + freq_offset: '0.00001' maxoutbuf: '0' minoutbuf: '0' noise_voltage: '0.2' @@ -542,9 +453,9 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1232, 1692.0] + coordinate: [248, 1388.0] rotation: 0 - state: disabled + state: enabled - name: digital_constellation_modulator_0 id: digital_constellation_modulator parameters: @@ -558,7 +469,6 @@ blocks: maxoutbuf: '0' minoutbuf: '0' samples_per_symbol: sps - truncate: 'False' verbose: 'False' states: bus_sink: false @@ -610,71 +520,87 @@ blocks: coordinate: [224, 836.0] rotation: 0 state: enabled -- name: fir_filter_xxx_1 - id: fir_filter_xxx +- name: epy_block_0 + id: epy_block parameters: + _source_code: "import pmt\n\nimport numpy as np\nfrom gnuradio import gr\n\n\n\ + class blk(gr.sync_block):\n def __init__(self):\n gr.sync_block.__init__(\n\ + \ self,\n name='Phase Lock',\n in_sig=[np.complex64],\n\ + \ out_sig=[np.complex64]\n )\n\n # keep track of how\ + \ many samples were processed,\n # because tags have an absolute offset\n\ + \ self.sampnr: np.complex64 = 0\n\n # because of block processing\ + \ a tagged block could\n # be split in half so we need to keep track\ + \ of the\n # \"previous\" values\n self.last_phase = 0\n\n \ + \ def work(self, input_items, output_items):\n # TODO: interpolate phase\ + \ values for frequency correction\n\n out = output_items[0]\n \ + \ inp = input_items[0]\n\n # create a phase correction vector\n \ + \ phase = np.zeros(len(inp), dtype=np.float64)\n\n # read tags\n \ + \ tags = self.get_tags_in_window(0, 0, len(inp))\n\n # get only\ + \ phase tags\n is_phase = lambda tag: pmt.to_python(tag.key) == \"phase_est\"\ + \n phase_tags = list(filter(is_phase, tags))\n\n print(f\"Processing\ + \ {len(inp)} samples, with {len(phase_tags)} tags\")\n\n # compute correction\ + \ from previous block\n first_tag = phase_tags[0]\n first_idx\ + \ = first_tag.offset - self.sampnr\n phase[:first_idx] = self.last_phase\n\ + \n # iterate phase tags \"in the middle\"\n for prev_tag, next_tag\ + \ in zip(phase_tags, phase_tags[1:]):\n # unpack pmt values\n \ + \ pval = pmt.to_python(prev_tag.value)\n\n # compute indexes\ + \ in phase vector\n pidx = prev_tag.offset - self.sampnr\n \ + \ idx = next_tag.offset - self.sampnr\n\n # compute phase correction\ + \ for block\n phase[pidx:idx] = pval\n print(f\"Correction\ + \ for block {pidx} to {idx} is {pval}\")\n\n # compute the remaining\ + \ part of the block\n last_tag = phase_tags[-1]\n last_val = pmt.to_python(last_tag.value)\n\ + \ last_idx = last_tag.offset - self.sampnr\n\n phase[last_idx:]\ + \ = last_val\n\n # save values for next call\n self.last_phase\ + \ = last_val\n\n # mark samples as processed and compute to output\n\ + \ self.sampnr += len(inp)\n out[:] = inp * np.exp(-1j * phase)\n\ + \n return len(out)\n" affinity: '' alias: '' comment: '' - decim: '1' maxoutbuf: '0' minoutbuf: '0' - samp_delay: '0' - taps: revconj_access_code_symbols - type: ccc states: + _io_cache: ('Phase Lock', 'blk', [], [('0', 'complex', 1)], [('0', 'complex', + 1)], '', []) bus_sink: false bus_source: false bus_structure: null - coordinate: [776, 828.0] + coordinate: [1088, 1040.0] rotation: 0 state: enabled -- name: high_pass_filter_0 - id: high_pass_filter +- name: fadingui_deframer_0 + id: fadingui_deframer parameters: affinity: '' alias: '' - beta: '6.76' comment: '' - cutoff_freq: 5e3 - decim: '1' - gain: '1' - interp: '1' + frame_obj: '' maxoutbuf: '0' minoutbuf: '0' - samp_rate: samp_rate - type: fir_filter_fff - width: '.7' - win: window.WIN_HAMMING states: bus_sink: false bus_source: false bus_structure: null - coordinate: [528, 1420.0] + coordinate: [552, 1388.0] rotation: 0 - state: disabled -- name: low_pass_filter_0 - id: low_pass_filter + state: true +- name: fir_filter_xxx_1 + id: fir_filter_xxx parameters: affinity: '' alias: '' - beta: '6.76' comment: '' - cutoff_freq: 7e3 decim: '1' - gain: '1' - interp: '1' maxoutbuf: '0' minoutbuf: '0' - samp_rate: samp_rate - type: fir_filter_fff - width: '.8' - win: window.WIN_HAMMING + samp_delay: '0' + taps: revconj_access_code_symbols + type: ccc states: bus_sink: false bus_source: false bus_structure: null - coordinate: [528, 1252.0] + coordinate: [776, 828.0] rotation: 0 state: disabled - name: qtgui_const_sink_x_0 @@ -769,12 +695,12 @@ blocks: coordinate: [776, 716.0] rotation: 0 state: enabled -- name: qtgui_const_sink_x_1 +- name: qtgui_const_sink_x_0_0 id: qtgui_const_sink_x parameters: affinity: '' alias: '' - alpha1: '.5' + alpha1: '1.0' alpha10: '1.0' alpha2: '1.0' alpha3: '1.0' @@ -784,7 +710,7 @@ blocks: alpha7: '1.0' alpha8: '1.0' alpha9: '1.0' - autoscale: 'True' + autoscale: 'False' axislabels: 'True' color1: '"blue"' color10: '"red"' @@ -797,7 +723,7 @@ blocks: color8: '"red"' color9: '"red"' comment: '' - grid: 'True' + grid: 'False' gui_hint: 2,1,2,1 label1: '' label10: '' @@ -810,7 +736,7 @@ blocks: label8: '' label9: '' legend: 'True' - marker1: '9' + marker1: '0' marker10: '0' marker2: '0' marker3: '0' @@ -820,10 +746,10 @@ blocks: marker7: '0' marker8: '0' marker9: '0' - name: '"Cross Correlation"' + name: '"Phase Locked Signal"' nconnections: '1' size: '1024' - style1: '2' + style1: '0' style10: '0' style2: '0' style3: '0' @@ -858,15 +784,15 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1048, 612.0] + coordinate: [1288, 940.0] rotation: 0 state: enabled -- name: qtgui_const_sink_x_2 +- name: qtgui_const_sink_x_1 id: qtgui_const_sink_x parameters: affinity: '' alias: '' - alpha1: '1.0' + alpha1: '.5' alpha10: '1.0' alpha2: '1.0' alpha3: '1.0' @@ -876,7 +802,7 @@ blocks: alpha7: '1.0' alpha8: '1.0' alpha9: '1.0' - autoscale: 'False' + autoscale: 'True' axislabels: 'True' color1: '"blue"' color10: '"red"' @@ -889,8 +815,8 @@ blocks: color8: '"red"' color9: '"red"' comment: '' - grid: 'False' - gui_hint: '2,1,2,1 ' + grid: 'True' + gui_hint: 2,1,2,1 label1: '' label10: '' label2: '' @@ -902,7 +828,7 @@ blocks: label8: '' label9: '' legend: 'True' - marker1: '0' + marker1: '9' marker10: '0' marker2: '0' marker3: '0' @@ -912,10 +838,10 @@ blocks: marker7: '0' marker8: '0' marker9: '0' - name: '"Phase Correction"' + name: '"Cross Correlation"' nconnections: '1' size: '1024' - style1: '0' + style1: '2' style10: '0' style2: '0' style3: '0' @@ -950,7 +876,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1248, 1588.0] + coordinate: [1048, 612.0] rotation: 0 state: disabled - name: qtgui_time_sink_x_0 @@ -1049,7 +975,7 @@ blocks: bus_structure: null coordinate: [1320, 604.0] rotation: 0 - state: enabled + state: disabled - name: qtgui_time_sink_x_0_0 id: qtgui_time_sink_x parameters: @@ -1144,7 +1070,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1336, 1084.0] + coordinate: [1336, 1108.0] rotation: 0 state: enabled - name: qtgui_time_sink_x_0_0_0 @@ -1233,7 +1159,7 @@ blocks: width7: '1' width8: '1' width9: '1' - ylabel: XC Magnitude + ylabel: Equalized ymax: '2' ymin: '-2' yunit: '""' @@ -1241,106 +1167,9 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1048, 1020.0] + coordinate: [1048, 940.0] rotation: 0 state: enabled -- name: qtgui_time_sink_x_1 - id: qtgui_time_sink_x - parameters: - affinity: '' - alias: '' - alpha1: '1.0' - alpha10: '1.0' - alpha2: '1.0' - alpha3: '1.0' - alpha4: '1.0' - alpha5: '1.0' - alpha6: '1.0' - alpha7: '1.0' - alpha8: '1.0' - alpha9: '1.0' - autoscale: 'False' - axislabels: 'True' - color1: blue - color10: dark blue - color2: red - color3: green - color4: black - color5: cyan - color6: magenta - color7: yellow - color8: dark red - color9: dark green - comment: '' - ctrlpanel: 'False' - entags: 'True' - grid: 'False' - gui_hint: '' - label1: Signal 1 - label10: Signal 10 - label2: Signal 2 - label3: Signal 3 - label4: Signal 4 - label5: Signal 5 - label6: Signal 6 - label7: Signal 7 - label8: Signal 8 - label9: Signal 9 - legend: 'True' - marker1: '-1' - marker10: '-1' - marker2: '-1' - marker3: '-1' - marker4: '-1' - marker5: '-1' - marker6: '-1' - marker7: '-1' - marker8: '-1' - marker9: '-1' - name: '""' - nconnections: '1' - size: '1024' - srate: samp_rate - stemplot: 'False' - style1: '1' - style10: '1' - style2: '1' - style3: '1' - style4: '1' - style5: '1' - style6: '1' - style7: '1' - style8: '1' - style9: '1' - tr_chan: '0' - tr_delay: '0' - tr_level: '0.0' - tr_mode: qtgui.TRIG_MODE_FREE - tr_slope: qtgui.TRIG_SLOPE_POS - tr_tag: '""' - type: float - update_time: '0.10' - width1: '1' - width10: '1' - width2: '1' - width3: '1' - width4: '1' - width5: '1' - width6: '1' - width7: '1' - width8: '1' - width9: '1' - ylabel: Amplitude - ymax: '20' - ymin: '-5' - yunit: '""' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [784, 1452.0] - rotation: 0 - state: disabled - name: qtgui_time_sink_x_1_0 id: qtgui_time_sink_x parameters: @@ -1534,7 +1363,7 @@ blocks: bus_structure: null coordinate: [776, 612.0] rotation: 0 - state: enabled + state: disabled - name: qtgui_time_sink_x_2 id: qtgui_time_sink_x parameters: @@ -1631,7 +1460,7 @@ blocks: bus_structure: null coordinate: [1480, 708.0] rotation: 0 - state: enabled + state: disabled - name: qtgui_time_sink_x_2_0 id: qtgui_time_sink_x parameters: @@ -1726,7 +1555,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1512, 1164.0] + coordinate: [1512, 1188.0] rotation: 0 state: disabled - name: root_raised_cosine_filter_0 @@ -1765,30 +1594,17 @@ blocks: coordinate: [1480, 404.0] rotation: 0 state: enabled -- name: virtual_sink_1 +- name: virtual_sink_3 id: virtual_sink parameters: alias: '' comment: '' - stream_id: symbols + stream_id: locked states: bus_sink: false bus_source: false bus_structure: null - coordinate: [776, 916.0] - rotation: 0 - state: true -- name: virtual_sink_2 - id: virtual_sink - parameters: - alias: '' - comment: '' - stream_id: xcorrelation - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [1080, 836.0] + coordinate: [1336, 1036.0] rotation: 0 state: true - name: virtual_source_0 @@ -1804,49 +1620,29 @@ blocks: coordinate: [32, 884.0] rotation: 0 state: enabled -- name: virtual_source_2 - id: virtual_source - parameters: - alias: '' - comment: '' - stream_id: symbols - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [32, 1716.0] - rotation: 0 - state: disabled -- name: virtual_source_3 +- name: virtual_source_1 id: virtual_source parameters: alias: '' comment: '' - stream_id: xcorrelation + stream_id: locked states: bus_sink: false bus_source: false bus_structure: null - coordinate: [32, 1604.0] + coordinate: [24, 1388.0] rotation: 0 - state: disabled + state: true connections: -- [blocks_char_to_short_0, '0', blocks_burst_tagger_0, '1'] - [blocks_complex_to_magphase_0, '0', qtgui_time_sink_x_0, '0'] - [blocks_complex_to_magphase_0, '1', blocks_multiply_const_vxx_0, '0'] - [blocks_complex_to_magphase_0_0, '0', qtgui_time_sink_x_0_0, '0'] - [blocks_complex_to_magphase_0_0, '1', blocks_multiply_const_vxx_0_0, '0'] - [blocks_complex_to_magphase_0_0, '1', blocks_null_sink_3, '0'] -- [blocks_complex_to_magphase_0_1, '0', blocks_burst_tagger_0, '0'] -- [blocks_complex_to_magphase_0_1, '0', blocks_peak_detector2_fb_0, '0'] -- [blocks_complex_to_magphase_0_1, '0', high_pass_filter_0, '0'] -- [blocks_complex_to_magphase_0_1, '0', low_pass_filter_0, '0'] -- [blocks_complex_to_magphase_0_1, '1', blocks_null_sink_2, '0'] - [blocks_multiply_const_vxx_0, '0', qtgui_time_sink_x_2, '0'] - [blocks_multiply_const_vxx_0_0, '0', qtgui_time_sink_x_2_0, '0'] - [blocks_null_source_0, '0', blocks_stream_mux_0, '0'] -- [blocks_peak_detector2_fb_0, '0', blocks_char_to_short_0, '0'] - [blocks_stream_mux_0, '0', digital_constellation_modulator_0, '0'] - [blocks_stream_mux_1, '0', channels_channel_model_0, '0'] - [blocks_throttle_0, '0', virtual_sink_0, '0'] @@ -1857,22 +1653,22 @@ connections: - [digital_cma_equalizer_cc_0, '0', fir_filter_xxx_1, '0'] - [digital_cma_equalizer_cc_0, '0', qtgui_const_sink_x_0, '0'] - [digital_cma_equalizer_cc_0, '0', qtgui_time_sink_x_1_1, '0'] -- [digital_cma_equalizer_cc_0, '0', virtual_sink_1, '0'] -- [digital_constellation_decoder_cb_0, '0', blocks_null_sink_0, '0'] +- [digital_constellation_decoder_cb_0, '0', fadingui_deframer_0, '0'] - [digital_constellation_modulator_0, '0', blocks_stream_mux_1, '1'] - [digital_constellation_modulator_0, '0', channels_channel_model_0, '0'] - [digital_constellation_modulator_0, '0', qtgui_time_sink_x_1_0, '0'] +- [digital_corr_est_cc_0, '0', epy_block_0, '0'] - [digital_corr_est_cc_0, '0', qtgui_time_sink_x_0_0_0, '0'] - [digital_corr_est_cc_0, '1', blocks_complex_to_magphase_0_0, '0'] - [digital_pfb_clock_sync_xxx_0, '0', digital_cma_equalizer_cc_0, '0'] +- [epy_block_0, '0', qtgui_const_sink_x_0_0, '0'] +- [epy_block_0, '0', virtual_sink_3, '0'] +- [fadingui_deframer_0, '0', blocks_vector_sink_x_0, '0'] - [fir_filter_xxx_1, '0', blocks_complex_to_magphase_0, '0'] - [fir_filter_xxx_1, '0', qtgui_const_sink_x_1, '0'] -- [fir_filter_xxx_1, '0', virtual_sink_2, '0'] -- [high_pass_filter_0, '0', qtgui_time_sink_x_1, '0'] -- [low_pass_filter_0, '0', qtgui_time_sink_x_1, '0'] - [root_raised_cosine_filter_0, '0', blocks_stream_mux_1, '0'] - [virtual_source_0, '0', digital_pfb_clock_sync_xxx_0, '0'] -- [virtual_source_3, '0', blocks_complex_to_magphase_0_1, '0'] +- [virtual_source_1, '0', digital_constellation_decoder_cb_0, '0'] metadata: file_format: 1 -- cgit v1.2.1 From de7b4dac4af5ff592258f48eee72d191201826d7 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Thu, 2 Dec 2021 21:24:33 +0100 Subject: Begin frequency correction (incomplete) --- tests/correlator/correlator.grc | 65 +++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 25 deletions(-) (limited to 'tests/correlator/correlator.grc') diff --git a/tests/correlator/correlator.grc b/tests/correlator/correlator.grc index aa21770..58cf3b4 100644 --- a/tests/correlator/correlator.grc +++ b/tests/correlator/correlator.grc @@ -408,7 +408,7 @@ blocks: block_tags: 'False' comment: '' epsilon: '1.0' - freq_offset: '0.00001' + freq_offset: '0.0001' maxoutbuf: '0' minoutbuf: '0' noise_voltage: '0.2' @@ -530,30 +530,45 @@ blocks: \ many samples were processed,\n # because tags have an absolute offset\n\ \ self.sampnr: np.complex64 = 0\n\n # because of block processing\ \ a tagged block could\n # be split in half so we need to keep track\ - \ of the\n # \"previous\" values\n self.last_phase = 0\n\n \ - \ def work(self, input_items, output_items):\n # TODO: interpolate phase\ - \ values for frequency correction\n\n out = output_items[0]\n \ - \ inp = input_items[0]\n\n # create a phase correction vector\n \ - \ phase = np.zeros(len(inp), dtype=np.float64)\n\n # read tags\n \ - \ tags = self.get_tags_in_window(0, 0, len(inp))\n\n # get only\ - \ phase tags\n is_phase = lambda tag: pmt.to_python(tag.key) == \"phase_est\"\ - \n phase_tags = list(filter(is_phase, tags))\n\n print(f\"Processing\ - \ {len(inp)} samples, with {len(phase_tags)} tags\")\n\n # compute correction\ - \ from previous block\n first_tag = phase_tags[0]\n first_idx\ - \ = first_tag.offset - self.sampnr\n phase[:first_idx] = self.last_phase\n\ - \n # iterate phase tags \"in the middle\"\n for prev_tag, next_tag\ - \ in zip(phase_tags, phase_tags[1:]):\n # unpack pmt values\n \ - \ pval = pmt.to_python(prev_tag.value)\n\n # compute indexes\ + \ of the\n # \"previous\" values\n self.last_tag = None\n\n \ + \ def work(self, input_items, output_items):\n # nicer aliases\n \ + \ out = output_items[0]\n inp = input_items[0]\n\n def print_phase_correction(start,\ + \ end, phase, freq):\n print(f\"Correction for block {start:3d} to\ + \ {end:3d} is phase = {phase: 2.4f} rad, freq = {freq * 1e3: 2.4f} milli rad/samp\"\ + )\n\n # read only phase tags\n tags = self.get_tags_in_window(0,\ + \ 0, len(inp))\n\n is_phase = lambda tag: pmt.to_python(tag.key) == \"\ + phase_est\"\n phase_tags = list(filter(is_phase, tags))\n\n #\ + \ FIXME: what if there are no tags? check that!\n\n print(f\"Processing\ + \ {len(inp)} samples, with {len(phase_tags)} tags\")\n\n # create a phase\ + \ correction vector\n phase = np.zeros(len(inp), dtype=np.float64)\n\n\ + \ # compute correction from previous block (if present)\n if self.last_tag:\n\ + \ # variables for first and last phase values\n lval =\ + \ pmt.to_python(self.last_tag.value)\n fval = pmt.to_python(phase_tags[0].value)\n\ + \n # compute index for phase vector\n fidx = phase_tags[0].offset\ + \ - self.sampnr\n\n # compute frequency offset\n nsamples\ + \ = phase_tags[0].offset - self.last_tag.offset\n freq = (fval -\ + \ lval) / nsamples\n\n # total phase correction is: phase + freq\ + \ * time\n phase[:fidx] = lval * np.ones(fidx) + freq * np.arange(0,\ + \ fidx)\n\n # compute correction\n print_phase_correction(0,\ + \ fidx, lval, freq)\n\n # iterate phase tags \"in the middle\"\n \ + \ # FIXME: what if there are less than 2 tags?\n # the code\ + \ below will probably crash\n for prev_tag, next_tag in zip(phase_tags,\ + \ phase_tags[1:]):\n # unpack pmt values\n pval = pmt.to_python(prev_tag.value)\n\ + \ nval = pmt.to_python(next_tag.value)\n\n # compute indexes\ \ in phase vector\n pidx = prev_tag.offset - self.sampnr\n \ - \ idx = next_tag.offset - self.sampnr\n\n # compute phase correction\ - \ for block\n phase[pidx:idx] = pval\n print(f\"Correction\ - \ for block {pidx} to {idx} is {pval}\")\n\n # compute the remaining\ - \ part of the block\n last_tag = phase_tags[-1]\n last_val = pmt.to_python(last_tag.value)\n\ - \ last_idx = last_tag.offset - self.sampnr\n\n phase[last_idx:]\ - \ = last_val\n\n # save values for next call\n self.last_phase\ - \ = last_val\n\n # mark samples as processed and compute to output\n\ - \ self.sampnr += len(inp)\n out[:] = inp * np.exp(-1j * phase)\n\ - \n return len(out)\n" + \ nidx = next_tag.offset - self.sampnr\n\n # compute frquency\ + \ correction for block by linearly interpolating\n # frame values\n\ + \ nsamples = nidx - pidx\n freq = (nval - pval) / nsamples\n\ + \n # total correction is: phase + freq * time\n phase[pidx:nidx]\ + \ = pval * np.ones(nsamples) + freq * np.arange(0, nsamples)\n print_phase_correction(pidx,\ + \ nidx, pval, freq)\n\n # for the last block because the next tag is\ + \ unknown (in the future) we\n # cannot predict the frequency offset.\ + \ Thus we save the last tag for\n # the next call.\n self.last_tag\ + \ = phase_tags[-1]\n val = pmt.to_python(self.last_tag.value)\n \ + \ idx = self.last_tag.offset - self.sampnr\n\n phase[idx:] = val\n\n\ + \ # compute correction\n out[:] = inp * np.exp(-1j * phase)\n\n\ + \ # increment processed samples counter\n self.sampnr += len(inp)\n\ + \ return len(phase)\n" affinity: '' alias: '' comment: '' @@ -583,7 +598,7 @@ blocks: bus_structure: null coordinate: [552, 1388.0] rotation: 0 - state: true + state: bypassed - name: fir_filter_xxx_1 id: fir_filter_xxx parameters: -- cgit v1.2.1 From 6d56e1b35b061ffe4f677d0d6e7867f366068e82 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Thu, 2 Dec 2021 21:27:17 +0100 Subject: Remove custom blocks from correlator test --- tests/correlator/correlator.grc | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'tests/correlator/correlator.grc') diff --git a/tests/correlator/correlator.grc b/tests/correlator/correlator.grc index 58cf3b4..f54430c 100644 --- a/tests/correlator/correlator.grc +++ b/tests/correlator/correlator.grc @@ -357,7 +357,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [840, 1392.0] + coordinate: [536, 1392.0] rotation: 0 state: true - name: blocks_vector_source_x_0 @@ -583,22 +583,6 @@ blocks: coordinate: [1088, 1040.0] rotation: 0 state: enabled -- name: fadingui_deframer_0 - id: fadingui_deframer - parameters: - affinity: '' - alias: '' - comment: '' - frame_obj: '' - maxoutbuf: '0' - minoutbuf: '0' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [552, 1388.0] - rotation: 0 - state: bypassed - name: fir_filter_xxx_1 id: fir_filter_xxx parameters: @@ -1668,7 +1652,7 @@ connections: - [digital_cma_equalizer_cc_0, '0', fir_filter_xxx_1, '0'] - [digital_cma_equalizer_cc_0, '0', qtgui_const_sink_x_0, '0'] - [digital_cma_equalizer_cc_0, '0', qtgui_time_sink_x_1_1, '0'] -- [digital_constellation_decoder_cb_0, '0', fadingui_deframer_0, '0'] +- [digital_constellation_decoder_cb_0, '0', blocks_vector_sink_x_0, '0'] - [digital_constellation_modulator_0, '0', blocks_stream_mux_1, '1'] - [digital_constellation_modulator_0, '0', channels_channel_model_0, '0'] - [digital_constellation_modulator_0, '0', qtgui_time_sink_x_1_0, '0'] @@ -1678,7 +1662,6 @@ connections: - [digital_pfb_clock_sync_xxx_0, '0', digital_cma_equalizer_cc_0, '0'] - [epy_block_0, '0', qtgui_const_sink_x_0_0, '0'] - [epy_block_0, '0', virtual_sink_3, '0'] -- [fadingui_deframer_0, '0', blocks_vector_sink_x_0, '0'] - [fir_filter_xxx_1, '0', blocks_complex_to_magphase_0, '0'] - [fir_filter_xxx_1, '0', qtgui_const_sink_x_1, '0'] - [root_raised_cosine_filter_0, '0', blocks_stream_mux_1, '0'] -- cgit v1.2.1 From 3718e92fe6418e33a7e8d53192383d021d20c524 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 3 Dec 2021 00:18:55 +0100 Subject: Refractor frequency correction --- tests/correlator/correlator.grc | 82 ++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 43 deletions(-) (limited to 'tests/correlator/correlator.grc') diff --git a/tests/correlator/correlator.grc b/tests/correlator/correlator.grc index f54430c..57c1762 100644 --- a/tests/correlator/correlator.grc +++ b/tests/correlator/correlator.grc @@ -526,49 +526,45 @@ blocks: _source_code: "import pmt\n\nimport numpy as np\nfrom gnuradio import gr\n\n\n\ class blk(gr.sync_block):\n def __init__(self):\n gr.sync_block.__init__(\n\ \ self,\n name='Phase Lock',\n in_sig=[np.complex64],\n\ - \ out_sig=[np.complex64]\n )\n\n # keep track of how\ - \ many samples were processed,\n # because tags have an absolute offset\n\ - \ self.sampnr: np.complex64 = 0\n\n # because of block processing\ - \ a tagged block could\n # be split in half so we need to keep track\ - \ of the\n # \"previous\" values\n self.last_tag = None\n\n \ - \ def work(self, input_items, output_items):\n # nicer aliases\n \ - \ out = output_items[0]\n inp = input_items[0]\n\n def print_phase_correction(start,\ - \ end, phase, freq):\n print(f\"Correction for block {start:3d} to\ - \ {end:3d} is phase = {phase: 2.4f} rad, freq = {freq * 1e3: 2.4f} milli rad/samp\"\ - )\n\n # read only phase tags\n tags = self.get_tags_in_window(0,\ - \ 0, len(inp))\n\n is_phase = lambda tag: pmt.to_python(tag.key) == \"\ - phase_est\"\n phase_tags = list(filter(is_phase, tags))\n\n #\ - \ FIXME: what if there are no tags? check that!\n\n print(f\"Processing\ - \ {len(inp)} samples, with {len(phase_tags)} tags\")\n\n # create a phase\ - \ correction vector\n phase = np.zeros(len(inp), dtype=np.float64)\n\n\ - \ # compute correction from previous block (if present)\n if self.last_tag:\n\ - \ # variables for first and last phase values\n lval =\ - \ pmt.to_python(self.last_tag.value)\n fval = pmt.to_python(phase_tags[0].value)\n\ - \n # compute index for phase vector\n fidx = phase_tags[0].offset\ - \ - self.sampnr\n\n # compute frequency offset\n nsamples\ - \ = phase_tags[0].offset - self.last_tag.offset\n freq = (fval -\ - \ lval) / nsamples\n\n # total phase correction is: phase + freq\ - \ * time\n phase[:fidx] = lval * np.ones(fidx) + freq * np.arange(0,\ - \ fidx)\n\n # compute correction\n print_phase_correction(0,\ - \ fidx, lval, freq)\n\n # iterate phase tags \"in the middle\"\n \ - \ # FIXME: what if there are less than 2 tags?\n # the code\ - \ below will probably crash\n for prev_tag, next_tag in zip(phase_tags,\ - \ phase_tags[1:]):\n # unpack pmt values\n pval = pmt.to_python(prev_tag.value)\n\ - \ nval = pmt.to_python(next_tag.value)\n\n # compute indexes\ - \ in phase vector\n pidx = prev_tag.offset - self.sampnr\n \ - \ nidx = next_tag.offset - self.sampnr\n\n # compute frquency\ - \ correction for block by linearly interpolating\n # frame values\n\ - \ nsamples = nidx - pidx\n freq = (nval - pval) / nsamples\n\ - \n # total correction is: phase + freq * time\n phase[pidx:nidx]\ - \ = pval * np.ones(nsamples) + freq * np.arange(0, nsamples)\n print_phase_correction(pidx,\ - \ nidx, pval, freq)\n\n # for the last block because the next tag is\ - \ unknown (in the future) we\n # cannot predict the frequency offset.\ - \ Thus we save the last tag for\n # the next call.\n self.last_tag\ - \ = phase_tags[-1]\n val = pmt.to_python(self.last_tag.value)\n \ - \ idx = self.last_tag.offset - self.sampnr\n\n phase[idx:] = val\n\n\ - \ # compute correction\n out[:] = inp * np.exp(-1j * phase)\n\n\ - \ # increment processed samples counter\n self.sampnr += len(inp)\n\ - \ return len(phase)\n" + \ out_sig=[np.complex64]\n )\n\n # we need to keep\ + \ track of the aboslute number of samples that have\n # been processed,\ + \ because tags have an absolute offset\n self.counter: np.uint64 = 0\n\ + \n # because we do block processing, we need to keep track of the last\ + \ tag\n # of the previous block to correct the first values of the next\ + \ block\n self.last = None\n\n def block_phase(self, start, end):\n\ + \ # compute number of samples in block\n nsamples = end.offset\ + \ - 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 freq = (sphase\ + \ - ephase) / nsamples\n\n # debugging\n print(f\"Correction for\ + \ block of {nsamples:2d} samples is \" \\\n f\"phase={sphase: .4f}\ + \ rad and freq={freq*1e3: .4f} milli rad / sample\")\n\n # compute block\ + \ values\n return sphase * np.ones(nsamples) + freq * np.arange(0, nsamples)\n\ + \n def work(self, input_items, output_items):\n # FIXME: replace class\ + \ counter with local variable\n # self.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 # 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 \ + \ blocks = [ self.block_phase(start, end) for (start, end) in pairs ]\n \ + \ middle = np.concatenate(blocks) if blocks else []\n\n # compute\ + \ the remainder from the previous call\n nfront = tags[0].offset - self.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 else np.zeros(nfront)\n\n # compute values at\ + \ the end\n nback = len(inp) - (tags[-1].offset - self.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\n # compute\ + \ correction\n correction = np.exp(-1j * np.concatenate([start, middle,\ + \ end]))\n length = len(correction)\n\n # write outputs\n \ + \ out[:length] = inp[:length] * correction\n self.counter += len(inp)\n\ + \n # save last tag for next call\n self.last = tags[-1]\n\n \ + \ # FIXME: should return `length' but then the last sample is not\n \ + \ # included and self.last does something weird\n return len(out)\n" affinity: '' alias: '' comment: '' -- cgit v1.2.1 From 5d2f01fe71b736f2f5bb8a57bb2f4cd383290e9f Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 3 Dec 2021 00:29:03 +0100 Subject: Fix bug when tag is aligned with inp block --- tests/correlator/correlator.grc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests/correlator/correlator.grc') diff --git a/tests/correlator/correlator.grc b/tests/correlator/correlator.grc index 57c1762..5a73092 100644 --- a/tests/correlator/correlator.grc +++ b/tests/correlator/correlator.grc @@ -408,7 +408,7 @@ blocks: block_tags: 'False' comment: '' epsilon: '1.0' - freq_offset: '0.0001' + freq_offset: '0.0002' maxoutbuf: '0' minoutbuf: '0' noise_voltage: '0.2' @@ -541,7 +541,7 @@ blocks: \ rad and freq={freq*1e3: .4f} milli rad / sample\")\n\n # compute block\ \ values\n return sphase * np.ones(nsamples) + freq * np.arange(0, nsamples)\n\ \n def work(self, input_items, output_items):\n # FIXME: replace class\ - \ counter with local variable\n # self.counter = self.nitems_written(0)\n\ + \ counter with local variable\n self.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,\ @@ -555,10 +555,10 @@ blocks: \ the remainder from the previous call\n nfront = tags[0].offset - self.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 else np.zeros(nfront)\n\n # compute values at\ - \ the end\n nback = len(inp) - (tags[-1].offset - self.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\n # compute\ + \ if self.last and nfront else np.zeros(nfront)\n\n # compute\ + \ values at the end\n nback = len(inp) - (tags[-1].offset - self.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\n # compute\ \ correction\n correction = np.exp(-1j * np.concatenate([start, middle,\ \ end]))\n length = len(correction)\n\n # write outputs\n \ \ out[:length] = inp[:length] * correction\n self.counter += len(inp)\n\ -- cgit v1.2.1 From edf08d1815772fc985a89c976a190b3fcd6fb087 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 3 Dec 2021 00:45:23 +0100 Subject: Add a LPF on the frequency --- tests/correlator/correlator.grc | 52 ++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'tests/correlator/correlator.grc') diff --git a/tests/correlator/correlator.grc b/tests/correlator/correlator.grc index 5a73092..bf44544 100644 --- a/tests/correlator/correlator.grc +++ b/tests/correlator/correlator.grc @@ -163,7 +163,7 @@ blocks: id: variable parameters: comment: '' - value: '[31, 53] + [0x12, 0xe3, 0x9b, 0xee, 0x84, 0x23, 0x41, 0xf3]' + value: '[31, 53] + [0x12, 0xe3, 0x9b, 0xee, 0x84, 0x23, 0x41, 0xf3] * 2' states: bus_sink: false bus_source: false @@ -531,17 +531,23 @@ blocks: \ because tags have an absolute offset\n self.counter: np.uint64 = 0\n\ \n # because we do block processing, we need to keep track of the last\ \ tag\n # of the previous block to correct the first values of the next\ - \ block\n self.last = None\n\n def block_phase(self, start, end):\n\ - \ # compute number of samples in block\n nsamples = end.offset\ - \ - 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 freq = (sphase\ - \ - ephase) / nsamples\n\n # debugging\n print(f\"Correction for\ - \ block of {nsamples:2d} samples is \" \\\n f\"phase={sphase: .4f}\ - \ rad and freq={freq*1e3: .4f} milli rad / sample\")\n\n # compute block\ - \ values\n return sphase * np.ones(nsamples) + freq * np.arange(0, nsamples)\n\ - \n def work(self, input_items, output_items):\n # FIXME: replace class\ - \ counter with local variable\n self.counter = self.nitems_written(0)\n\ + \ block\n self.last = None\n\n # to compute the values that are\ + \ at the end we need to know the frequency\n # of the last block\n \ + \ self.freq = 1\n\n def block_phase(self, start, end):\n # compute\ + \ number of samples in block\n nsamples = end.offset - 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 freq = (sphase - ephase) / nsamples\n\n \ + \ # save this frequency values to compute the end block, unless frequency\n\ + \ # has changed too fast, in that case replace the current values with\n\ + \ # the previous one . This is effectively like a low pass filter.\n\ + \ if abs(freq / self.freq) > 4:\n freq = self.freq\n \ + \ else:\n self.freq = freq\n\n\n # debugging\n print(f\"\ + Correction for block of {nsamples:2d} samples is \" \\\n f\"phase={sphase:\ + \ .4f} rad and freq={freq*1e3: .4f} milli rad / sample\")\n\n # compute\ + \ block values\n return sphase * np.ones(nsamples) + freq * np.arange(0,\ + \ nsamples)\n\n def work(self, input_items, output_items):\n # FIXME:\ + \ replace class counter with local variable\n self.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,\ @@ -552,16 +558,18 @@ blocks: \ pairs = list(filter(enough_samples, zip(tags, tags[1:])))\n \ \ blocks = [ self.block_phase(start, end) for (start, end) in pairs ]\n \ \ middle = np.concatenate(blocks) if blocks else []\n\n # compute\ - \ the remainder from the previous call\n nfront = tags[0].offset - self.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\ - \ values at the end\n nback = len(inp) - (tags[-1].offset - self.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\n # compute\ - \ correction\n correction = np.exp(-1j * np.concatenate([start, middle,\ - \ end]))\n length = len(correction)\n\n # write outputs\n \ - \ out[:length] = inp[:length] * correction\n self.counter += len(inp)\n\ + \ values at the end, we do not have informations about the future\n #\ + \ but we can use the frequency of the last block to approximate\n nback\ + \ = len(inp) - (tags[-1].offset - self.counter)\n print(f\"Processing\ + \ {nback} samples at the back of the buffer\")\n end = np.ones(nback)\ + \ * pmt.to_python(tags[-1].value) + self.freq * np.arange(0, nback)\n\n \ + \ # compute the \"start\", using the last tag from the previous call\n \ + \ nfront = tags[0].offset - self.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\ + \ out[:length] = inp[:length] * correction\n self.counter += len(inp)\n\ \n # save last tag for next call\n self.last = tags[-1]\n\n \ \ # FIXME: should return `length' but then the last sample is not\n \ \ # included and self.last does something weird\n return len(out)\n" -- cgit v1.2.1 From b389c8d00064d224a534d3c4a37bd4ee700a5022 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 3 Dec 2021 13:01:42 +0100 Subject: Improve frequency LPF --- tests/correlator/correlator.grc | 100 +++++++++++++++++++++++++--------------- 1 file changed, 62 insertions(+), 38 deletions(-) (limited to 'tests/correlator/correlator.grc') diff --git a/tests/correlator/correlator.grc b/tests/correlator/correlator.grc index bf44544..220eaed 100644 --- a/tests/correlator/correlator.grc +++ b/tests/correlator/correlator.grc @@ -163,7 +163,7 @@ blocks: id: variable parameters: comment: '' - value: '[31, 53] + [0x12, 0xe3, 0x9b, 0xee, 0x84, 0x23, 0x41, 0xf3] * 2' + value: '[31, 53] + [0x12, 0xe3, 0x9b, 0xee, 0x84, 0x23, 0x41, 0xf3] ' states: bus_sink: false bus_source: false @@ -212,7 +212,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1048, 1128.0] + coordinate: [1088, 1304.0] rotation: 0 state: enabled - name: blocks_multiply_const_vxx_0 @@ -248,7 +248,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1336, 1204.0] + coordinate: [1376, 1380.0] rotation: 0 state: disabled - name: blocks_null_sink_3 @@ -265,7 +265,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1336, 1256.0] + coordinate: [1376, 1432.0] rotation: 0 state: true - name: blocks_null_source_0 @@ -408,7 +408,7 @@ blocks: block_tags: 'False' comment: '' epsilon: '1.0' - freq_offset: '0.0002' + freq_offset: '0.0001' maxoutbuf: '0' minoutbuf: '0' noise_voltage: '0.2' @@ -497,6 +497,24 @@ blocks: coordinate: [776, 1020.0] rotation: 0 state: enabled +- name: digital_costas_loop_cc_0 + id: digital_costas_loop_cc + parameters: + affinity: '' + alias: '' + comment: '' + maxoutbuf: '0' + minoutbuf: '0' + order: '4' + use_snr: 'False' + w: 2 * 3.141592653589793 / 100 + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [1088, 1128.0] + rotation: 0 + state: true - name: digital_pfb_clock_sync_xxx_0 id: digital_pfb_clock_sync_xxx parameters: @@ -531,18 +549,20 @@ blocks: \ because tags have an absolute offset\n self.counter: np.uint64 = 0\n\ \n # because we do block processing, we need to keep track of the last\ \ tag\n # of the previous block to correct the first values of the next\ - \ block\n self.last = None\n\n # to compute the values that are\ - \ at the end we need to know the frequency\n # of the last block\n \ - \ self.freq = 1\n\n def block_phase(self, start, end):\n # compute\ - \ number of samples in block\n nsamples = end.offset - 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 freq = (sphase - ephase) / nsamples\n\n \ - \ # save this frequency values to compute the end block, unless frequency\n\ - \ # has changed too fast, in that case replace the current values with\n\ - \ # the previous one . This is effectively like a low pass filter.\n\ - \ if abs(freq / self.freq) > 4:\n freq = self.freq\n \ - \ else:\n self.freq = freq\n\n\n # debugging\n print(f\"\ + \ block\n self.last = None\n\n # both the phase and frequency\ + \ corrections should go through a low pass\n # filter to avoid werid\ + \ jumps in the correction. to do that, there are\n # two buffers with\ + \ an index\n self.index = 0\n self.length = 7\n self.freq\ + \ = np.zeros(self.length)\n\n def lpf_freq(self, new_sample):\n #\ + \ save new sample\n self.freq[self.index] = new_sample\n # increment\ + \ index\n self.index = (self.index + 1) % self.length\n\n return\ + \ np.sum(self.freq) / self.length\n\n def block_phase(self, start, end):\n\ + \ # compute number of samples in block\n nsamples = end.offset\ + \ - 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 # and run\ + \ it through a low pass filter (mean)\n freq = (sphase - ephase) / nsamples\n\ + \ freq = self.lpf_freq(freq)\n\n # debugging\n print(f\"\ Correction for block of {nsamples:2d} samples is \" \\\n f\"phase={sphase:\ \ .4f} rad and freq={freq*1e3: .4f} milli rad / sample\")\n\n # compute\ \ block values\n return sphase * np.ones(nsamples) + freq * np.arange(0,\ @@ -551,20 +571,22 @@ blocks: \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 # 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 \ - \ blocks = [ self.block_phase(start, end) for (start, end) in pairs ]\n \ - \ middle = np.concatenate(blocks) if blocks 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 block to approximate\n nback\ - \ = len(inp) - (tags[-1].offset - self.counter)\n print(f\"Processing\ - \ {nback} samples at the back of the buffer\")\n end = np.ones(nback)\ - \ * pmt.to_python(tags[-1].value) + self.freq * np.arange(0, nback)\n\n \ - \ # compute the \"start\", using the last tag from the previous call\n \ - \ nfront = tags[0].offset - self.counter\n print(f\"Processing {nfront}\ + \ 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 blocks = [ self.block_phase(start, end) for\ + \ (start, end) in pairs ]\n middle = np.concatenate(blocks) if blocks\ + \ 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 block\ + \ to approximate\n nback = len(inp) - (tags[-1].offset - self.counter)\n\ + \ print(f\"Processing {nback} samples at the back of the buffer\")\n\ + \ endfreq = self.lpf_freq(self.freq[-1])\n end = np.ones(nback)\ + \ * pmt.to_python(tags[-1].value) + endfreq * np.arange(0, nback)\n\n \ + \ # compute the \"start\", using the last tag from the previous call\n \ + \ nfront = tags[0].offset - self.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,\ @@ -728,9 +750,9 @@ blocks: comment: '' grid: 'False' gui_hint: 2,1,2,1 - label1: '' + label1: Custom Block label10: '' - label2: '' + label2: Costas Loop label3: '' label4: '' label5: '' @@ -750,7 +772,7 @@ blocks: marker8: '0' marker9: '0' name: '"Phase Locked Signal"' - nconnections: '1' + nconnections: '2' size: '1024' style1: '0' style10: '0' @@ -787,7 +809,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1288, 940.0] + coordinate: [1368, 1092.0] rotation: 0 state: enabled - name: qtgui_const_sink_x_1 @@ -1073,7 +1095,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1336, 1108.0] + coordinate: [1376, 1284.0] rotation: 0 state: enabled - name: qtgui_time_sink_x_0_0_0 @@ -1558,7 +1580,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1512, 1188.0] + coordinate: [1552, 1364.0] rotation: 0 state: disabled - name: root_raised_cosine_filter_0 @@ -1607,7 +1629,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1336, 1036.0] + coordinate: [1368, 1036.0] rotation: 0 state: true - name: virtual_source_0 @@ -1660,9 +1682,11 @@ connections: - [digital_constellation_modulator_0, '0', blocks_stream_mux_1, '1'] - [digital_constellation_modulator_0, '0', channels_channel_model_0, '0'] - [digital_constellation_modulator_0, '0', qtgui_time_sink_x_1_0, '0'] +- [digital_corr_est_cc_0, '0', digital_costas_loop_cc_0, '0'] - [digital_corr_est_cc_0, '0', epy_block_0, '0'] - [digital_corr_est_cc_0, '0', qtgui_time_sink_x_0_0_0, '0'] - [digital_corr_est_cc_0, '1', blocks_complex_to_magphase_0_0, '0'] +- [digital_costas_loop_cc_0, '0', qtgui_const_sink_x_0_0, '1'] - [digital_pfb_clock_sync_xxx_0, '0', digital_cma_equalizer_cc_0, '0'] - [epy_block_0, '0', qtgui_const_sink_x_0_0, '0'] - [epy_block_0, '0', virtual_sink_3, '0'] -- cgit v1.2.1 From 0cb8ac7bd0e88d6d26c1fda3abcf0977c2e8150b Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 3 Dec 2021 17:54:07 +0100 Subject: Fix bug that makes jump estimated frequency to unreasonably high values --- tests/correlator/correlator.grc | 285 +++++++++++++++++++--------------------- 1 file changed, 132 insertions(+), 153 deletions(-) (limited to 'tests/correlator/correlator.grc') diff --git a/tests/correlator/correlator.grc b/tests/correlator/correlator.grc index 220eaed..0f82f27 100644 --- a/tests/correlator/correlator.grc +++ b/tests/correlator/correlator.grc @@ -44,26 +44,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [776, 1140.0] - rotation: 0 - state: enabled -- name: access_code_symbols_sps - id: variable - parameters: - comment: '' - value: '[(1.4142197+1.4142197j), (1.4142197+1.4142197j), (1.4142197+1.4142197j), - (1.4142197+1.4142197j), (1.4142197-1.4142197j), (1.4142197-1.4142197j), (1.4142197-1.4142197j), - (1.4142197-1.4142197j), (1.4142197-1.4142197j), (1.4142197-1.4142197j), (1.4142197-1.4142197j), - (1.4142197-1.4142197j), (-1.4142197-1.4142197j), (-1.4142197-1.4142197j), (-1.4142197-1.4142197j), - (-1.4142197-1.4142197j), (1.4142197-1.4142197j), (1.4142197-1.4142197j), (1.4142197-1.4142197j), - (1.4142197-1.4142197j), (1.4142197+1.4142197j), (1.4142197+1.4142197j), (1.4142197+1.4142197j), - (1.4142197+1.4142197j), (1.4142197+1.4142197j), (1.4142197+1.4142197j), (1.4142197+1.4142197j), - (1.4142197+1.4142197j)]' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [224, 132.0] + coordinate: [768, 1016.0] rotation: 0 state: enabled - name: const @@ -81,7 +62,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [592, 484.0] + coordinate: [592, 360.0] rotation: 0 state: enabled - name: excess_bw @@ -93,7 +74,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [496, 484.0] + coordinate: [496, 360.0] rotation: 0 state: enabled - name: nfilts @@ -105,7 +86,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [224, 988.0] + coordinate: [224, 856.0] rotation: 0 state: enabled - name: revconj_access_code_symbols @@ -120,7 +101,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [48, 564.0] + coordinate: [48, 440.0] rotation: 0 state: enabled - name: rrc_taps @@ -132,14 +113,14 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [304, 988.0] + coordinate: [304, 856.0] rotation: 0 state: enabled - name: samp_rate id: variable parameters: comment: '' - value: '32000' + value: int(1.5e6) states: bus_sink: false bus_source: false @@ -163,24 +144,24 @@ blocks: id: variable parameters: comment: '' - value: '[31, 53] + [0x12, 0xe3, 0x9b, 0xee, 0x84, 0x23, 0x41, 0xf3] ' + value: '[0x1f, 0x35] + [0x12, 0xe3, 0x9b, 0xee, 0x84, 0x23, 0x41, 0xf3] ' states: bus_sink: false bus_source: false bus_structure: null - coordinate: [48, 492.0] + coordinate: [48, 360.0] rotation: 0 state: enabled - name: timing_loop_bw id: variable parameters: comment: '' - value: 2 * 3.141592653589793 / 100 + value: 2 * np.pi / 100 states: bus_sink: false bus_source: false bus_structure: null - coordinate: [224, 1068.0] + coordinate: [224, 936.0] rotation: 0 state: enabled - name: blocks_complex_to_magphase_0 @@ -196,7 +177,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1048, 696.0] + coordinate: [1040, 568.0] rotation: 0 state: disabled - name: blocks_complex_to_magphase_0_0 @@ -212,7 +193,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1088, 1304.0] + coordinate: [1032, 1176.0] rotation: 0 state: enabled - name: blocks_multiply_const_vxx_0 @@ -230,7 +211,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1288, 724.0] + coordinate: [1288, 596.0] rotation: 0 state: disabled - name: blocks_multiply_const_vxx_0_0 @@ -248,7 +229,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1376, 1380.0] + coordinate: [1376, 1248.0] rotation: 0 state: disabled - name: blocks_null_sink_3 @@ -265,7 +246,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1376, 1432.0] + coordinate: [1376, 1304.0] rotation: 0 state: true - name: blocks_null_source_0 @@ -284,47 +265,48 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [96, 344.0] + coordinate: [96, 200.0] rotation: 0 state: enabled -- name: blocks_stream_mux_0 - id: blocks_stream_mux +- name: blocks_repack_bits_bb_0 + id: blocks_repack_bits_bb parameters: affinity: '' alias: '' + align_output: 'False' comment: '' - lengths: '[10, len(testvec)]' + endianness: gr.GR_MSB_FIRST + k: '2' + l: '8' + len_tag_key: '""' maxoutbuf: '0' minoutbuf: '0' - num_inputs: '2' - type: byte - vlen: '1' states: bus_sink: false bus_source: false bus_structure: null - coordinate: [288, 392.0] + coordinate: [672, 1252.0] rotation: 0 - state: enabled -- name: blocks_stream_mux_1 + state: true +- name: blocks_stream_mux_0 id: blocks_stream_mux parameters: affinity: '' alias: '' comment: '' - lengths: '[len(access_code_symbols_sps), sps * (len(testvec) + 15)]' + lengths: '[5, len(testvec)]' maxoutbuf: '0' minoutbuf: '0' num_inputs: '2' - type: complex + type: byte vlen: '1' states: bus_sink: false bus_source: false bus_structure: null - coordinate: [776, 280.0] + coordinate: [288, 256.0] rotation: 0 - state: disabled + state: enabled - name: blocks_throttle_0 id: blocks_throttle parameters: @@ -341,25 +323,9 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1272, 404.0] + coordinate: [1272, 268.0] rotation: 0 state: enabled -- name: blocks_vector_sink_x_0 - id: blocks_vector_sink_x - parameters: - affinity: '' - alias: '' - comment: '' - reserve_items: '1024' - type: byte - vlen: '1' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [536, 1392.0] - rotation: 0 - state: true - name: blocks_vector_source_x_0 id: blocks_vector_source_x parameters: @@ -371,35 +337,15 @@ blocks: repeat: 'True' tags: '[]' type: byte - vector: testvec * 1600 + vector: testvec * 500 vlen: '1' states: bus_sink: false bus_source: false bus_structure: null - coordinate: [48, 404.0] + coordinate: [48, 268.0] rotation: 0 state: enabled -- name: blocks_vector_source_x_1 - id: blocks_vector_source_x - parameters: - affinity: '' - alias: '' - comment: '' - maxoutbuf: '0' - minoutbuf: '0' - repeat: 'True' - tags: '[]' - type: complex - vector: access_code_symbols_sps - vlen: '1' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [224, 204.0] - rotation: 0 - state: disabled - name: channels_channel_model_0 id: channels_channel_model parameters: @@ -411,14 +357,14 @@ blocks: freq_offset: '0.0001' maxoutbuf: '0' minoutbuf: '0' - noise_voltage: '0.2' + noise_voltage: '0.01' seed: '243' - taps: -1.4 + .4j + taps: np.exp(1j * 30 / 180 * np.pi) states: bus_sink: false bus_source: false bus_structure: null - coordinate: [992, 364.0] + coordinate: [1000, 228.0] rotation: 0 state: enabled - name: digital_cma_equalizer_cc_0 @@ -437,7 +383,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [528, 812.0] + coordinate: [520, 676.0] rotation: 0 state: enabled - name: digital_constellation_decoder_cb_0 @@ -453,7 +399,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [248, 1388.0] + coordinate: [224, 1260.0] rotation: 0 state: enabled - name: digital_constellation_modulator_0 @@ -474,7 +420,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [496, 380.0] + coordinate: [504, 244.0] rotation: 0 state: enabled - name: digital_corr_est_cc_0 @@ -494,7 +440,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [776, 1020.0] + coordinate: [768, 892.0] rotation: 0 state: enabled - name: digital_costas_loop_cc_0 @@ -512,9 +458,25 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1088, 1128.0] + coordinate: [1080, 1000.0] rotation: 0 state: true +- name: digital_map_bb_0 + id: digital_map_bb + parameters: + affinity: '' + alias: '' + comment: '' + map: '[0, 1, 3, 2]' + maxoutbuf: '0' + minoutbuf: '0' + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [496, 1260.0] + rotation: 0 + state: bypassed - name: digital_pfb_clock_sync_xxx_0 id: digital_pfb_clock_sync_xxx parameters: @@ -535,7 +497,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [224, 836.0] + coordinate: [224, 700.0] rotation: 0 state: enabled - name: epy_block_0 @@ -552,7 +514,7 @@ blocks: \ block\n self.last = None\n\n # both the phase and frequency\ \ corrections should go through a low pass\n # filter to avoid werid\ \ jumps in the correction. to do that, there are\n # two buffers with\ - \ an index\n self.index = 0\n self.length = 7\n self.freq\ + \ an index\n self.index = 0\n self.length = 5\n self.freq\ \ = np.zeros(self.length)\n\n def lpf_freq(self, new_sample):\n #\ \ save new sample\n self.freq[self.index] = new_sample\n # increment\ \ index\n self.index = (self.index + 1) % self.length\n\n return\ @@ -561,15 +523,18 @@ 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 # and run\ - \ it through a low pass filter (mean)\n freq = (sphase - ephase) / nsamples\n\ - \ freq = self.lpf_freq(freq)\n\n # debugging\n print(f\"\ - Correction for block of {nsamples:2d} samples is \" \\\n f\"phase={sphase:\ - \ .4f} rad and freq={freq*1e3: .4f} milli rad / sample\")\n\n # compute\ - \ block values\n return sphase * np.ones(nsamples) + freq * np.arange(0,\ - \ nsamples)\n\n def work(self, input_items, output_items):\n # FIXME:\ - \ replace class counter with local variable\n self.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)\ + \ it through a low pass filter (mean)\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 # freq = self.lpf_freq(freq)\n\n #\ + \ debugging\n print(f\"Correction for block of {nsamples:2d} samples\ + \ is \" \\\n f\"sphase={sphase: .4f} rad and freq={freq*1e3: .4f}\ + \ milli rad / sample\")\n\n # compute block values\n return sphase\ + \ * np.ones(nsamples) + freq * np.arange(0, nsamples)\n\n def work(self,\ + \ input_items, output_items):\n # FIXME: replace class counter with local\ + \ variable\n self.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\ @@ -606,9 +571,35 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1088, 1040.0] + coordinate: [1208, 912.0] rotation: 0 state: enabled +- name: epy_block_1 + id: epy_block + parameters: + _source_code: "\"\"\"\nEmbedded Python Blocks:\n\nEach time this file is saved,\ + \ GRC will instantiate the first class it finds\nto get ports and parameters\ + \ of your block. The arguments to __init__ will\nbe the parameters. All of\ + \ them are required to have default values!\n\"\"\"\n\nimport numpy as np\n\ + from gnuradio import gr\n\nnp.set_printoptions(formatter={'int':hex})\n\nclass\ + \ blk(gr.sync_block):\n def __init__(self):\n gr.sync_block.__init__(\n\ + \ self,\n name='Printer',\n in_sig=[np.byte],\n\ + \ out_sig=[]\n )\n\n def work(self, input_items, output_items):\n\ + \ inp = np.array(input_items[0], dtype=np.uint8)\n print(f\"Decoded\ + \ {len(inp)} samples:\\n{inp}\")\n\n return len(inp)\n" + affinity: '' + alias: '' + comment: '' + maxoutbuf: '0' + minoutbuf: '0' + states: + _io_cache: ('Printer', 'blk', [], [('0', 'byte', 1)], [], '', []) + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [920, 1264.0] + rotation: 0 + state: true - name: fir_filter_xxx_1 id: fir_filter_xxx parameters: @@ -625,9 +616,22 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [776, 828.0] + coordinate: [776, 692.0] rotation: 0 state: disabled +- name: import_0 + id: import + parameters: + alias: '' + comment: '' + imports: import numpy as np + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [184, 12.0] + rotation: 0 + state: true - name: qtgui_const_sink_x_0 id: qtgui_const_sink_x parameters: @@ -717,7 +721,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [776, 716.0] + coordinate: [768, 592.0] rotation: 0 state: enabled - name: qtgui_const_sink_x_0_0 @@ -809,7 +813,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1368, 1092.0] + coordinate: [1408, 964.0] rotation: 0 state: enabled - name: qtgui_const_sink_x_1 @@ -901,7 +905,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1048, 612.0] + coordinate: [1040, 480.0] rotation: 0 state: disabled - name: qtgui_time_sink_x_0 @@ -998,7 +1002,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1320, 604.0] + coordinate: [1312, 480.0] rotation: 0 state: disabled - name: qtgui_time_sink_x_0_0 @@ -1057,7 +1061,7 @@ blocks: name: '""' nconnections: '1' size: '1024' - srate: samp_rate + srate: samp_rate / sps stemplot: 'False' style1: '1' style10: '1' @@ -1095,7 +1099,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1376, 1284.0] + coordinate: [1376, 1152.0] rotation: 0 state: enabled - name: qtgui_time_sink_x_0_0_0 @@ -1154,7 +1158,7 @@ blocks: name: '""' nconnections: '1' size: '1024' - srate: samp_rate + srate: samp_rate / sps stemplot: 'False' style1: '1' style10: '1' @@ -1192,7 +1196,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1048, 940.0] + coordinate: [1072, 788.0] rotation: 0 state: enabled - name: qtgui_time_sink_x_1_0 @@ -1289,7 +1293,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [808, 452.0] + coordinate: [800, 320.0] rotation: 0 state: enabled - name: qtgui_time_sink_x_1_1 @@ -1386,7 +1390,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [776, 612.0] + coordinate: [768, 480.0] rotation: 0 state: disabled - name: qtgui_time_sink_x_2 @@ -1483,7 +1487,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1480, 708.0] + coordinate: [1488, 580.0] rotation: 0 state: disabled - name: qtgui_time_sink_x_2_0 @@ -1580,30 +1584,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1552, 1364.0] - rotation: 0 - state: disabled -- name: root_raised_cosine_filter_0 - id: root_raised_cosine_filter - parameters: - affinity: '' - alias: '' - alpha: excess_bw - comment: '' - decim: '1' - gain: '2' - interp: '1' - maxoutbuf: '0' - minoutbuf: '0' - ntaps: 11*samp_rate - samp_rate: samp_rate - sym_rate: sps * samp_rate - type: fir_filter_ccf - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [496, 180.0] + coordinate: [1552, 1232.0] rotation: 0 state: disabled - name: virtual_sink_0 @@ -1616,7 +1597,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1480, 404.0] + coordinate: [1488, 268.0] rotation: 0 state: enabled - name: virtual_sink_3 @@ -1629,7 +1610,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1368, 1036.0] + coordinate: [1400, 828.0] rotation: 0 state: true - name: virtual_source_0 @@ -1642,7 +1623,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [32, 884.0] + coordinate: [16, 748.0] rotation: 0 state: enabled - name: virtual_source_1 @@ -1655,7 +1636,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [24, 1388.0] + coordinate: [16, 1260.0] rotation: 0 state: true @@ -1668,18 +1649,16 @@ connections: - [blocks_multiply_const_vxx_0, '0', qtgui_time_sink_x_2, '0'] - [blocks_multiply_const_vxx_0_0, '0', qtgui_time_sink_x_2_0, '0'] - [blocks_null_source_0, '0', blocks_stream_mux_0, '0'] +- [blocks_repack_bits_bb_0, '0', epy_block_1, '0'] - [blocks_stream_mux_0, '0', digital_constellation_modulator_0, '0'] -- [blocks_stream_mux_1, '0', channels_channel_model_0, '0'] - [blocks_throttle_0, '0', virtual_sink_0, '0'] - [blocks_vector_source_x_0, '0', blocks_stream_mux_0, '1'] -- [blocks_vector_source_x_1, '0', root_raised_cosine_filter_0, '0'] - [channels_channel_model_0, '0', blocks_throttle_0, '0'] - [digital_cma_equalizer_cc_0, '0', digital_corr_est_cc_0, '0'] - [digital_cma_equalizer_cc_0, '0', fir_filter_xxx_1, '0'] - [digital_cma_equalizer_cc_0, '0', qtgui_const_sink_x_0, '0'] - [digital_cma_equalizer_cc_0, '0', qtgui_time_sink_x_1_1, '0'] -- [digital_constellation_decoder_cb_0, '0', blocks_vector_sink_x_0, '0'] -- [digital_constellation_modulator_0, '0', blocks_stream_mux_1, '1'] +- [digital_constellation_decoder_cb_0, '0', digital_map_bb_0, '0'] - [digital_constellation_modulator_0, '0', channels_channel_model_0, '0'] - [digital_constellation_modulator_0, '0', qtgui_time_sink_x_1_0, '0'] - [digital_corr_est_cc_0, '0', digital_costas_loop_cc_0, '0'] @@ -1687,12 +1666,12 @@ connections: - [digital_corr_est_cc_0, '0', qtgui_time_sink_x_0_0_0, '0'] - [digital_corr_est_cc_0, '1', blocks_complex_to_magphase_0_0, '0'] - [digital_costas_loop_cc_0, '0', qtgui_const_sink_x_0_0, '1'] +- [digital_map_bb_0, '0', blocks_repack_bits_bb_0, '0'] - [digital_pfb_clock_sync_xxx_0, '0', digital_cma_equalizer_cc_0, '0'] - [epy_block_0, '0', qtgui_const_sink_x_0_0, '0'] - [epy_block_0, '0', virtual_sink_3, '0'] - [fir_filter_xxx_1, '0', blocks_complex_to_magphase_0, '0'] - [fir_filter_xxx_1, '0', qtgui_const_sink_x_1, '0'] -- [root_raised_cosine_filter_0, '0', blocks_stream_mux_1, '0'] - [virtual_source_0, '0', digital_pfb_clock_sync_xxx_0, '0'] - [virtual_source_1, '0', digital_constellation_decoder_cb_0, '0'] -- cgit v1.2.1 From eb385ffb0c3c41d7097fb74260f3a39c2aaeb926 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 3 Dec 2021 21:55:18 +0100 Subject: Remove frequency LPF and clean up --- tests/correlator/correlator.grc | 94 ++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 48 deletions(-) (limited to 'tests/correlator/correlator.grc') diff --git a/tests/correlator/correlator.grc b/tests/correlator/correlator.grc index 0f82f27..beea007 100644 --- a/tests/correlator/correlator.grc +++ b/tests/correlator/correlator.grc @@ -193,7 +193,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1032, 1176.0] + coordinate: [1080, 1176.0] rotation: 0 state: enabled - name: blocks_multiply_const_vxx_0 @@ -505,36 +505,34 @@ blocks: parameters: _source_code: "import pmt\n\nimport numpy as np\nfrom gnuradio import gr\n\n\n\ class blk(gr.sync_block):\n def __init__(self):\n gr.sync_block.__init__(\n\ - \ self,\n name='Phase Lock',\n in_sig=[np.complex64],\n\ - \ out_sig=[np.complex64]\n )\n\n # we need to keep\ - \ track of the aboslute number of samples that have\n # been processed,\ - \ because tags have an absolute offset\n self.counter: np.uint64 = 0\n\ - \n # because we do block processing, we need to keep track of the last\ - \ tag\n # of the previous block to correct the first values of the next\ - \ block\n self.last = None\n\n # both the phase and frequency\ - \ corrections should go through a low pass\n # filter to avoid werid\ - \ jumps in the correction. to do that, there are\n # two buffers with\ - \ an index\n self.index = 0\n self.length = 5\n self.freq\ - \ = np.zeros(self.length)\n\n def lpf_freq(self, new_sample):\n #\ - \ save new sample\n self.freq[self.index] = new_sample\n # increment\ - \ index\n self.index = (self.index + 1) % self.length\n\n return\ - \ np.sum(self.freq) / self.length\n\n def block_phase(self, start, end):\n\ - \ # compute number of samples in block\n nsamples = end.offset\ - \ - 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 # and run\ - \ it through a low pass filter (mean)\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 # freq = self.lpf_freq(freq)\n\n #\ - \ debugging\n print(f\"Correction for block of {nsamples:2d} samples\ - \ is \" \\\n f\"sphase={sphase: .4f} rad and freq={freq*1e3: .4f}\ - \ milli rad / sample\")\n\n # compute block values\n return sphase\ - \ * np.ones(nsamples) + freq * np.arange(0, nsamples)\n\n def work(self,\ - \ input_items, output_items):\n # FIXME: replace class counter with local\ - \ variable\n self.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)\ + \ self,\n name='Phase and Frequency Correction',\n \ + \ in_sig=[np.complex64],\n out_sig=[np.complex64]\n \ + \ )\n\n # tags should not be propagated, we then output our own tags\n\ + \ self.set_tag_propagation_policy(gr.TPP_DONT)\n\n # because we\ + \ do block processing, we need to keep track of the last tag\n # of the\ + \ previous block to correct the first values of the next block\n self.last\ + \ = None\n self.lastfreq = 0\n\n def block_phase(self, start, end):\n\ + \ \"\"\"\n Compute a vector for the phase and frequency correction\ + \ for the samples\n between two tags (start and end).\n\n @param\ + \ start Tag where the samples should start to be corrected\n @param end\ + \ Tag where to stop correcting\n\n @return A vector of phase values\ + \ for each sample. If we call the ouput\n `phase' to correct\ + \ the samples between the start and end tags,\n TODO: finish\n\ + \ \"\"\"\n # compute number of samples in block\n nsamples\ + \ = end.offset - 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 block of {nsamples:2d}\ + \ samples is \" \\\n f\"sphase={sphase: .4f} rad and freq={freq*1e3:\ + \ .4f} milli rad / sample\")\n\n # compute block 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\ @@ -546,32 +544,32 @@ blocks: \ (start, end) in pairs ]\n middle = np.concatenate(blocks) if blocks\ \ 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 block\ - \ to approximate\n nback = len(inp) - (tags[-1].offset - self.counter)\n\ - \ print(f\"Processing {nback} samples at the back of the buffer\")\n\ - \ endfreq = self.lpf_freq(self.freq[-1])\n end = np.ones(nback)\ - \ * pmt.to_python(tags[-1].value) + endfreq * np.arange(0, nback)\n\n \ - \ # compute the \"start\", using the last tag from the previous call\n \ - \ nfront = tags[0].offset - self.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,\ + \ 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\ - \ out[:length] = inp[:length] * correction\n self.counter += len(inp)\n\ - \n # save last tag for next call\n self.last = tags[-1]\n\n \ - \ # FIXME: should return `length' but then the last sample is not\n \ - \ # included and self.last does something weird\n return len(out)\n" + \ out[:length] = inp[:length] * correction\n\n # save last tag\ + \ for next call\n self.last = tags[-1]\n\n # FIXME: should return\ + \ `length' but then the last sample is not\n # included and self.last\ + \ does something weird\n return len(out)\n" affinity: '' alias: '' comment: '' maxoutbuf: '0' minoutbuf: '0' states: - _io_cache: ('Phase Lock', 'blk', [], [('0', 'complex', 1)], [('0', 'complex', - 1)], '', []) + _io_cache: ('Phase and Frequency Correction', 'blk', [], [('0', 'complex', 1)], + [('0', 'complex', 1)], '', []) bus_sink: false bus_source: false bus_structure: null - coordinate: [1208, 912.0] + coordinate: [1072, 912.0] rotation: 0 state: enabled - name: epy_block_1 @@ -1099,7 +1097,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1376, 1152.0] + coordinate: [1376, 1156.0] rotation: 0 state: enabled - name: qtgui_time_sink_x_0_0_0 -- cgit v1.2.1 From 13a2fda61a5cb1e6d3f807d0acda42c45e128434 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 3 Dec 2021 23:46:33 +0100 Subject: Fix correlation peak detector and add frame_start tags --- tests/correlator/correlator.grc | 502 ++++++++++------------------------------ 1 file changed, 120 insertions(+), 382 deletions(-) (limited to 'tests/correlator/correlator.grc') diff --git a/tests/correlator/correlator.grc b/tests/correlator/correlator.grc index beea007..c34e5a9 100644 --- a/tests/correlator/correlator.grc +++ b/tests/correlator/correlator.grc @@ -36,15 +36,15 @@ blocks: id: variable parameters: comment: '' - value: '[(-1.4142135623730951-1.4142135623730951j), (1.4142135623730951-1.4142135623730951j), + value: .5 * np.array([(-1.4142135623730951-1.4142135623730951j), (1.4142135623730951-1.4142135623730951j), (1.4142135623730951+1.4142135623730951j), (1.4142135623730951+1.4142135623730951j), (-1.4142135623730951-1.4142135623730951j), (1.4142135623730951+1.4142135623730951j), - (1.4142135623730951-1.4142135623730951j), (1.4142135623730951-1.4142135623730951j)]' + (1.4142135623730951-1.4142135623730951j), (1.4142135623730951-1.4142135623730951j)]) states: bus_sink: false bus_source: false bus_structure: null - coordinate: [768, 1016.0] + coordinate: [792, 788.0] rotation: 0 state: enabled - name: const @@ -101,7 +101,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [48, 440.0] + coordinate: [784, 1052.0] rotation: 0 state: enabled - name: rrc_taps @@ -164,22 +164,6 @@ blocks: coordinate: [224, 936.0] rotation: 0 state: enabled -- name: blocks_complex_to_magphase_0 - id: blocks_complex_to_magphase - parameters: - affinity: '' - alias: '' - comment: '' - maxoutbuf: '0' - minoutbuf: '0' - vlen: '1' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [1040, 568.0] - rotation: 0 - state: disabled - name: blocks_complex_to_magphase_0_0 id: blocks_complex_to_magphase parameters: @@ -193,27 +177,9 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1080, 1176.0] + coordinate: [1056, 984.0] rotation: 0 state: enabled -- name: blocks_multiply_const_vxx_0 - id: blocks_multiply_const_vxx - parameters: - affinity: '' - alias: '' - comment: '' - const: 180 / 3.141592653589793 - maxoutbuf: '0' - minoutbuf: '0' - type: float - vlen: '1' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [1288, 596.0] - rotation: 0 - state: disabled - name: blocks_multiply_const_vxx_0_0 id: blocks_multiply_const_vxx parameters: @@ -229,7 +195,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1376, 1248.0] + coordinate: [1312, 1076.0] rotation: 0 state: disabled - name: blocks_null_sink_3 @@ -246,7 +212,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1376, 1304.0] + coordinate: [1360, 1016.0] rotation: 0 state: true - name: blocks_null_source_0 @@ -294,7 +260,7 @@ blocks: affinity: '' alias: '' comment: '' - lengths: '[5, len(testvec)]' + lengths: '[0, len(testvec)]' maxoutbuf: '0' minoutbuf: '0' num_inputs: '2' @@ -307,6 +273,43 @@ blocks: coordinate: [288, 256.0] rotation: 0 state: enabled +- name: blocks_tag_debug_0 + id: blocks_tag_debug + parameters: + affinity: '' + alias: '' + comment: '' + display: 'True' + filter: '""' + name: '' + num_inputs: '1' + type: byte + vlen: '1' + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [1208, 1164.0] + rotation: 0 + state: disabled +- name: blocks_tagged_stream_align_0 + id: blocks_tagged_stream_align + parameters: + affinity: '' + alias: '' + comment: '' + lengthtagname: frame_start + maxoutbuf: '0' + minoutbuf: '0' + type: byte + vlen: '1' + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [928, 1260.0] + rotation: 0 + state: true - name: blocks_throttle_0 id: blocks_throttle parameters: @@ -354,7 +357,7 @@ blocks: block_tags: 'False' comment: '' epsilon: '1.0' - freq_offset: '0.0001' + freq_offset: '0.002' maxoutbuf: '0' minoutbuf: '0' noise_voltage: '0.01' @@ -429,18 +432,18 @@ blocks: affinity: '' alias: '' comment: '' - mark_delay: '0' + mark_delay: len(access_code_symbols) // 2 maxoutbuf: '0' minoutbuf: '0' sps: '1' symbols: access_code_symbols - threshold: '.8' - threshold_method: digital.THRESHOLD_DYNAMIC + threshold: '.9' + threshold_method: digital.THRESHOLD_ABSOLUTE states: bus_sink: false bus_source: false bus_structure: null - coordinate: [768, 892.0] + coordinate: [792, 668.0] rotation: 0 state: enabled - name: digital_costas_loop_cc_0 @@ -458,7 +461,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1080, 1000.0] + coordinate: [1104, 808.0] rotation: 0 state: true - name: digital_map_bb_0 @@ -476,7 +479,7 @@ blocks: bus_structure: null coordinate: [496, 1260.0] rotation: 0 - state: bypassed + state: enabled - name: digital_pfb_clock_sync_xxx_0 id: digital_pfb_clock_sync_xxx parameters: @@ -504,31 +507,33 @@ blocks: id: epy_block parameters: _source_code: "import pmt\n\nimport numpy as np\nfrom gnuradio import gr\n\n\n\ - class blk(gr.sync_block):\n def __init__(self):\n gr.sync_block.__init__(\n\ - \ self,\n name='Phase and Frequency Correction',\n \ - \ in_sig=[np.complex64],\n out_sig=[np.complex64]\n \ - \ )\n\n # tags should not be propagated, we then output our own tags\n\ - \ self.set_tag_propagation_policy(gr.TPP_DONT)\n\n # because we\ - \ do block processing, we need to keep track of the last tag\n # of the\ - \ previous block to correct the first values of the next block\n self.last\ - \ = None\n self.lastfreq = 0\n\n def block_phase(self, start, end):\n\ - \ \"\"\"\n Compute a vector for the phase and frequency correction\ - \ for the samples\n between two tags (start and end).\n\n @param\ - \ start Tag where the samples should start to be corrected\n @param end\ - \ Tag where to stop correcting\n\n @return A vector of phase values\ - \ for each sample. If we call the ouput\n `phase' to correct\ - \ the samples between the start and end tags,\n TODO: finish\n\ - \ \"\"\"\n # compute number of samples in block\n nsamples\ - \ = end.offset - 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\ + class blk(gr.sync_block):\n \"\"\"\n Apply phase and frequency correction\ + \ where there is a correlation peak tag.\n\n The correlation peak tags are\ + \ NOT propagated, and instead replaced with a\n frame_start tag.\n \"\"\ + \"\n def __init__(self):\n gr.sync_block.__init__(\n self,\n\ + \ name='Phase and Frequency Correction',\n in_sig=[np.complex64],\n\ + \ out_sig=[np.complex64]\n )\n\n # tags should not\ + \ be propagated, we then output our own tags\n self.set_tag_propagation_policy(gr.TPP_DONT)\n\ + \n # because we do block processing, we need to keep track of the last\ + \ tag\n # of the previous block to correct the first values of the next\ + \ block\n self.last = None\n self.lastfreq = 0\n\n def block_phase(self,\ + \ start, end):\n \"\"\"\n Compute a vector for the phase and frequency\ + \ correction for the samples\n between two tags (start and end).\n\n\ + \ @param start Tag where the samples should start to be corrected\n \ + \ @param end Tag where to stop correcting\n\n @return A vector\ + \ of phase values for each sample. To correct the samples\n the\ + \ data should be multiplied with np.exp(-1j * phase)\n \"\"\"\n \ + \ # compute number of samples between tags\n nsamples = end.offset\ + \ - 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 block of {nsamples:2d}\ + \ # 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 block values\n return\ + \ .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\ @@ -540,14 +545,14 @@ blocks: \ = {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 blocks = [ self.block_phase(start, end) for\ - \ (start, end) in pairs ]\n middle = np.concatenate(blocks) if blocks\ + \ 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 block\ - \ 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\"\ + \ 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:]\ @@ -555,9 +560,11 @@ blocks: \ # compute correction\n correction = np.exp(-1j * np.concatenate([start,\ \ middle, end]))\n length = len(correction)\n\n # write outputs\n\ \ out[:length] = inp[:length] * correction\n\n # save last tag\ - \ for next call\n self.last = tags[-1]\n\n # FIXME: should return\ - \ `length' but then the last sample is not\n # included and self.last\ - \ does something weird\n return len(out)\n" + \ for next call\n self.last = tags[-1]\n\n # add tags\n \ + \ for tag in tags:\n self.add_item_tag(0, tag.offset, pmt.intern(\"\ + frame_start\"), pmt.PMT_T)\n\n # FIXME: should return `length' but then\ + \ the last sample is not\n # included and self.last does something\ + \ weird\n return len(out)\n" affinity: '' alias: '' comment: '' @@ -565,11 +572,13 @@ blocks: minoutbuf: '0' states: _io_cache: ('Phase and Frequency Correction', 'blk', [], [('0', 'complex', 1)], - [('0', 'complex', 1)], '', []) + [('0', 'complex', 1)], '\n Apply phase and frequency correction where there + is a correlation peak tag.\n\n The correlation peak tags are NOT propagated, + and instead replaced with a\n frame_start tag.\n ', []) bus_sink: false bus_source: false bus_structure: null - coordinate: [1072, 912.0] + coordinate: [1088, 688.0] rotation: 0 state: enabled - name: epy_block_1 @@ -595,7 +604,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [920, 1264.0] + coordinate: [1232, 1264.0] rotation: 0 state: true - name: fir_filter_xxx_1 @@ -614,7 +623,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [776, 692.0] + coordinate: [784, 988.0] rotation: 0 state: disabled - name: import_0 @@ -630,6 +639,23 @@ blocks: coordinate: [184, 12.0] rotation: 0 state: true +- name: note_0 + id: note + parameters: + alias: '' + comment: 'THIS FLOWGRAPH MUST BE RUN + + FROM THE TERMINAL BECAUSE + + IT HAS A HUGE OUTPUT (PRINT)' + note: README + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [280, 12.0] + rotation: 0 + state: true - name: qtgui_const_sink_x_0 id: qtgui_const_sink_x parameters: @@ -719,7 +745,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [768, 592.0] + coordinate: [792, 572.0] rotation: 0 state: enabled - name: qtgui_const_sink_x_0_0 @@ -811,198 +837,9 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1408, 964.0] + coordinate: [1416, 772.0] rotation: 0 state: enabled -- name: qtgui_const_sink_x_1 - id: qtgui_const_sink_x - parameters: - affinity: '' - alias: '' - alpha1: '.5' - alpha10: '1.0' - alpha2: '1.0' - alpha3: '1.0' - alpha4: '1.0' - alpha5: '1.0' - alpha6: '1.0' - alpha7: '1.0' - alpha8: '1.0' - alpha9: '1.0' - autoscale: 'True' - axislabels: 'True' - color1: '"blue"' - color10: '"red"' - color2: '"red"' - color3: '"red"' - color4: '"red"' - color5: '"red"' - color6: '"red"' - color7: '"red"' - color8: '"red"' - color9: '"red"' - comment: '' - grid: 'True' - gui_hint: 2,1,2,1 - label1: '' - label10: '' - label2: '' - label3: '' - label4: '' - label5: '' - label6: '' - label7: '' - label8: '' - label9: '' - legend: 'True' - marker1: '9' - marker10: '0' - marker2: '0' - marker3: '0' - marker4: '0' - marker5: '0' - marker6: '0' - marker7: '0' - marker8: '0' - marker9: '0' - name: '"Cross Correlation"' - nconnections: '1' - size: '1024' - style1: '2' - style10: '0' - style2: '0' - style3: '0' - style4: '0' - style5: '0' - style6: '0' - style7: '0' - style8: '0' - style9: '0' - tr_chan: '0' - tr_level: '0.0' - tr_mode: qtgui.TRIG_MODE_FREE - tr_slope: qtgui.TRIG_SLOPE_POS - tr_tag: '""' - type: complex - update_time: '0.10' - width1: '1' - width10: '1' - width2: '1' - width3: '1' - width4: '1' - width5: '1' - width6: '1' - width7: '1' - width8: '1' - width9: '1' - xmax: '2' - xmin: '-2' - ymax: '2' - ymin: '-2' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [1040, 480.0] - rotation: 0 - state: disabled -- name: qtgui_time_sink_x_0 - id: qtgui_time_sink_x - parameters: - affinity: '' - alias: '' - alpha1: '1.0' - alpha10: '1.0' - alpha2: '1.0' - alpha3: '1.0' - alpha4: '1.0' - alpha5: '1.0' - alpha6: '1.0' - alpha7: '1.0' - alpha8: '1.0' - alpha9: '1.0' - autoscale: 'True' - axislabels: 'True' - color1: blue - color10: dark blue - color2: red - color3: green - color4: black - color5: cyan - color6: magenta - color7: yellow - color8: dark red - color9: dark green - comment: '' - ctrlpanel: 'False' - entags: 'True' - grid: 'False' - gui_hint: 2,0,1,1 - label1: Signal 1 - label10: Signal 10 - label2: Signal 2 - label3: Signal 3 - label4: Signal 4 - label5: Signal 5 - label6: Signal 6 - label7: Signal 7 - label8: Signal 8 - label9: Signal 9 - legend: 'True' - marker1: '-1' - marker10: '-1' - marker2: '-1' - marker3: '-1' - marker4: '-1' - marker5: '-1' - marker6: '-1' - marker7: '-1' - marker8: '-1' - marker9: '-1' - name: '""' - nconnections: '1' - size: '1024' - srate: samp_rate - stemplot: 'False' - style1: '1' - style10: '1' - style2: '1' - style3: '1' - style4: '1' - style5: '1' - style6: '1' - style7: '1' - style8: '1' - style9: '1' - tr_chan: '0' - tr_delay: '0' - tr_level: '0.0' - tr_mode: qtgui.TRIG_MODE_FREE - tr_slope: qtgui.TRIG_SLOPE_POS - tr_tag: '""' - type: float - update_time: '0.10' - width1: '1' - width10: '1' - width2: '1' - width3: '1' - width4: '1' - width5: '1' - width6: '1' - width7: '1' - width8: '1' - width9: '1' - ylabel: XC Magnitude - ymax: '20' - ymin: '0' - yunit: '""' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [1312, 480.0] - rotation: 0 - state: disabled - name: qtgui_time_sink_x_0_0 id: qtgui_time_sink_x parameters: @@ -1097,7 +934,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1376, 1156.0] + coordinate: [1472, 964.0] rotation: 0 state: enabled - name: qtgui_time_sink_x_0_0_0 @@ -1194,7 +1031,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1072, 788.0] + coordinate: [1096, 572.0] rotation: 0 state: enabled - name: qtgui_time_sink_x_1_0 @@ -1291,7 +1128,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [800, 320.0] + coordinate: [800, 172.0] rotation: 0 state: enabled - name: qtgui_time_sink_x_1_1 @@ -1388,104 +1225,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [768, 480.0] - rotation: 0 - state: disabled -- name: qtgui_time_sink_x_2 - id: qtgui_time_sink_x - parameters: - affinity: '' - alias: '' - alpha1: '1.0' - alpha10: '1.0' - alpha2: '1.0' - alpha3: '1.0' - alpha4: '1.0' - alpha5: '1.0' - alpha6: '1.0' - alpha7: '1.0' - alpha8: '1.0' - alpha9: '1.0' - autoscale: 'True' - axislabels: 'True' - color1: blue - color10: dark blue - color2: red - color3: green - color4: black - color5: cyan - color6: magenta - color7: yellow - color8: dark red - color9: dark green - comment: '' - ctrlpanel: 'False' - entags: 'True' - grid: 'False' - gui_hint: 3,0,1,1 - label1: Signal 1 - label10: Signal 10 - label2: Signal 2 - label3: Signal 3 - label4: Signal 4 - label5: Signal 5 - label6: Signal 6 - label7: Signal 7 - label8: Signal 8 - label9: Signal 9 - legend: 'True' - marker1: '-1' - marker10: '-1' - marker2: '-1' - marker3: '-1' - marker4: '-1' - marker5: '-1' - marker6: '-1' - marker7: '-1' - marker8: '-1' - marker9: '-1' - name: '""' - nconnections: '1' - size: '1024' - srate: samp_rate - stemplot: 'False' - style1: '1' - style10: '1' - style2: '1' - style3: '1' - style4: '1' - style5: '1' - style6: '1' - style7: '1' - style8: '1' - style9: '1' - tr_chan: '0' - tr_delay: '0' - tr_level: '0.0' - tr_mode: qtgui.TRIG_MODE_FREE - tr_slope: qtgui.TRIG_SLOPE_POS - tr_tag: '""' - type: float - update_time: '0.10' - width1: '1' - width10: '1' - width2: '1' - width3: '1' - width4: '1' - width5: '1' - width6: '1' - width7: '1' - width8: '1' - width9: '1' - ylabel: XC Phase - ymax: '1' - ymin: '-1' - yunit: '""' - states: - bus_sink: false - bus_source: false - bus_structure: null - coordinate: [1488, 580.0] + coordinate: [792, 484.0] rotation: 0 state: disabled - name: qtgui_time_sink_x_2_0 @@ -1582,7 +1322,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1552, 1232.0] + coordinate: [1472, 1060.0] rotation: 0 state: disabled - name: virtual_sink_0 @@ -1608,7 +1348,7 @@ blocks: bus_sink: false bus_source: false bus_structure: null - coordinate: [1400, 828.0] + coordinate: [1416, 684.0] rotation: 0 state: true - name: virtual_source_0 @@ -1639,16 +1379,15 @@ blocks: state: true connections: -- [blocks_complex_to_magphase_0, '0', qtgui_time_sink_x_0, '0'] -- [blocks_complex_to_magphase_0, '1', blocks_multiply_const_vxx_0, '0'] - [blocks_complex_to_magphase_0_0, '0', qtgui_time_sink_x_0_0, '0'] - [blocks_complex_to_magphase_0_0, '1', blocks_multiply_const_vxx_0_0, '0'] - [blocks_complex_to_magphase_0_0, '1', blocks_null_sink_3, '0'] -- [blocks_multiply_const_vxx_0, '0', qtgui_time_sink_x_2, '0'] - [blocks_multiply_const_vxx_0_0, '0', qtgui_time_sink_x_2_0, '0'] - [blocks_null_source_0, '0', blocks_stream_mux_0, '0'] -- [blocks_repack_bits_bb_0, '0', epy_block_1, '0'] +- [blocks_repack_bits_bb_0, '0', blocks_tagged_stream_align_0, '0'] - [blocks_stream_mux_0, '0', digital_constellation_modulator_0, '0'] +- [blocks_tagged_stream_align_0, '0', blocks_tag_debug_0, '0'] +- [blocks_tagged_stream_align_0, '0', epy_block_1, '0'] - [blocks_throttle_0, '0', virtual_sink_0, '0'] - [blocks_vector_source_x_0, '0', blocks_stream_mux_0, '1'] - [channels_channel_model_0, '0', blocks_throttle_0, '0'] @@ -1668,8 +1407,7 @@ connections: - [digital_pfb_clock_sync_xxx_0, '0', digital_cma_equalizer_cc_0, '0'] - [epy_block_0, '0', qtgui_const_sink_x_0_0, '0'] - [epy_block_0, '0', virtual_sink_3, '0'] -- [fir_filter_xxx_1, '0', blocks_complex_to_magphase_0, '0'] -- [fir_filter_xxx_1, '0', qtgui_const_sink_x_1, '0'] +- [fir_filter_xxx_1, '0', blocks_complex_to_magphase_0_0, '0'] - [virtual_source_0, '0', digital_pfb_clock_sync_xxx_0, '0'] - [virtual_source_1, '0', digital_constellation_decoder_cb_0, '0'] -- cgit v1.2.1