# -*- coding: utf-8 -*-
#
# SPDX-License-Identifier: GPL-3.0
#
# GNU Radio Python Flow Graph
# Title: The FSM Method of SCF Estimation
# Author: Chad M. Spooner
# GNU Radio version: 3.8.1.0
from distutils.version import StrictVersion
if __name__ == '__main__':
import ctypes
import sys
if sys.platform.startswith('linux'):
try:
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print("Warning: failed to XInitThreads()")
import os
import sys
sys.path.append(os.environ.get('GRC_HIER_PATH', os.path.expanduser('~/.grc_gnuradio')))
from PyQt5 import Qt
from gnuradio import qtgui
from gnuradio.filter import firdes
import sip
from csp_fsm_coh import csp_fsm_coh # grc-generated hier_block
from csp_fsm_conj_coh import csp_fsm_conj_coh # grc-generated hier_block
from csp_fsm_conj_core import csp_fsm_conj_core # grc-generated hier_block
from csp_fsm_core import csp_fsm_core # grc-generated hier_block
from csp_fsm_psd_blocks import csp_fsm_psd_blocks # grc-generated hier_block
from dsss_255_cms import dsss_255_cms # grc-generated hier_block
from gnuradio import analog
from gnuradio import blocks
import numpy
from gnuradio import fft
from gnuradio.fft import window
from gnuradio import gr
import signal
from argparse import ArgumentParser
from gnuradio.eng_arg import eng_float, intx
from gnuradio import eng_notation
from gnuradio import qtgui
class csp_fsm_live_data(gr.top_block, Qt.QWidget):
def __init__(self, alpha1=49019.60784313, alpha2=98039.21568627450980392156, alpha3=0, beta1=3880049019.61, block_size=65536, fcarrier=1940e6, parameter_0=0, samp_rate=25e6, smooth_width_percent=1):
gr.top_block.__init__(self, "The FSM Method of SCF Estimation")
Qt.QWidget.__init__(self)
self.setWindowTitle("The FSM Method of SCF Estimation")
qtgui.util.check_set_qss()
try:
self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
except:
pass
self.top_scroll_layout = Qt.QVBoxLayout()
self.setLayout(self.top_scroll_layout)
self.top_scroll = Qt.QScrollArea()
self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
self.top_scroll_layout.addWidget(self.top_scroll)
self.top_scroll.setWidgetResizable(True)
self.top_widget = Qt.QWidget()
self.top_scroll.setWidget(self.top_widget)
self.top_layout = Qt.QVBoxLayout(self.top_widget)
self.top_grid_layout = Qt.QGridLayout()
self.top_layout.addLayout(self.top_grid_layout)
self.settings = Qt.QSettings("GNU Radio", "csp_fsm_live_data")
try:
if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
self.restoreGeometry(self.settings.value("geometry").toByteArray())
else:
self.restoreGeometry(self.settings.value("geometry"))
except:
pass
##################################################
# Parameters
##################################################
self.alpha1 = alpha1
self.alpha2 = alpha2
self.alpha3 = alpha3
self.beta1 = beta1
self.block_size = block_size
self.fcarrier = fcarrier
self.parameter_0 = parameter_0
self.samp_rate = samp_rate
self.smooth_width_percent = smooth_width_percent
##################################################
# Variables
##################################################
self.smooth_width_samples = smooth_width_samples = int(block_size * smooth_width_percent / 100.0)
self.resamp_factor_up = resamp_factor_up = 2
self.resamp_factor_down = resamp_factor_down = 1
self.quad_override_bpsk = quad_override_bpsk = 0
self.log2_M_bpsk = log2_M_bpsk = 1
##################################################
# Blocks
##################################################
self.qtgui_vector_sink_scf = qtgui.vector_sink_f(
block_size,
(-0.5*samp_rate + fcarrier)/1.0e6,
(samp_rate*(1.0/block_size))/1.0e6,
"Frequency (MHz)",
"SCF",
"",
3 # Number of inputs
)
self.qtgui_vector_sink_scf.set_update_time(0.25)
self.qtgui_vector_sink_scf.set_y_axis(-20, 20)
self.qtgui_vector_sink_scf.enable_autoscale(False)
self.qtgui_vector_sink_scf.enable_grid(True)
self.qtgui_vector_sink_scf.set_x_axis_units("")
self.qtgui_vector_sink_scf.set_y_axis_units("")
self.qtgui_vector_sink_scf.set_ref_level(0)
labels = ['NC SCF a1 Hz', 'NC SCF a2 Hz', 'NC SCF a3 Hz', 'NC SCF a3 Hz', 'NC SCF 1.2288 MHz',
'', '', '', '', '']
widths = [1, 1, 1, 1, 1,
1, 1, 1, 1, 1]
colors = ["green", "dark blue", "dark red", "dark red", "magenta",
"magenta", "yellow", "dark red", "dark green", "dark blue"]
alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0]
for i in range(3):
if len(labels[i]) == 0:
self.qtgui_vector_sink_scf.set_line_label(i, "Data {0}".format(i))
else:
self.qtgui_vector_sink_scf.set_line_label(i, labels[i])
self.qtgui_vector_sink_scf.set_line_width(i, widths[i])
self.qtgui_vector_sink_scf.set_line_color(i, colors[i])
self.qtgui_vector_sink_scf.set_line_alpha(i, alphas[i])
self._qtgui_vector_sink_scf_win = sip.wrapinstance(self.qtgui_vector_sink_scf.pyqwidget(), Qt.QWidget)
self.top_grid_layout.addWidget(self._qtgui_vector_sink_scf_win, 2, 1, 1, 1)
for r in range(2, 3):
self.top_grid_layout.setRowStretch(r, 1)
for c in range(1, 2):
self.top_grid_layout.setColumnStretch(c, 1)
self.qtgui_vector_sink_f_conj_coh = qtgui.vector_sink_f(
block_size,
(-0.5*samp_rate)/1.0e6,
(samp_rate*(1.0/block_size))/1.0e6,
"Frequency (MHz)",
"Conj Coherence",
"",
1 # Number of inputs
)
self.qtgui_vector_sink_f_conj_coh.set_update_time(0.25)
self.qtgui_vector_sink_f_conj_coh.set_y_axis(0, 1.05)
self.qtgui_vector_sink_f_conj_coh.enable_autoscale(False)
self.qtgui_vector_sink_f_conj_coh.enable_grid(True)
self.qtgui_vector_sink_f_conj_coh.set_x_axis_units("")
self.qtgui_vector_sink_f_conj_coh.set_y_axis_units("")
self.qtgui_vector_sink_f_conj_coh.set_ref_level(0)
labels = ['Coherence a1 Hz', 'Coherence a2 Hz', 'Coherence a3 Hz', 'NC SCF 3.84 MHz', 'NC SCF 1.2288 MHz',
'', '', '', '', '']
widths = [1, 1, 1, 1, 1,
1, 1, 1, 1, 1]
colors = ["green", "dark blue", "dark red", "red", "magenta",
"magenta", "yellow", "dark red", "dark green", "dark blue"]
alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0]
for i in range(1):
if len(labels[i]) == 0:
self.qtgui_vector_sink_f_conj_coh.set_line_label(i, "Data {0}".format(i))
else:
self.qtgui_vector_sink_f_conj_coh.set_line_label(i, labels[i])
self.qtgui_vector_sink_f_conj_coh.set_line_width(i, widths[i])
self.qtgui_vector_sink_f_conj_coh.set_line_color(i, colors[i])
self.qtgui_vector_sink_f_conj_coh.set_line_alpha(i, alphas[i])
self._qtgui_vector_sink_f_conj_coh_win = sip.wrapinstance(self.qtgui_vector_sink_f_conj_coh.pyqwidget(), Qt.QWidget)
self.top_grid_layout.addWidget(self._qtgui_vector_sink_f_conj_coh_win, 3, 2, 1, 1)
for r in range(3, 4):
self.top_grid_layout.setRowStretch(r, 1)
for c in range(2, 3):
self.top_grid_layout.setColumnStretch(c, 1)
self.qtgui_vector_sink_f_coh = qtgui.vector_sink_f(
block_size,
(-0.5*samp_rate + fcarrier)/1.0e6,
(samp_rate*(1.0/block_size))/1.0e6,
"Frequency (MHz)",
"Coherence",
"",
3 # Number of inputs
)
self.qtgui_vector_sink_f_coh.set_update_time(0.25)
self.qtgui_vector_sink_f_coh.set_y_axis(0, 1.05)
self.qtgui_vector_sink_f_coh.enable_autoscale(False)
self.qtgui_vector_sink_f_coh.enable_grid(True)
self.qtgui_vector_sink_f_coh.set_x_axis_units("")
self.qtgui_vector_sink_f_coh.set_y_axis_units("")
self.qtgui_vector_sink_f_coh.set_ref_level(0)
labels = ['Coherence a1 Hz', 'Coherence a2 Hz', 'Coherence a3 Hz', 'NC SCF 3.84 MHz', 'NC SCF 1.2288 MHz',
'', '', '', '', '']
widths = [1, 1, 1, 1, 1,
1, 1, 1, 1, 1]
colors = ["green", "dark blue", "dark red", "red", "magenta",
"magenta", "yellow", "dark red", "dark green", "dark blue"]
alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0]
for i in range(3):
if len(labels[i]) == 0:
self.qtgui_vector_sink_f_coh.set_line_label(i, "Data {0}".format(i))
else:
self.qtgui_vector_sink_f_coh.set_line_label(i, labels[i])
self.qtgui_vector_sink_f_coh.set_line_width(i, widths[i])
self.qtgui_vector_sink_f_coh.set_line_color(i, colors[i])
self.qtgui_vector_sink_f_coh.set_line_alpha(i, alphas[i])
self._qtgui_vector_sink_f_coh_win = sip.wrapinstance(self.qtgui_vector_sink_f_coh.pyqwidget(), Qt.QWidget)
self.top_grid_layout.addWidget(self._qtgui_vector_sink_f_coh_win, 2, 2, 1, 1)
for r in range(2, 3):
self.top_grid_layout.setRowStretch(r, 1)
for c in range(2, 3):
self.top_grid_layout.setColumnStretch(c, 1)
self.qtgui_vector_sink_conj_scf = qtgui.vector_sink_f(
block_size,
(-0.5*samp_rate)/1.0e6,
(samp_rate*(1.0/block_size))/1.0e6,
"Frequency (MHz)",
"Conj SCF",
"",
1 # Number of inputs
)
self.qtgui_vector_sink_conj_scf.set_update_time(0.25)
self.qtgui_vector_sink_conj_scf.set_y_axis(-20, 20)
self.qtgui_vector_sink_conj_scf.enable_autoscale(False)
self.qtgui_vector_sink_conj_scf.enable_grid(False)
self.qtgui_vector_sink_conj_scf.set_x_axis_units("")
self.qtgui_vector_sink_conj_scf.set_y_axis_units("")
self.qtgui_vector_sink_conj_scf.set_ref_level(0)
labels = ['NC SCF a1 Hz', 'NC SCF a2 Hz', 'NC SCF a3 Hz', 'NC SCF a3 Hz', 'NC SCF 1.2288 MHz',
'', '', '', '', '']
widths = [1, 1, 1, 1, 1,
1, 1, 1, 1, 1]
colors = ["green", "dark blue", "dark red", "dark red", "magenta",
"magenta", "yellow", "dark red", "dark green", "dark blue"]
alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0]
for i in range(1):
if len(labels[i]) == 0:
self.qtgui_vector_sink_conj_scf.set_line_label(i, "Data {0}".format(i))
else:
self.qtgui_vector_sink_conj_scf.set_line_label(i, labels[i])
self.qtgui_vector_sink_conj_scf.set_line_width(i, widths[i])
self.qtgui_vector_sink_conj_scf.set_line_color(i, colors[i])
self.qtgui_vector_sink_conj_scf.set_line_alpha(i, alphas[i])
self._qtgui_vector_sink_conj_scf_win = sip.wrapinstance(self.qtgui_vector_sink_conj_scf.pyqwidget(), Qt.QWidget)
self.top_grid_layout.addWidget(self._qtgui_vector_sink_conj_scf_win, 3, 1, 1, 1)
for r in range(3, 4):
self.top_grid_layout.setRowStretch(r, 1)
for c in range(1, 2):
self.top_grid_layout.setColumnStretch(c, 1)
self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
2048, #size
firdes.WIN_BLACKMAN, #wintype
fcarrier, #fc
samp_rate, #bw
"", #name
1
)
self.qtgui_freq_sink_x_0.set_update_time(0.25)
self.qtgui_freq_sink_x_0.set_y_axis(-30, 30)
self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB')
self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
self.qtgui_freq_sink_x_0.enable_autoscale(True)
self.qtgui_freq_sink_x_0.enable_grid(True)
self.qtgui_freq_sink_x_0.set_fft_average(0.1)
self.qtgui_freq_sink_x_0.enable_axis_labels(True)
self.qtgui_freq_sink_x_0.enable_control_panel(False)
labels = ['', '', '', '', '',
'', '', '', '', '']
widths = [1, 1, 1, 1, 1,
1, 1, 1, 1, 1]
colors = ["blue", "red", "green", "black", "cyan",
"magenta", "yellow", "dark red", "dark green", "dark blue"]
alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
1.0, 1.0, 1.0, 1.0, 1.0]
for i in range(1):
if len(labels[i]) == 0:
self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i))
else:
self.qtgui_freq_sink_x_0.set_line_label(i, labels[i])
self.qtgui_freq_sink_x_0.set_line_width(i, widths[i])
self.qtgui_freq_sink_x_0.set_line_color(i, colors[i])
self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i])
self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 1, 1, 1, 2)
for r in range(1, 2):
self.top_grid_layout.setRowStretch(r, 1)
for c in range(1, 3):
self.top_grid_layout.setColumnStretch(c, 1)
self.fft_vxx_0_0 = fft.fft_vcc(block_size, True, window.rectangular(block_size), True, 1)
self.fft_vxx_0 = fft.fft_vcc(block_size, True, window.rectangular(block_size), True, 1)
self.dsss_255_cms_0 = dsss_255_cms(
frame_length_symbols=100,
log2_M=log2_M_bpsk,
mlsr_m=8,
out_fc=fcarrier,
proc_gain=255,
quad_override=quad_override_bpsk,
resamp_factor_down=resamp_factor_down,
resamp_factor_up=resamp_factor_up,
resamp_ratio=0.5,
sink_rate=samp_rate,
)
self.csp_fsm_psd_blocks_normal = csp_fsm_psd_blocks(
block_size=block_size,
smooth_width_samples=smooth_width_samples,
)
self.csp_fsm_psd_blocks_conj = csp_fsm_psd_blocks(
block_size=block_size,
smooth_width_samples=smooth_width_samples,
)
self.csp_fsm_core_3 = csp_fsm_core(
alpha=alpha3,
block_size=block_size,
samp_rate=samp_rate,
smooth_width_samples=smooth_width_samples,
)
self.csp_fsm_core_2 = csp_fsm_core(
alpha=alpha2,
block_size=block_size,
samp_rate=samp_rate,
smooth_width_samples=smooth_width_samples,
)
self.csp_fsm_core_1 = csp_fsm_core(
alpha=alpha1,
block_size=block_size,
samp_rate=samp_rate,
smooth_width_samples=smooth_width_samples,
)
self.csp_fsm_conj_core_1 = csp_fsm_conj_core(
beta=beta1,
block_size=block_size,
fcarrier=fcarrier,
samp_rate=samp_rate,
smooth_width_samples=smooth_width_samples,
)
self.csp_fsm_conj_coh_0 = csp_fsm_conj_coh(
beta=beta1,
block_size=block_size,
fcarrier=fcarrier,
samp_rate=samp_rate,
)
self.csp_fsm_coh_3 = csp_fsm_coh(
alpha=alpha3,
block_size=block_size,
samp_rate=samp_rate,
)
self.csp_fsm_coh_2 = csp_fsm_coh(
alpha=alpha2,
block_size=block_size,
samp_rate=samp_rate,
)
self.csp_fsm_coh_1 = csp_fsm_coh(
alpha=alpha1,
block_size=block_size,
samp_rate=samp_rate,
)
self.blocks_vector_to_stream_0_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, block_size)
self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, block_size)
self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
self.blocks_stream_to_vector_0_1 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, block_size)
self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, block_size)
self.blocks_conjugate_cc_0_0 = blocks.conjugate_cc()
self.blocks_add_xx_0 = blocks.add_vcc(1)
self.analog_random_source_x_0_1_0_1_0 = blocks.vector_source_s(list(map(int, numpy.random.randint(0, log2_M_bpsk + 1 - quad_override_bpsk, 10000000))), True)
self.analog_random_source_x_0_0_0_0_1_0 = blocks.vector_source_s(list(map(int, numpy.random.randint(0, log2_M_bpsk + 1 - quad_override_bpsk, 10000000))), True)
self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 0.2, 0)
self.analog_agc_xx_0 = analog.agc_cc(1e-4, 1.0, 1.0)
self.analog_agc_xx_0.set_max_gain(65536)
##################################################
# Connections
##################################################
self.connect((self.analog_agc_xx_0, 0), (self.blocks_add_xx_0, 0))
self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
self.connect((self.analog_random_source_x_0_0_0_0_1_0, 0), (self.dsss_255_cms_0, 1))
self.connect((self.analog_random_source_x_0_1_0_1_0, 0), (self.dsss_255_cms_0, 0))
self.connect((self.blocks_add_xx_0, 0), (self.blocks_conjugate_cc_0_0, 0))
self.connect((self.blocks_add_xx_0, 0), (self.blocks_stream_to_vector_0, 0))
self.connect((self.blocks_add_xx_0, 0), (self.qtgui_freq_sink_x_0, 0))
self.connect((self.blocks_conjugate_cc_0_0, 0), (self.blocks_stream_to_vector_0_1, 0))
self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
self.connect((self.blocks_stream_to_vector_0_1, 0), (self.fft_vxx_0_0, 0))
self.connect((self.blocks_throttle_0, 0), (self.analog_agc_xx_0, 0))
self.connect((self.blocks_vector_to_stream_0, 0), (self.csp_fsm_conj_core_1, 0))
self.connect((self.blocks_vector_to_stream_0, 0), (self.csp_fsm_core_1, 0))
self.connect((self.blocks_vector_to_stream_0, 0), (self.csp_fsm_core_2, 0))
self.connect((self.blocks_vector_to_stream_0, 0), (self.csp_fsm_core_3, 0))
self.connect((self.blocks_vector_to_stream_0, 0), (self.csp_fsm_psd_blocks_normal, 0))
self.connect((self.blocks_vector_to_stream_0_0, 0), (self.csp_fsm_conj_core_1, 1))
self.connect((self.blocks_vector_to_stream_0_0, 0), (self.csp_fsm_psd_blocks_conj, 0))
self.connect((self.csp_fsm_coh_1, 0), (self.qtgui_vector_sink_f_coh, 0))
self.connect((self.csp_fsm_coh_2, 0), (self.qtgui_vector_sink_f_coh, 1))
self.connect((self.csp_fsm_coh_3, 0), (self.qtgui_vector_sink_f_coh, 2))
self.connect((self.csp_fsm_conj_coh_0, 0), (self.qtgui_vector_sink_f_conj_coh, 0))
self.connect((self.csp_fsm_conj_core_1, 1), (self.csp_fsm_conj_coh_0, 0))
self.connect((self.csp_fsm_conj_core_1, 0), (self.qtgui_vector_sink_conj_scf, 0))
self.connect((self.csp_fsm_core_1, 1), (self.csp_fsm_coh_1, 0))
self.connect((self.csp_fsm_core_1, 0), (self.qtgui_vector_sink_scf, 0))
self.connect((self.csp_fsm_core_2, 1), (self.csp_fsm_coh_2, 0))
self.connect((self.csp_fsm_core_2, 0), (self.qtgui_vector_sink_scf, 1))
self.connect((self.csp_fsm_core_3, 1), (self.csp_fsm_coh_3, 0))
self.connect((self.csp_fsm_core_3, 0), (self.qtgui_vector_sink_scf, 2))
self.connect((self.csp_fsm_psd_blocks_conj, 0), (self.csp_fsm_conj_coh_0, 2))
self.connect((self.csp_fsm_psd_blocks_normal, 0), (self.csp_fsm_coh_1, 1))
self.connect((self.csp_fsm_psd_blocks_normal, 0), (self.csp_fsm_coh_2, 1))
self.connect((self.csp_fsm_psd_blocks_normal, 0), (self.csp_fsm_coh_3, 1))
self.connect((self.csp_fsm_psd_blocks_normal, 0), (self.csp_fsm_conj_coh_0, 1))
self.connect((self.dsss_255_cms_0, 0), (self.blocks_throttle_0, 0))
self.connect((self.fft_vxx_0, 0), (self.blocks_vector_to_stream_0, 0))
self.connect((self.fft_vxx_0_0, 0), (self.blocks_vector_to_stream_0_0, 0))
def closeEvent(self, event):
self.settings = Qt.QSettings("GNU Radio", "csp_fsm_live_data")
self.settings.setValue("geometry", self.saveGeometry())
event.accept()
def get_alpha1(self):
return self.alpha1
def set_alpha1(self, alpha1):
self.alpha1 = alpha1
self.csp_fsm_coh_1.set_alpha(self.alpha1)
self.csp_fsm_core_1.set_alpha(self.alpha1)
def get_alpha2(self):
return self.alpha2
def set_alpha2(self, alpha2):
self.alpha2 = alpha2
self.csp_fsm_coh_2.set_alpha(self.alpha2)
self.csp_fsm_core_2.set_alpha(self.alpha2)
def get_alpha3(self):
return self.alpha3
def set_alpha3(self, alpha3):
self.alpha3 = alpha3
self.csp_fsm_coh_3.set_alpha(self.alpha3)
self.csp_fsm_core_3.set_alpha(self.alpha3)
def get_beta1(self):
return self.beta1
def set_beta1(self, beta1):
self.beta1 = beta1
self.csp_fsm_conj_coh_0.set_beta(self.beta1)
self.csp_fsm_conj_core_1.set_beta(self.beta1)
def get_block_size(self):
return self.block_size
def set_block_size(self, block_size):
self.block_size = block_size
self.set_smooth_width_samples(int(self.block_size * self.smooth_width_percent / 100.0))
self.csp_fsm_coh_1.set_block_size(self.block_size)
self.csp_fsm_coh_2.set_block_size(self.block_size)
self.csp_fsm_coh_3.set_block_size(self.block_size)
self.csp_fsm_conj_coh_0.set_block_size(self.block_size)
self.csp_fsm_conj_core_1.set_block_size(self.block_size)
self.csp_fsm_core_1.set_block_size(self.block_size)
self.csp_fsm_core_2.set_block_size(self.block_size)
self.csp_fsm_core_3.set_block_size(self.block_size)
self.csp_fsm_psd_blocks_conj.set_block_size(self.block_size)
self.csp_fsm_psd_blocks_normal.set_block_size(self.block_size)
self.qtgui_vector_sink_conj_scf.set_x_axis((-0.5*self.samp_rate)/1.0e6, (self.samp_rate*(1.0/self.block_size))/1.0e6)
self.qtgui_vector_sink_f_coh.set_x_axis((-0.5*self.samp_rate + self.fcarrier)/1.0e6, (self.samp_rate*(1.0/self.block_size))/1.0e6)
self.qtgui_vector_sink_f_conj_coh.set_x_axis((-0.5*self.samp_rate)/1.0e6, (self.samp_rate*(1.0/self.block_size))/1.0e6)
self.qtgui_vector_sink_scf.set_x_axis((-0.5*self.samp_rate + self.fcarrier)/1.0e6, (self.samp_rate*(1.0/self.block_size))/1.0e6)
def get_fcarrier(self):
return self.fcarrier
def set_fcarrier(self, fcarrier):
self.fcarrier = fcarrier
self.csp_fsm_conj_coh_0.set_fcarrier(self.fcarrier)
self.csp_fsm_conj_core_1.set_fcarrier(self.fcarrier)
self.dsss_255_cms_0.set_out_fc(self.fcarrier)
self.qtgui_freq_sink_x_0.set_frequency_range(self.fcarrier, self.samp_rate)
self.qtgui_vector_sink_f_coh.set_x_axis((-0.5*self.samp_rate + self.fcarrier)/1.0e6, (self.samp_rate*(1.0/self.block_size))/1.0e6)
self.qtgui_vector_sink_scf.set_x_axis((-0.5*self.samp_rate + self.fcarrier)/1.0e6, (self.samp_rate*(1.0/self.block_size))/1.0e6)
def get_parameter_0(self):
return self.parameter_0
def set_parameter_0(self, parameter_0):
self.parameter_0 = parameter_0
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.blocks_throttle_0.set_sample_rate(self.samp_rate)
self.csp_fsm_coh_1.set_samp_rate(self.samp_rate)
self.csp_fsm_coh_2.set_samp_rate(self.samp_rate)
self.csp_fsm_coh_3.set_samp_rate(self.samp_rate)
self.csp_fsm_conj_coh_0.set_samp_rate(self.samp_rate)
self.csp_fsm_conj_core_1.set_samp_rate(self.samp_rate)
self.csp_fsm_core_1.set_samp_rate(self.samp_rate)
self.csp_fsm_core_2.set_samp_rate(self.samp_rate)
self.csp_fsm_core_3.set_samp_rate(self.samp_rate)
self.dsss_255_cms_0.set_sink_rate(self.samp_rate)
self.qtgui_freq_sink_x_0.set_frequency_range(self.fcarrier, self.samp_rate)
self.qtgui_vector_sink_conj_scf.set_x_axis((-0.5*self.samp_rate)/1.0e6, (self.samp_rate*(1.0/self.block_size))/1.0e6)
self.qtgui_vector_sink_f_coh.set_x_axis((-0.5*self.samp_rate + self.fcarrier)/1.0e6, (self.samp_rate*(1.0/self.block_size))/1.0e6)
self.qtgui_vector_sink_f_conj_coh.set_x_axis((-0.5*self.samp_rate)/1.0e6, (self.samp_rate*(1.0/self.block_size))/1.0e6)
self.qtgui_vector_sink_scf.set_x_axis((-0.5*self.samp_rate + self.fcarrier)/1.0e6, (self.samp_rate*(1.0/self.block_size))/1.0e6)
def get_smooth_width_percent(self):
return self.smooth_width_percent
def set_smooth_width_percent(self, smooth_width_percent):
self.smooth_width_percent = smooth_width_percent
self.set_smooth_width_samples(int(self.block_size * self.smooth_width_percent / 100.0))
def get_smooth_width_samples(self):
return self.smooth_width_samples
def set_smooth_width_samples(self, smooth_width_samples):
self.smooth_width_samples = smooth_width_samples
self.csp_fsm_conj_core_1.set_smooth_width_samples(self.smooth_width_samples)
self.csp_fsm_core_1.set_smooth_width_samples(self.smooth_width_samples)
self.csp_fsm_core_2.set_smooth_width_samples(self.smooth_width_samples)
self.csp_fsm_core_3.set_smooth_width_samples(self.smooth_width_samples)
self.csp_fsm_psd_blocks_conj.set_smooth_width_samples(self.smooth_width_samples)
self.csp_fsm_psd_blocks_normal.set_smooth_width_samples(self.smooth_width_samples)
def get_resamp_factor_up(self):
return self.resamp_factor_up
def set_resamp_factor_up(self, resamp_factor_up):
self.resamp_factor_up = resamp_factor_up
self.dsss_255_cms_0.set_resamp_factor_up(self.resamp_factor_up)
def get_resamp_factor_down(self):
return self.resamp_factor_down
def set_resamp_factor_down(self, resamp_factor_down):
self.resamp_factor_down = resamp_factor_down
self.dsss_255_cms_0.set_resamp_factor_down(self.resamp_factor_down)
def get_quad_override_bpsk(self):
return self.quad_override_bpsk
def set_quad_override_bpsk(self, quad_override_bpsk):
self.quad_override_bpsk = quad_override_bpsk
self.dsss_255_cms_0.set_quad_override(self.quad_override_bpsk)
def get_log2_M_bpsk(self):
return self.log2_M_bpsk
def set_log2_M_bpsk(self, log2_M_bpsk):
self.log2_M_bpsk = log2_M_bpsk
self.dsss_255_cms_0.set_log2_M(self.log2_M_bpsk)
def argument_parser():
parser = ArgumentParser()
parser.add_argument(
"--alpha1", dest="alpha1", type=eng_float, default="49.0196k",
help="Set alpha1 [default=%(default)r]")
parser.add_argument(
"--alpha2", dest="alpha2", type=eng_float, default="98.0392k",
help="Set alpha2 [default=%(default)r]")
parser.add_argument(
"--alpha3", dest="alpha3", type=eng_float, default="0.0",
help="Set alpha3 [default=%(default)r]")
parser.add_argument(
"--beta1", dest="beta1", type=eng_float, default="3.88005G",
help="Set beta1 [default=%(default)r]")
parser.add_argument(
"--block-size", dest="block_size", type=intx, default=65536,
help="Set block_size [default=%(default)r]")
parser.add_argument(
"--fcarrier", dest="fcarrier", type=eng_float, default="1.94G",
help="Set fcarrier [default=%(default)r]")
parser.add_argument(
"--samp-rate", dest="samp_rate", type=eng_float, default="25.0M",
help="Set samp_rate [default=%(default)r]")
parser.add_argument(
"--smooth-width-percent", dest="smooth_width_percent", type=eng_float, default="1.0",
help="Set smooth_width_percent [default=%(default)r]")
return parser
def main(top_block_cls=csp_fsm_live_data, options=None):
if options is None:
options = argument_parser().parse_args()
if StrictVersion("4.5.0") <= StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
style = gr.prefs().get_string('qtgui', 'style', 'raster')
Qt.QApplication.setGraphicsSystem(style)
qapp = Qt.QApplication(sys.argv)
tb = top_block_cls(alpha1=options.alpha1, alpha2=options.alpha2, alpha3=options.alpha3, beta1=options.beta1, block_size=options.block_size, fcarrier=options.fcarrier, samp_rate=options.samp_rate, smooth_width_percent=options.smooth_width_percent)
tb.start()
tb.show()
def sig_handler(sig=None, frame=None):
Qt.QApplication.quit()
signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
timer = Qt.QTimer()
timer.start(500)
timer.timeout.connect(lambda: None)
def quitting():
tb.stop()
tb.wait()
qapp.aboutToQuit.connect(quitting)
qapp.exec_()
if __name__ == '__main__':
main()
# -*- coding: utf-8 -*-
#
# SPDX-License-Identifier: GPL-3.0
#
# GNU Radio Python Flow Graph
# Title: Csp Fsm Core
# Author: Chad M. Spooner
# GNU Radio version: 3.8.1.0
from gnuradio import blocks
from gnuradio import gr
from gnuradio.filter import firdes
import sys
import signal
class csp_fsm_core(gr.hier_block2):
def __init__(self, alpha=0, block_size=65536, samp_rate=1000000, smooth_width_samples=100):
gr.hier_block2.__init__(
self, "Csp Fsm Core",
gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
gr.io_signaturev(2, 2, [gr.sizeof_float*block_size, gr.sizeof_float*block_size]),
)
##################################################
# Parameters
##################################################
self.alpha = alpha
self.block_size = block_size
self.samp_rate = samp_rate
self.smooth_width_samples = smooth_width_samples
##################################################
# Variables
##################################################
self.alpha_up = alpha_up = round(block_size*(alpha/samp_rate))
##################################################
# Blocks
##################################################
self.blocks_stream_to_vector_0_0_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, block_size)
self.blocks_nlog10_ff_0 = blocks.nlog10_ff(10, block_size, 0)
self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1)
self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_cc(1.0/block_size)
self.blocks_moving_average_xx_0_0 = blocks.moving_average_cc(smooth_width_samples, 1.0/smooth_width_samples, 4000, 1)
self.blocks_delay_0_1_1 = blocks.delay(gr.sizeof_gr_complex*1, block_size - int(smooth_width_samples/2.0))
self.blocks_delay_0_1_0 = blocks.delay(gr.sizeof_gr_complex*1, block_size - int(alpha_up/2.0))
self.blocks_delay_0_0 = blocks.delay(gr.sizeof_gr_complex*1, int(alpha_up + 0.5))
self.blocks_conjugate_cc_0_0 = blocks.conjugate_cc()
self.blocks_complex_to_mag_0_0 = blocks.complex_to_mag(block_size)
##################################################
# Connections
##################################################
self.connect((self.blocks_complex_to_mag_0_0, 0), (self.blocks_nlog10_ff_0, 0))
self.connect((self.blocks_complex_to_mag_0_0, 0), (self, 1))
self.connect((self.blocks_conjugate_cc_0_0, 0), (self.blocks_multiply_xx_0_0, 0))
self.connect((self.blocks_delay_0_0, 0), (self.blocks_multiply_xx_0_0, 1))
self.connect((self.blocks_delay_0_1_0, 0), (self.blocks_moving_average_xx_0_0, 0))
self.connect((self.blocks_delay_0_1_1, 0), (self.blocks_stream_to_vector_0_0_0, 0))
self.connect((self.blocks_moving_average_xx_0_0, 0), (self.blocks_delay_0_1_1, 0))
self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.blocks_delay_0_1_0, 0))
self.connect((self.blocks_multiply_xx_0_0, 0), (self.blocks_multiply_const_vxx_0_0, 0))
self.connect((self.blocks_nlog10_ff_0, 0), (self, 0))
self.connect((self.blocks_stream_to_vector_0_0_0, 0), (self.blocks_complex_to_mag_0_0, 0))
self.connect((self, 0), (self.blocks_conjugate_cc_0_0, 0))
self.connect((self, 0), (self.blocks_delay_0_0, 0))
def get_alpha(self):
return self.alpha
def set_alpha(self, alpha):
self.alpha = alpha
self.set_alpha_up(round(self.block_size*(self.alpha/self.samp_rate)))
def get_block_size(self):
return self.block_size
def set_block_size(self, block_size):
self.block_size = block_size
self.set_alpha_up(round(self.block_size*(self.alpha/self.samp_rate)))
self.blocks_delay_0_1_0.set_dly(self.block_size - int(self.alpha_up/2.0))
self.blocks_delay_0_1_1.set_dly(self.block_size - int(self.smooth_width_samples/2.0))
self.blocks_multiply_const_vxx_0_0.set_k(1.0/self.block_size)
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.set_alpha_up(round(self.block_size*(self.alpha/self.samp_rate)))
def get_smooth_width_samples(self):
return self.smooth_width_samples
def set_smooth_width_samples(self, smooth_width_samples):
self.smooth_width_samples = smooth_width_samples
self.blocks_delay_0_1_1.set_dly(self.block_size - int(self.smooth_width_samples/2.0))
self.blocks_moving_average_xx_0_0.set_length_and_scale(self.smooth_width_samples, 1.0/self.smooth_width_samples)
def get_alpha_up(self):
return self.alpha_up
def set_alpha_up(self, alpha_up):
self.alpha_up = alpha_up
self.blocks_delay_0_0.set_dly(int(self.alpha_up + 0.5))
self.blocks_delay_0_1_0.set_dly(self.block_size - int(self.alpha_up/2.0))
Jeff:
I've attached the python produced by the companion for the main flowgraph (csp_fsm_live_data.grc) and one of the hier blocks (csp_fsm_core.grc).
Yes, all the hier blocks in csp_fsm_live_data.grc are mine.
C
Ok, I see what you mean. Then maybe there's a difference on how parameter setting propagates/chains, e.g., what code is spit out by set_x() in GR 3.8. What does the generated code look like? Can't see anything from the GRC files ... I assume the csp_fsm_ blocks are yours?
On Wed, Aug 12, 2020 at 12:07 PM Chad Spooner <cmspooner@nwra.com> wrote:
Jeff:
Thanks for the tip on division. I can't find any division-related flaws.
The consistent thing about the errors from the companion is that the source vector length is always reported as the number of bytes in the hier block using the default parameter block_size inside the heir block, not the value of block_size that is actually specified in the csp_fsm_live_data.grc flowgraph. As I change block_size in that flowgraph, the reported vector size of the QT Vector Sink blocks changes accordingly (and correctly) in the error messages, but the reported vector size for my hier blocks is always equal to the size for the value of the block_size parameter inside the hier flowgraph.
It's as if the companion can't tell that the hier block is getting the parameters set in the main flowgraph. However, as you can see in the images below, the companion displays the block_size parameter correctly for each component of the flowgraph.
C
On 8/11/20 5:30 PM, Jeff Long wrote:
131072 is the number of bytes for 32768 float samples.
When numbers change going from 3.7 to 3.8, check Python division. The change in division operators (/ vs //) between Python2 and Python3 may change the result of Python expressions used in parameters.
On Tue, Aug 11, 2020 at 8:02 PM Chad Spooner <cmspooner@nwra.com> wrote:
All:
Thanks to Derek Kozel and Cinaed Simson for helping me to compile gnuradio 3.8.1.0 under Ubuntu 18.04.5.
I've been trying to migrate my flowgraphs from 3.7 to 3.8 with much success, but I have two stubborn problems I can't solve.
1. For the attached flowgraph csp_fsm_live_data.grc, I've created multiple hier blocks and strung them together to produce a block-oriented signal processor. All the heir blocks get the parameter 'block_size' and I also use 'block_size' as the vector length in some vector blocks of GRC. All of this worked fine in GR 3.7. I could change the block_size parameter in csp_fsm_live_data.grc and the processing would reflect the change correctly.
In 3.8, the flowgraph will operate correctly only if the block_size parameter in csp_fsm_live_data.grc matches the default block_size parameter in the various heirblocks. When I change block_size, I end up with an error involving the final connection of some of the heir blocks to QT Vector Sink Blocks. When all is well (block_size matches default in all heir blocks), the relevant portion of the flowgraph looks like this:
and when I change it from the default of 65536 to 32768, it looks like this:
The only errors reported by the companion are related to the red connection arrows:
I can't figure out where the '262144' and '131072' numbers are coming from. They are multiples of two times the block_size of 32768 of course, but I can't see how they are used or are relevant.
2. Another flowgraph, bank_of_dsss_gens_sleuth.grc (also attached), generates various DSSS-like signals and switches between them using the Stream Mux block. The output of the GR 3.8 version appears to be correct, but the flowgraph does not run for very long before overwhelming the companion and forcing me to kill it. I get the warning that gnuradio-companion has become unresponsive (wait or force stop). Looking at top while I run it, it does not use more than about 2.5 of my 8 cores. This flowgraph also ran very well (indefinitely) in GR 3.7 on the same hardware (computer) running the same OS. I get the feeling there has been some kind of relevant change to the use of multiple threads, but I can't figure out how to convince the companion to use as much CPU as it needs to (as it did before).
C
-- Chad M. Spooner, PhD NorthWest Research Associates 301 Webster Street Monterey, CA 93940 cmspooner@nwra.com 831 582 4904 cyclostationary.blog-- Chad M. Spooner, PhD NorthWest Research Associates 301 Webster Street Monterey, CA 93940 cmspooner@nwra.com 831 582 4904 cyclostationary.blog
-- Chad M. Spooner, PhD NorthWest Research Associates 301 Webster Street Monterey, CA 93940 cmspooner@nwra.com 831 582 4904 cyclostationary.blog



No comments:
Post a Comment