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