forked from MITHaystack/srt-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
radio_calibrate.grc
149 lines (146 loc) · 5.11 KB
/
radio_calibrate.grc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
options:
parameters:
author: ''
category: '[GRC Hier Blocks]'
cmake_opt: ''
comment: ''
copyright: ''
description: ''
gen_cmake: 'On'
gen_linking: dynamic
generate_options: no_gui
hier_block_src_path: '.:'
id: radio_calibrate
max_nouts: '0'
output_language: python
placement: (0,0)
qt_qss_theme: ''
realtime_scheduling: ''
run: 'True'
run_command: '{python} -u {filename}'
run_options: run
sizing_mode: fixed
thread_safe_setters: ''
title: radio_calibrate
window_size: ''
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [8, 8]
rotation: 0
state: enabled
blocks:
- name: directory_name
id: parameter
parameters:
alias: ''
comment: ''
hide: none
label: directory_name
short_id: ''
type: str
value: '"."'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [8, 205]
rotation: 0
state: true
- name: num_bins
id: parameter
parameters:
alias: ''
comment: ''
hide: none
label: num_bins
short_id: ''
type: intx
value: '4096'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [9, 106]
rotation: 0
state: true
- name: save_calibration
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\
import numpy.polynomial.polynomial as poly\nimport json\n\nfrom gnuradio import\
\ gr\nimport pmt\n\nimport pathlib\n\n\nclass blk(gr.sync_block):\n \"\"\"\
Embedded Python Block - Calculate Calibration Values\"\"\"\n\n def __init__(\n\
\ self,\n directory=\".\",\n filename=\"calibration.json\"\
,\n vec_length=4096,\n poly_smoothing_order=25,\n ): # only\
\ default arguments here\n \"\"\"arguments to this function show up as\
\ parameters in GRC\"\"\"\n gr.sync_block.__init__(\n self,\n\
\ name=\"Embedded Python Block\", # will show up in GRC\n \
\ in_sig=[(np.float32, vec_length)],\n out_sig=None,\n \
\ )\n # if an attribute with the same name as a parameter is found,\n\
\ # a callback is registered (properties work, too).\n self.directory\
\ = directory\n self.filename = filename\n self.vec_length = vec_length\n\
\ self.poly_smoothing_order = poly_smoothing_order\n self.past_input\
\ = np.zeros(vec_length)\n self.num_past_input = 0\n\n def work(self,\
\ input_items, output_items):\n \"\"\"Divide Input by Average, Determine\
\ Calibration Power, and Save\"\"\"\n for input_array in input_items[0]:\n\
\ self.past_input += input_array\n self.num_past_input\
\ += 1\n averaged_input = self.past_input / self.num_past_input\n\
\ relative_freq_values = np.linspace(-1, 1, self.vec_length)\n \
\ poly_fit = poly.Polynomial.fit(\n relative_freq_values,\
\ averaged_input, self.poly_smoothing_order,\n )\n smoothed_input\
\ = poly_fit(relative_freq_values)\n average_value = np.average(smoothed_input)\n\
\ rescaled_input = smoothed_input / average_value\n file_output\
\ = {\n \"cal_pwr\": average_value,\n \"cal_values\"\
: rescaled_input.tolist(),\n }\n with open(pathlib.Path(self.directory,\
\ self.filename), \"w\") as outfile:\n json.dump(file_output,\
\ outfile)\n return len(input_items[0])\n"
affinity: ''
alias: ''
comment: ''
directory: directory_name
filename: '''calibration.json'''
maxoutbuf: '0'
minoutbuf: '0'
poly_smoothing_order: '25'
vec_length: num_bins
states:
_io_cache: ('Embedded Python Block', 'blk', [('directory', "'.'"), ('filename',
"'calibration.json'"), ('vec_length', '4096'), ('poly_smoothing_order', '25')],
[('0', 'float', 4096)], [], 'Embedded Python Block - Calculate Calibration Values',
['directory', 'filename', 'poly_smoothing_order', 'vec_length'])
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [492, 134]
rotation: 0
state: true
- name: zeromq_sub_source_0
id: zeromq_sub_source
parameters:
address: tcp://127.0.0.1:5560
affinity: ''
alias: ''
comment: ''
hwm: '-1'
maxoutbuf: '0'
minoutbuf: '0'
pass_tags: 'True'
timeout: '100'
type: float
vlen: num_bins
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [238, 134]
rotation: 0
state: true
connections:
- [zeromq_sub_source_0, '0', save_calibration, '0']
metadata:
file_format: 1