From af6398eb6e3273c005312939fb6d965f8a50baed Mon Sep 17 00:00:00 2001 From: FOSSEE Date: Tue, 10 Mar 2015 17:11:34 +0530 Subject: Plot-sink added --- gr-input/grc/CMakeLists.txt | 6 + gr-input/grc/plot_sink.xml | 112 +++++++++++++++ gr-input/python/CMakeLists.txt | 16 +++ gr-input/python/matplotsink.py | 312 +++++++++++++++++++++++++++++++++++++++++ gr-input/python/plot_sink.py | 57 ++++++++ 5 files changed, 503 insertions(+) create mode 100755 gr-input/grc/plot_sink.xml create mode 100755 gr-input/python/matplotsink.py create mode 100755 gr-input/python/plot_sink.py diff --git a/gr-input/grc/CMakeLists.txt b/gr-input/grc/CMakeLists.txt index 1b604feb2..61b317f77 100644 --- a/gr-input/grc/CMakeLists.txt +++ b/gr-input/grc/CMakeLists.txt @@ -69,3 +69,9 @@ install(FILES ) +install(FILES + plot_sink.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "input_python" +) + diff --git a/gr-input/grc/plot_sink.xml b/gr-input/grc/plot_sink.xml new file mode 100755 index 000000000..07022ea07 --- /dev/null +++ b/gr-input/grc/plot_sink.xml @@ -0,0 +1,112 @@ + + + + Plot Sink + plot_sink + Single Board Heater System + import gnuradio.input.plot_sink + #set $parent = $notebook() and 'self.%s.GetPage(%s)'%$notebook() or 'self' +gnuradio.input.plot_sink.plot_sink_$(type.fcn)( + $(parent).GetWin(), + title=$title, + vlen=$vlen, + decim=$decim, + gsz=$gsz, + zoom=$zoom, +) +#if not $grid_pos() +$(parent).Add(self.$(id).win) +#else +$(parent).GridAdd(self.$(id).win, $(', '.join(map(str, $grid_pos())))) +#end if + set_decim($decim) + + Type + type + enum + + + + + + + + Title + title + Scope Plot + string + + + Decimation + decim + 1 + int + + + Vec Length + vlen + 1 + int + + + + Graph size + gsz + 50 + int + + + History Required + zoom + 0 + int + + + + Grid Position + grid_pos + + grid_pos + + + Notebook + notebook + + notebook + + + $vlen > 0 + + in + $type + $vlen + + +Read samples from the input stream and \ +plot one in every decimation samples to the plot sink. + + diff --git a/gr-input/python/CMakeLists.txt b/gr-input/python/CMakeLists.txt index 77ac986ac..7c73fc59f 100644 --- a/gr-input/python/CMakeLists.txt +++ b/gr-input/python/CMakeLists.txt @@ -92,6 +92,20 @@ GR_PYTHON_INSTALL( COMPONENT "input_python" ) +GR_PYTHON_INSTALL( + FILES + plot_sink.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + matplotsink.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + ######################################################################## # Handle the unit tests @@ -104,6 +118,8 @@ list(APPEND GR_TEST_PYTHON_DIRS list(APPEND GR_TEST_TARGET_DEPS gnuradio-input) include(GrTest) + + file(GLOB py_qa_test_files "qa_*.py") foreach(py_qa_test_file ${py_qa_test_files}) get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) diff --git a/gr-input/python/matplotsink.py b/gr-input/python/matplotsink.py new file mode 100755 index 000000000..105009b4d --- /dev/null +++ b/gr-input/python/matplotsink.py @@ -0,0 +1,312 @@ +""" +$$ + +Modified for working as a GNU Radio block +Rakesh Peter (rakesh.peter@gmail.com) +Last modified: 07.05.2010 + +$$ + +This demo demonstrates how to draw a dynamic mpl (matplotlib) +plot in a wxPython application. + +It allows "live" plotting as well as manual zooming to specific +regions. + +Both X and Y axes allow "auto" or "manual" settings. For Y, auto +mode sets the scaling of the graph to see all the data points. +For X, auto mode makes the graph "follow" the data. Set it X min +to manual 0 to always see the whole data from the beginning. + +Note: press Enter in the 'manual' text box to make a new value +affect the plot. + +Eli Bendersky (eliben@gmail.com) +License: this code is in the public domain +Last modified: 31.07.2008 +""" + +import os +import pprint +import random +import sys +import wx +import gnuradio.grc.gui +from gnuradio.grc.gui import Actions,ActionHandler +# The recommended way to use wx with mpl is with the WXAgg +# backend. +# +import matplotlib +import matplotlib.pyplot as plt +import matplotlib.animation as animation +#matplotlib.use('WXAgg') +from matplotlib.figure import Figure +from matplotlib.backends.backend_wxagg import \ + FigureCanvasWxAgg as FigCanvas, \ + NavigationToolbar2WxAgg as NavigationToolbar +import numpy as np +import pylab + + +class DataGen(object): + """ A silly class that generates pseudo-random data for + display in the plot. + """ + def __init__(self, init=50): + self.data = self.init = init + + def next(self): + self._recalc_data() + #return self.data + return [0.0,1.1,2.2,3.3] + + def _recalc_data(self): + delta = random.uniform(-0.5, 0.5) + r = random.random() + + if r > 0.9: + self.data += delta * 15 + elif r > 0.8: + # attraction to the initial value + delta += (0.5 if self.init > self.data else -0.5) + self.data += delta + else: + self.data += delta + + + +class matplotsink(wx.Panel): + + def __init__(self, parent, title, queue,gsz,zoom): + wx.Panel.__init__(self, parent, wx.SIMPLE_BORDER) + + self.gsz = gsz + self.parent = parent + self.title = title + self.q = queue + self.zoom=zoom + self.paused = False + +# self.create_menu() +# self.create_status_bar() + self.create_main_panel() + + + def create_menu(self): + self.menubar = wx.MenuBar() + + menu_file = wx.Menu() + m_expt = menu_file.Append(-1, "&Save plot\tCtrl-S", "Save plot to file") + self.Bind(wx.EVT_MENU, self.on_save_plot, m_expt) + menu_file.AppendSeparator() + m_exit = menu_file.Append(-1, "E&xit\tCtrl-X", "Exit") + self.Bind(wx.EVT_MENU, self.on_exit, m_exit) + self.menubar.Append(menu_file, "&File") + self.SetMenuBar(self.menubar) + + + def create_main_panel(self): + self.panel = self + + self.init_plot() + self.canvas = FigCanvas(self.panel, -1, self.fig) + self.scroll_range = 400 + self.canvas.SetScrollbar(wx.HORIZONTAL,0,5,self.scroll_range) + self.canvas.Bind(wx.EVT_SCROLLWIN,self.OnScrollEvt) + + + self.pause_button = wx.Button(self.panel, -1, "Pause") + self.Bind(wx.EVT_BUTTON, self.on_pause_button, self.pause_button) + self.Bind(wx.EVT_UPDATE_UI, self.on_update_pause_button, self.pause_button) + + self.cb_grid = wx.CheckBox(self.panel, -1, + "Show Grid", + style=wx.ALIGN_RIGHT) + self.Bind(wx.EVT_CHECKBOX, self.on_cb_grid, self.cb_grid) + self.cb_grid.SetValue(True) + + self.cb_xlab = wx.CheckBox(self.panel, -1, + "Show X labels", + style=wx.ALIGN_RIGHT) + self.Bind(wx.EVT_CHECKBOX, self.on_cb_xlab, self.cb_xlab) + self.cb_xlab.SetValue(True) + + self.hbox1 = wx.BoxSizer(wx.HORIZONTAL) + self.hbox1.Add(self.pause_button, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) + self.hbox1.AddSpacer(20) + self.hbox1.Add(self.cb_grid, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) + self.hbox1.AddSpacer(10) + self.hbox1.Add(self.cb_xlab, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) + + + self.vbox = wx.BoxSizer(wx.VERTICAL) + self.vbox.Add(self.canvas, 1, flag=wx.LEFT | wx.TOP | wx.GROW) + self.vbox.Add(self.hbox1, 0, flag=wx.ALIGN_LEFT | wx.TOP) + + self.panel.SetSizer(self.vbox) + self.vbox.Fit(self) + self.ani=animation.FuncAnimation(self.fig,self.draw_plot,interval=100) + + def OnScrollEvt(self,event): + self.i_start = event.GetPosition() + self.i_end = self.i_window + event.GetPosition() + self.draw_plot(0) + + def create_status_bar(self): + self.statusbar = self.CreateStatusBar() + + def draw_test(self,event): + self.xar=np.arange(len(self.q.queue)) + self.yar=np.array(self.q.queue) + self.axes.plot(self.xar,self.yar) + + def init_plot(self): + self.dpi = 100 + self.fig = Figure((3.0, 3.0), dpi=self.dpi) + self.fig.set_size_inches(7.0,4.0) + self.fig.set_dpi(self.dpi) + + self.axes = self.fig.add_subplot(111) + self.axes.set_axis_bgcolor('black') + self.axes.set_title(self.title, size=12) + + pylab.setp(self.axes.get_xticklabels(), fontsize=8) + pylab.setp(self.axes.get_yticklabels(), fontsize=8) + self.i_window = self.gsz + self.i_start = 0 + self.i_end = self.i_start + self.i_window + # plot the data as a line series, and save the reference + # to the plotted line series + # + self.plot_data = self.axes.plot( + [], + linewidth=1, + color=(1, 1, 0), + )[0] + + + def draw_plot(self,event): + """ Redraws the plot + """ + if len(list(self.q.queue))>1 and not self.paused: + + if self.zoom: + xmax = len(list(self.q.queue)) if len(list(self.q.queue)) > 50 else 50 + + xmin = xmax - 50 + # for ymin and ymax, find the minimal and maximal values + # in the data set and add a mininal margin. + # + # note that it's easy to change this scheme to the + # minimal/maximal value in the current display, and not + # the whole data set. + # + ymin = round(min(list(self.q.queue)), 0) - 1 + + ymax = round(max(list(self.q.queue)), 0) + 1 + + self.axes.set_xbound(lower=xmin, upper=xmax) + self.axes.set_ybound(lower=ymin, upper=ymax) + + # anecdote: axes.grid assumes b=True if any other flag is + # given even if b is set to False. + # so just passing the flag into the first statement won't + # work. + # + if self.cb_grid.IsChecked(): + self.axes.grid(True, color='gray') + else: + self.axes.grid(False) + + # Using setp here is convenient, because get_xticklabels + # returns a list over which one needs to explicitly + # iterate, and setp already handles this. + # + pylab.setp(self.axes.get_xticklabels(), + visible=self.cb_xlab.IsChecked()) + + + self.plot_data.set_xdata(np.arange(len(list(self.q.queue)))) + self.plot_data.set_ydata(np.array(list(self.q.queue))) + self.canvas.draw() + + else: + if self.cb_grid.IsChecked(): + self.axes.grid(True, color='gray') + else: + self.axes.grid(False) + + # Using setp here is convenient, because get_xticklabels + # returns a list over which one needs to explicitly + # iterate, and setp already handles this. + + pylab.setp(self.axes.get_xticklabels(), + visible=self.cb_xlab.IsChecked()) + + self.plot_data.set_xdata(np.arange(len(list(self.q.queue)))[self.i_start:self.i_end]) + self.plot_data.set_ydata(np.array(list(self.q.queue))[self.i_start:self.i_end]) + self.axes.set_xlim(min(np.arange(len(list(self.q.queue)))[self.i_start:self.i_end]),max(np.arange(len(list(self.q.queue)))[self.i_start:self.i_end])) + # if self.zoom: + self.axes.set_ylim(min(np.array(list(self.q.queue))),max(np.array(list(self.q.queue)))) + + self.canvas.draw() + + + + def on_pause_button(self, event): + self.paused = not self.paused + + def on_update_pause_button(self, event): + label = "Resume" if self.paused else "Pause" + self.pause_button.SetLabel(label) + + def on_cb_grid(self, event): + self.draw_plot(0) + + def on_cb_xlab(self, event): + self.draw_plot(0) + + def on_save_plot(self, event): + file_choices = "PNG (*.png)|*.png" + + dlg = wx.FileDialog( + self, + message="Save plot as...", + defaultDir=os.getcwd(), + defaultFile="plot.png", + wildcard=file_choices, + style=wx.SAVE) + + if dlg.ShowModal() == wx.ID_OK: + path = dlg.GetPath() + self.canvas.print_figure(path, dpi=self.dpi) + self.flash_status_message("Saved to %s" % path) + + def on_redraw_timer(self, event): + # if paused do not add data, but still redraw the plot + # (to respond to scale modifications, grid change, etc.) + # + if not self.paused: + self.data += self.datagen.next() + self.draw_plot(0) + + + def on_exit(self, event): + self.Destroy() + + def flash_status_message(self, msg, flash_len_ms=1500): + self.statusbar.SetStatusText(msg) + self.timeroff = wx.Timer(self) + self.Bind( + wx.EVT_TIMER, + self.on_flash_status_off, + self.timeroff) + self.timeroff.Start(flash_len_ms, oneShot=True) + + def on_flash_status_off(self, event): + self.statusbar.SetStatusText('') + + + + + diff --git a/gr-input/python/plot_sink.py b/gr-input/python/plot_sink.py new file mode 100755 index 000000000..1c1def3fc --- /dev/null +++ b/gr-input/python/plot_sink.py @@ -0,0 +1,57 @@ +# Hacked from blks2/variable_sink.py +# Requires modified Matplotsink code + +from gnuradio import gr +import threading +import numpy +import matplotsink +import Queue + +class _plot_sink_base(gr.hier_block2, threading.Thread): + """ + The thread polls the message queue for values and writes to matplotsink callback + """ + + def __init__(self, parent, title, vlen, decim,gsz,zoom): + self._vlen = vlen + self._parent = parent + self._title = title + print "Initing block: %s" % title + + self.plotQueue = Queue.Queue() + self.win = matplotsink.matplotsink(parent,title, self.plotQueue,gsz,zoom) + + self._item_size = self._size*self._vlen + #init hier block + gr.hier_block2.__init__( + self, 'plot_sink', + gr.io_signature(1, 1, self._item_size), + gr.io_signature(0, 0, 0), + ) + #create blocks + self._msgq = gr.msg_queue(2) + message_sink = gr.message_sink(self._item_size, self._msgq, False) + #connect + self.connect(self, message_sink) + #setup thread + threading.Thread.__init__(self) + self.setDaemon(True) + self.start() + + def set_decim(self, decim): self._decimator.set_n(decim) + + def run(self): + while True: #truncate to item size, convert to array, callback + msg = self._msgq.delete_head().to_string()[-self._item_size:] + arr = map(self._cast, numpy.fromstring(msg, self._numpy)) + print "Sending value:" , arr + self.plotQueue.put(self._vlen > 1 and arr or arr[0]) + + def print_callback(self, array): + print array + +class plot_sink_b(_plot_sink_base): _numpy, _size, _cast = numpy.int8, gr.sizeof_char, int +class plot_sink_s(_plot_sink_base): _numpy, _size, _cast = numpy.int16, gr.sizeof_short, int +class plot_sink_i(_plot_sink_base): _numpy, _size, _cast = numpy.int32, gr.sizeof_int, int +class plot_sink_f(_plot_sink_base): _numpy, _size, _cast = numpy.float32, gr.sizeof_float, float +class plot_sink_c(_plot_sink_base): _numpy, _size, _cast = numpy.complex64, gr.sizeof_gr_complex, complex -- cgit From 92326794e39e1753f5fcb20715c57ea0f537752e Mon Sep 17 00:00:00 2001 From: Ashwini Date: Tue, 10 Mar 2015 17:23:13 +0530 Subject: Deleted --- gr-input/CMakeLists.txt | 55 ---- gr-input/doc/CMakeLists.txt | 23 -- gr-input/doc/README.input | 2 - gr-input/doc/input.dox | 29 -- gr-input/grc/CMakeLists.txt | 77 ----- gr-input/grc/Calculation_Calculator.xml | 65 ----- gr-input/grc/Calculation_Roots.xml | 34 --- gr-input/grc/Transfer_Function_Denominator.xml | 33 --- gr-input/grc/Transfer_Function_Numerator.xml | 33 --- .../grc/Transfer_Function_Transfer_Function.xml | 66 ----- gr-input/grc/Transfer_function_Denominator.xml | 49 ---- gr-input/grc/Transfer_function_Numerator.xml | 48 ---- gr-input/grc/Transfer_function_Response.xml | 80 ------ gr-input/grc/plot_sink.xml | 112 -------- gr-input/grc/plzr_plot.xml | 37 --- gr-input/grc/ramp_source.xml | 87 ------ gr-input/grc/step_source.xml | 88 ------ gr-input/python/CMakeLists.txt | 128 --------- gr-input/python/Calculator.py | 99 ------- gr-input/python/Denominator.py | 91 ------ gr-input/python/Numerator.py | 90 ------ gr-input/python/Response.py | 98 ------- gr-input/python/Roots.py | 126 --------- gr-input/python/Transfer_Function.py | 100 ------- gr-input/python/__init__.py | 53 ---- gr-input/python/gr_ramp_source.py | 46 --- gr-input/python/gr_step_source.py | 43 --- gr-input/python/matplotsink.py | 312 --------------------- gr-input/python/plot_sink.py | 57 ---- gr-input/python/plzr_plot.py | 71 ----- gr-input/python/ramp_hierblock.py | 19 -- gr-input/python/step_hierblock.py | 22 -- 32 files changed, 2273 deletions(-) delete mode 100644 gr-input/CMakeLists.txt delete mode 100644 gr-input/doc/CMakeLists.txt delete mode 100644 gr-input/doc/README.input delete mode 100644 gr-input/doc/input.dox delete mode 100644 gr-input/grc/CMakeLists.txt delete mode 100644 gr-input/grc/Calculation_Calculator.xml delete mode 100644 gr-input/grc/Calculation_Roots.xml delete mode 100644 gr-input/grc/Transfer_Function_Denominator.xml delete mode 100644 gr-input/grc/Transfer_Function_Numerator.xml delete mode 100644 gr-input/grc/Transfer_Function_Transfer_Function.xml delete mode 100644 gr-input/grc/Transfer_function_Denominator.xml delete mode 100644 gr-input/grc/Transfer_function_Numerator.xml delete mode 100644 gr-input/grc/Transfer_function_Response.xml delete mode 100755 gr-input/grc/plot_sink.xml delete mode 100644 gr-input/grc/plzr_plot.xml delete mode 100644 gr-input/grc/ramp_source.xml delete mode 100644 gr-input/grc/step_source.xml delete mode 100644 gr-input/python/CMakeLists.txt delete mode 100644 gr-input/python/Calculator.py delete mode 100644 gr-input/python/Denominator.py delete mode 100644 gr-input/python/Numerator.py delete mode 100644 gr-input/python/Response.py delete mode 100644 gr-input/python/Roots.py delete mode 100644 gr-input/python/Transfer_Function.py delete mode 100644 gr-input/python/__init__.py delete mode 100644 gr-input/python/gr_ramp_source.py delete mode 100644 gr-input/python/gr_step_source.py delete mode 100755 gr-input/python/matplotsink.py delete mode 100755 gr-input/python/plot_sink.py delete mode 100644 gr-input/python/plzr_plot.py delete mode 100644 gr-input/python/ramp_hierblock.py delete mode 100644 gr-input/python/step_hierblock.py diff --git a/gr-input/CMakeLists.txt b/gr-input/CMakeLists.txt deleted file mode 100644 index 50babee29..000000000 --- a/gr-input/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright 2012 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. - -######################################################################## -# Setup dependencies -######################################################################## -#include(GrBoost) - -#find_package(SCIGENW3f) - -######################################################################## -# Register component -######################################################################## -include(GrComponent) - -GR_REGISTER_COMPONENT("gr-input" ENABLE_GR_INPUT - ENABLE_GRUEL - ENABLE_VOLK - Boost_FOUND - ENABLE_GR_CORE -) - -######################################################################## -# Begin conditional configuration -######################################################################## -if(ENABLE_GR_INPUT) - -######################################################################## -# Add subdirectories -######################################################################## -if(ENABLE_PYTHON) - add_subdirectory(python) - add_subdirectory(grc) -endif(ENABLE_PYTHON) -#add_subdirectory(examples) -add_subdirectory(doc) - - -endif(ENABLE_GR_INPUT) diff --git a/gr-input/doc/CMakeLists.txt b/gr-input/doc/CMakeLists.txt deleted file mode 100644 index b10223aaf..000000000 --- a/gr-input/doc/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright 2012 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. - -install( - FILES README.input - DESTINATION ${GR_PKG_DOC_DIR} -) diff --git a/gr-input/doc/README.input b/gr-input/doc/README.input deleted file mode 100644 index 1bd326897..000000000 --- a/gr-input/doc/README.input +++ /dev/null @@ -1,2 +0,0 @@ -Serial Python block - diff --git a/gr-input/doc/input.dox b/gr-input/doc/input.dox deleted file mode 100644 index 8843d0560..000000000 --- a/gr-input/doc/input.dox +++ /dev/null @@ -1,29 +0,0 @@ -/*! \page page_fft FFT Signal Processing Blocks - -\section Introduction - -This is the gr-scigen package. It contains signal processing blocks to -perform FFTs and FFT-related functionality. - -The Python namespace is in gnuradio.fft, which would be normally -imported as: - -\code - from gnuradio import scigen -\endcode - -See the Doxygen documentation for details about the blocks available -in this package. A quick listing of the details can be found in Python -after importing by using: - -\code - help(scigen) -\endcode - -\section Dependencies - -The scigen blocks require the following dependencies. - -\li fftw3f (>= 3.0) http://www.fftw.org/download.html - -*/ diff --git a/gr-input/grc/CMakeLists.txt b/gr-input/grc/CMakeLists.txt deleted file mode 100644 index 61b317f77..000000000 --- a/gr-input/grc/CMakeLists.txt +++ /dev/null @@ -1,77 +0,0 @@ -# Copyright 2012 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. - -install(FILES - step_source.xml - DESTINATION ${GRC_BLOCKS_DIR} - COMPONENT "input_python" -) - -install(FILES - ramp_source.xml - DESTINATION ${GRC_BLOCKS_DIR} - COMPONENT "input_python" -) - -install(FILES - Transfer_function_Numerator.xml - DESTINATION ${GRC_BLOCKS_DIR} - COMPONENT "input_python" -) - - - -install(FILES - Transfer_function_Denominator.xml - DESTINATION ${GRC_BLOCKS_DIR} - COMPONENT "input_python" -) - - -install(FILES - Transfer_function_Denominator.xml - DESTINATION ${GRC_BLOCKS_DIR} - COMPONENT "input_python" -) - -install(FILES - Transfer_function_Response.xml - DESTINATION ${GRC_BLOCKS_DIR} - COMPONENT "input_python" -) - -install(FILES - Calculation_Roots.xml - DESTINATION ${GRC_BLOCKS_DIR} - COMPONENT "input_python" -) - -install(FILES - Calculation_Calculator.xml - DESTINATION ${GRC_BLOCKS_DIR} - COMPONENT "input_python" -) - - -install(FILES - plot_sink.xml - DESTINATION ${GRC_BLOCKS_DIR} - COMPONENT "input_python" -) - diff --git a/gr-input/grc/Calculation_Calculator.xml b/gr-input/grc/Calculation_Calculator.xml deleted file mode 100644 index 070712f57..000000000 --- a/gr-input/grc/Calculation_Calculator.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - Calculator - Calculation_Calculator - Calculation - import gnuradio.input.Calculator - gnuradio.input.Calculator.Calculator($num_inputs) -self.$(id).set_parameters($Exp,$num_inputs) - - -Expression -Exp -string - - - -Num inputs -num_inputs -1 -int - - - - in0 - float - $num_inputs - - - - - - out - float - - - - -Variable names must be a0,a1,a2 and so on. - -You can use maximum 10 variables per block. - -Example to add 5 variables: - -"a0+a1+a2+a3+a4" - -To perform Exponential(power) calculations on operators use the following: - -a0**a1 - -To perform calculations like sqrt, log or exp use the following: - -sqrt(a4) - -log(a2) - -exp(a8) - - - - diff --git a/gr-input/grc/Calculation_Roots.xml b/gr-input/grc/Calculation_Roots.xml deleted file mode 100644 index 9871cad5a..000000000 --- a/gr-input/grc/Calculation_Roots.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - Roots - Calculation_Roots - Calculation - import gnuradio.input.Roots - gnuradio.input.Roots.Roots($order) - - - Order of transfer function - order - samp_rate - real - - - - - in - float - - - - - - out - float - 2*$order - - diff --git a/gr-input/grc/Transfer_Function_Denominator.xml b/gr-input/grc/Transfer_Function_Denominator.xml deleted file mode 100644 index 5ea581a98..000000000 --- a/gr-input/grc/Transfer_Function_Denominator.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - Denominator - Transfer_Function_Denominator - Transfer Function - import gnuradio.input.Denominator - gnuradio.input.Denominator.Denominator($num_inputs) - - -Num inputs -num_inputs -1 -int - - - - in0 - float - $num_inputs - - - - - - out - float - - diff --git a/gr-input/grc/Transfer_Function_Numerator.xml b/gr-input/grc/Transfer_Function_Numerator.xml deleted file mode 100644 index 8bb367a62..000000000 --- a/gr-input/grc/Transfer_Function_Numerator.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - Numerator - Transfer_Function_Numerator - Transfer Function - import gnuradio.input.Numerator - gnuradio.input.Numerator.Numerator($num_inputs) - - -Num inputs -num_inputs -1 -int - - - - in0 - float - $num_inputs - - - - - - out - float - - diff --git a/gr-input/grc/Transfer_Function_Transfer_Function.xml b/gr-input/grc/Transfer_Function_Transfer_Function.xml deleted file mode 100644 index 203fe4a7b..000000000 --- a/gr-input/grc/Transfer_Function_Transfer_Function.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - Transfer Function - Transfer_Function_Transfer_Function - Transfer Function - import gnuradio.input.Transfer_Function - gnuradio.input.Transfer_Function.Transfer_Function($order,$itype,$tstart,$tstop,$tstep) - - - Order of transfer function - order - 1 - real - - - - - - Input Types - itype - enum - - - - - - -tstart -tstart -0 -real - - - -tstop -tstop -0 -real - - - -tstep -tstep -0 -real - - - - - in - float - 2 - - - - - - out - float - - diff --git a/gr-input/grc/Transfer_function_Denominator.xml b/gr-input/grc/Transfer_function_Denominator.xml deleted file mode 100644 index 2ba936580..000000000 --- a/gr-input/grc/Transfer_function_Denominator.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - Denominator - Transfer_function_Denominator - Transfer_function - import gnuradio.input.Denominator - gnuradio.input.Denominator.Denominator($num_inputs) - - -Order of Transfer Function -num_inputs -1 -int - - - - in0 - float - 1+$num_inputs - - - - - - out - float - - - - -This will take the coefficient values for the Denominator. - -in00 = value of the coefficient of s^0 - -in01 = value of the coefficient of s^1 - -in02 = value of the coefficient of s^2 - -and so on.. - - - - - diff --git a/gr-input/grc/Transfer_function_Numerator.xml b/gr-input/grc/Transfer_function_Numerator.xml deleted file mode 100644 index 1ad34f316..000000000 --- a/gr-input/grc/Transfer_function_Numerator.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - Numerator - Transfer_function_Numerator - Transfer_function - import gnuradio.input.Numerator - gnuradio.input.Numerator.Numerator($num_inputs) - - -Order of Transfer Function -num_inputs -1 -int - - - - in0 - float - 1+$num_inputs - - - - - - out - float - - - - -This will take the coefficient values for the numerator. - -in00 = value of the coefficient of s^0 - -in01 = value of the coefficient of s^1 - -in02 = value of the coefficient of s^2 - -and so on.. - - - - diff --git a/gr-input/grc/Transfer_function_Response.xml b/gr-input/grc/Transfer_function_Response.xml deleted file mode 100644 index cb08a4c2a..000000000 --- a/gr-input/grc/Transfer_function_Response.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - Response - Transfer_function_Response - Transfer_function - import gnuradio.input.Response - gnuradio.input.Response.Response($order,$itype,$tstart,$tstop,$tstep) - - - Order of transfer function - order - 1 - real - - - - - - Input Types - itype - enum - - - - - - -tstart -tstart -0 -real - - - -tstop -tstop -0 -real - - - -tstep -tstep -0 -real - - - - - in - float - 2 - - - - - - out - float - - - - -This block can perfrom three types of system responses. - -Step, Ramp and Impulse. - -in0 = Numerator Equation - -in1 = Denominator Equation - - - - - diff --git a/gr-input/grc/plot_sink.xml b/gr-input/grc/plot_sink.xml deleted file mode 100755 index 07022ea07..000000000 --- a/gr-input/grc/plot_sink.xml +++ /dev/null @@ -1,112 +0,0 @@ - - - - Plot Sink - plot_sink - Single Board Heater System - import gnuradio.input.plot_sink - #set $parent = $notebook() and 'self.%s.GetPage(%s)'%$notebook() or 'self' -gnuradio.input.plot_sink.plot_sink_$(type.fcn)( - $(parent).GetWin(), - title=$title, - vlen=$vlen, - decim=$decim, - gsz=$gsz, - zoom=$zoom, -) -#if not $grid_pos() -$(parent).Add(self.$(id).win) -#else -$(parent).GridAdd(self.$(id).win, $(', '.join(map(str, $grid_pos())))) -#end if - set_decim($decim) - - Type - type - enum - - - - - - - - Title - title - Scope Plot - string - - - Decimation - decim - 1 - int - - - Vec Length - vlen - 1 - int - - - - Graph size - gsz - 50 - int - - - History Required - zoom - 0 - int - - - - Grid Position - grid_pos - - grid_pos - - - Notebook - notebook - - notebook - - - $vlen > 0 - - in - $type - $vlen - - -Read samples from the input stream and \ -plot one in every decimation samples to the plot sink. - - diff --git a/gr-input/grc/plzr_plot.xml b/gr-input/grc/plzr_plot.xml deleted file mode 100644 index 833149ea5..000000000 --- a/gr-input/grc/plzr_plot.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - plzr_plot - plzr_plot - Python_Blocks - import gnuradio.plzr_plot - gnuradio.plzr_plot.plzr_plot($order) - - - Order of transfer function - order - 1 - real - - - - - - - in - float - 2 - - - diff --git a/gr-input/grc/ramp_source.xml b/gr-input/grc/ramp_source.xml deleted file mode 100644 index 5cba29ae7..000000000 --- a/gr-input/grc/ramp_source.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - - Ramp Input - ramp - Sources - - from gnuradio.input import ramp_hierblock as ramp_hierblock - ramp_hierblock.HierBlock($S,$H_Off,$W_Off) - - - IO Type - type - enum - - - - - - - Num Inputs - num_inputs - 1 - int - - - Vec Length - vlen - 1 - int - - - - - slope of ramp - S - 1 - real - - - - height of offset - H_Off - 0 - real - - - - width of offset - W_Off - 0 - real - - - - $num_inputs > 0 - $vlen > 0 - - - out - $(str($type).split('_')[1]) - $vlen - - - -Ramp Input block : - -Slope of ramp is the slope of ramp user wants to generate. -Height of Offset is the height of step user wants to generate as initial signal. -Width of Offset is the length upto which user wants to see the generated offset be. - -Default slope of ramp is 1 unit. -Default height and width of offset is 1 unit. - - - diff --git a/gr-input/grc/step_source.xml b/gr-input/grc/step_source.xml deleted file mode 100644 index 599980030..000000000 --- a/gr-input/grc/step_source.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - Step Input - step_offset - Sources - - from gnuradio.input import step_hierblock as step_hierblock - step_hierblock.HierBlock($S,$H_Off,$W_Off) - - - IO Type - type - enum - - - - - - - Num Inputs - num_inputs - 1 - int - - - Vec Length - vlen - 1 - int - - - - - step size - S - 1 - real - - - - height of offset - H_Off - 0 - real - - - - width of offset - W_Off - 0 - real - - - - - $num_inputs > 0 - $vlen > 0 - - - out - $(str($type).split('_')[1]) - $vlen - - - -Step Input block : - -Step size is the height of step user wants to generate. -Height of Offset is the height of step user wants to generate as initial signal. -Width of Offset is the length upto which user wants to see the generated offset before starting with the height equivalent to step size. - -Default step size is 1 unit. -Default height and width of offset is 1 unit - - - diff --git a/gr-input/python/CMakeLists.txt b/gr-input/python/CMakeLists.txt deleted file mode 100644 index 7c73fc59f..000000000 --- a/gr-input/python/CMakeLists.txt +++ /dev/null @@ -1,128 +0,0 @@ -# Copyright 2012 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# GNU Radio is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# GNU Radio is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with GNU Radio; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. - -######################################################################## -include(GrPython) - -GR_PYTHON_INSTALL( - FILES - __init__.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/input - COMPONENT "input_python" -) - -GR_PYTHON_INSTALL( - FILES - gr_ramp_source.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/input - COMPONENT "input_python" -) - -GR_PYTHON_INSTALL( - FILES - gr_step_source.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/input - COMPONENT "input_python" -) - -GR_PYTHON_INSTALL( - FILES - ramp_hierblock.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/input - COMPONENT "input_python" -) - -GR_PYTHON_INSTALL( - FILES - step_hierblock.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/input - COMPONENT "input_python" -) - -GR_PYTHON_INSTALL( - FILES - Numerator.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/input - COMPONENT "input_python" -) - - -GR_PYTHON_INSTALL( - FILES - Denominator.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/input - COMPONENT "input_python" -) - - -GR_PYTHON_INSTALL( - FILES - Response.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/input - COMPONENT "input_python" -) - -GR_PYTHON_INSTALL( - FILES - Roots.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/input - COMPONENT "input_python" -) - -GR_PYTHON_INSTALL( - FILES - Calculator.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/input - COMPONENT "input_python" -) - -GR_PYTHON_INSTALL( - FILES - plot_sink.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/input - COMPONENT "input_python" -) - -GR_PYTHON_INSTALL( - FILES - matplotsink.py - DESTINATION ${GR_PYTHON_DIR}/gnuradio/input - COMPONENT "input_python" -) - - -######################################################################## -# Handle the unit tests -######################################################################## -if(ENABLE_TESTING) - -list(APPEND GR_TEST_PYTHON_DIRS - ${CMAKE_BINARY_DIR}/gr-input/python -) -list(APPEND GR_TEST_TARGET_DEPS gnuradio-input) - -include(GrTest) - - -file(GLOB py_qa_test_files "qa_*.py") -foreach(py_qa_test_file ${py_qa_test_files}) - get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) - GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B} ${py_qa_test_file}) -endforeach(py_qa_test_file) -endif(ENABLE_TESTING) diff --git a/gr-input/python/Calculator.py b/gr-input/python/Calculator.py deleted file mode 100644 index f2eaf0481..000000000 --- a/gr-input/python/Calculator.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2015 <+YOU OR YOUR COMPANY+>. -# -# This is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# This software is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this software; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -import numpy -from numpy import log -from numpy import exp -from numpy import sqrt -from gnuradio import gr -import time - -class Calculator(gr.sync_block): - """ - docstring for block add_python - """ - def __init__(self,num_inputs): - number = num_inputs - a = [] - for i in range(0,number): - a.append(numpy.float32) -# print "value of a",a - gr.sync_block.__init__(self, - name="Calculator", - in_sig=a, - out_sig=[numpy.float32]) - - #print "I am over slept" - #print len(self.ret_array) - def set_parameters(self,Exp,num_inputs): - self.Exp = Exp - #print "This is EXP", Exp - self.num_inputs = num_inputs - - - def work(self, input_items, output_items): - try: - a0 = input_items[0] - except IndexError: - pass - try: - a1 = input_items[1] - except IndexError: - pass - try: - a2 = input_items[2] - except IndexError: - pass - try: - a3 = input_items[3] - except IndexError: - pass - try: - a4 = input_items[4] - except IndexError: - pass - try: - a5 = input_items[5] - except IndexError: - pass - try: - a6 = input_items[6] - except IndexError: - pass - try: - a7 = input_items[7] - except IndexError: - pass - try: - a8 = input_items[8] - except IndexError: - pass - try: - a9 = input_items[9] - except IndexError: - pass - #out = output_items[0][0] - print "This is self.Exp\n",self.Exp - - output_items[0][:] = eval(self.Exp) - #print "This is the output value\n", output_items[0][0] - #print "I am the oputput add python\n", eval(self.Exp) - return len(output_items[0]) - diff --git a/gr-input/python/Denominator.py b/gr-input/python/Denominator.py deleted file mode 100644 index 5d256f136..000000000 --- a/gr-input/python/Denominator.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2015 <+YOU OR YOUR COMPANY+>. -# -# This is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# This software is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this software; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -import time -import numpy -from gnuradio import gr - -class Denominator(gr.sync_block): - """ - docstring for block add_python - """ - def __init__(self,num_inputs): - number = num_inputs - a = [] - for i in range(0,number): - a.append(numpy.float32) - gr.sync_block.__init__(self, - name="Denominator", - in_sig=a, - out_sig=[numpy.float32]) - - def work(self, input_items, output_items): - b=[0,0,0,0,0,0,0,0,0,0] - try: - b[0] = input_items[0][0] - except IndexError: - pass - try: - b[1] = input_items[1][0] - except IndexError: - pass - try: - b[2] = input_items[2][0] - except IndexError: - pass - try: - b[3] = input_items[3][0] - except IndexError: - pass - try: - b[4] = input_items[4][0] - except IndexError: - pass - try: - b[5] = input_items[5][0] - except IndexError: - pass - try: - b[6] = input_items[6][0] - except IndexError: - pass - try: - b[7] = input_items[7][0] - except IndexError: - pass - try: - b[8] = input_items[8][0] - except IndexError: - pass - try: - b[9] = input_items[9][0] - except IndexError: - pass - - var = len(input_items) - out = output_items[0][:var] - out_arr=[] - time.sleep(0.001) - - for i in range(0,len(input_items)): - out_arr.append(b[i]) - out[:] = out_arr - return len(output_items[0][:]) - diff --git a/gr-input/python/Numerator.py b/gr-input/python/Numerator.py deleted file mode 100644 index 90b44e285..000000000 --- a/gr-input/python/Numerator.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2015 <+YOU OR YOUR COMPANY+>. -# -# This is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# This software is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this software; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -import time -import numpy -from gnuradio import gr - -class Numerator(gr.sync_block): - """ - docstring for block add_python - """ - def __init__(self,num_inputs): - number = num_inputs - a = [] - for i in range(0,number): - a.append(numpy.float32) - gr.sync_block.__init__(self, - name="Numerator", - in_sig=a, - out_sig=[numpy.float32]) - - def work(self, input_items, output_items): - b=[0,0,0,0,0,0,0,0,0,0] - try: - b[0] = input_items[0][0] - except IndexError: - pass - try: - b[1] = input_items[1][0] - except IndexError: - pass - try: - b[2] = input_items[2][0] - except IndexError: - pass - try: - b[3] = input_items[3][0] - except IndexError: - pass - try: - b[4] = input_items[4][0] - except IndexError: - pass - try: - b[5] = input_items[5][0] - except IndexError: - pass - try: - b[6] = input_items[6][0] - except IndexError: - pass - try: - b[7] = input_items[7][0] - except IndexError: - pass - try: - b[8] = input_items[8][0] - except IndexError: - pass - try: - b[9] = input_items[9][0] - except IndexError: - pass - var = len(input_items) - o1 = output_items[0][:var] - out_arr=[] - time.sleep(0.001) - - for i in range(0,len(input_items)): - out_arr.append(b[i]) - o1[:] = out_arr - return len(output_items[0][:]) - diff --git a/gr-input/python/Response.py b/gr-input/python/Response.py deleted file mode 100644 index b895ca77c..000000000 --- a/gr-input/python/Response.py +++ /dev/null @@ -1,98 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2015 <+YOU OR YOUR COMPANY+>. -# -# This is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# This software is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this software; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# -import sys -import time -import numpy -from gnuradio import gr -import sciscipy - -class Response(gr.sync_block): - """ - docstring for block add_python - """ - def __init__(self,order,itype,tstart,tstop,tstep): - sys.setrecursionlimit(2000) - a = [] - self.b = [0.0,0.0,0.0,0.0,0.0,0.0] - [float(i) for i in self.b] - self.c = [0,0,0,0,0,0] - [float(i) for i in self.c] - self.i = 0 - self.order=int(order)+1 - self.itype = itype - self.tstart = tstart - self.tstop = tstop - self.tstep = tstep - gr.sync_block.__init__(self, - name="Response", - in_sig=[numpy.float32,numpy.float32], - out_sig=[numpy.float32]) - - def find_resp(self,b,c): - if (self.itype == 11): - typo = "'imp'" - elif (self.itype == 12): - typo = "'step'" - else: - typo = "t" - string1 = "s=%s; h=syslin('c'," - string2 = str(b[4])+"*s^4+"+str(b[3])+"*s^3+"+str(b[2])+"*s^2+"+str(b[1])+"*s+"+str(b[0])+"," - string3 = str(c[4])+"*s^4+"+str(c[3])+"*s^3+"+str(c[2])+"*s^2+"+str(c[1])+"*s+"+str(c[0])+");" - string4 = "t="+str(self.tstart)+":"+str(self.tstep)+":"+str(self.tstop)+";" - string5 = "deff('u=input(t)','u=50');" - string6 = "r=tf2ss(h); a=csim("+typo+",t,r);" - string = string1+string2+string3+string4+string5+string6 - sciscipy.eval(string) - self.a = sciscipy.read("a") - - def work(self, input_items, output_items): - #sys.setrecursionlimit(1500) - k = self.order - - for i in range(0,k): - - self.b[i] = input_items[0][i] - for n,i in enumerate(self.b): - if i == 'nan': - self.b[n] = 0 - - - print "I am value of b\n",self.b - - - for j in range(0,k): - self.c[j] = input_items[1][j] - - for m,i in enumerate (self.c): - if n == 'nan': - self.c[m] = 0 - - print "I am vlaue of c\n", self.c - self.find_resp(self.b,self.c) - - - out = output_items[0] - self.i+=1 - if self.i >= len(self.a): - self.i = 0 - out[:] = numpy.float32(self.a[self.i]) - return len(output_items[0]) - - diff --git a/gr-input/python/Roots.py b/gr-input/python/Roots.py deleted file mode 100644 index 1057c8d76..000000000 --- a/gr-input/python/Roots.py +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2015 <+YOU OR YOUR COMPANY+>. -# -# This is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# This software is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this software; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -import time -import numpy -from gnuradio import gr -import sciscipy - -class Roots(gr.sync_block): - """ - docstring for block add_python - """ - def __init__(self,order): - self.out = [0,0,0,0,0,0,0,0,0,0] - a = [] - self.b = [0,0,0,0,0,0] - self.order=int(order)+1 - self.number = int(order)*2 - for i in range(0,self.number): - a.append(numpy.float32) - gr.sync_block.__init__(self, - name="Roots", - in_sig=[numpy.float32], - out_sig=a) - - def find_roots(self,n): - string1 = "s=%s;" - string2 = "h2="+str(n[3])+"*s^3+"+str(n[2])+"*s^2+"+str(n[1])+"*s+"+str(n[0])+";[E1]=roots(h2);a11=real(E1(1));a12=imag(E1(1));b11 = real(E1(2));b12 = imag(E1(2));c11 = real(E1(3));c12 = imag(E1(3)); d11 = real(E1(4)); d12 = imag(E1(4)); e11 = real(E1(5)); e12 = imag(E1(5));" - string = string1+string2 - print "This is string\n", string - sciscipy.eval(string) - - - try: - self.a11 = sciscipy.read("a11") - print "I am a11", self.a11 - except TypeError: - self.a11 = 0 - try: - self.a12 = sciscipy.read("a12") - print "I am a12", self.a12 - except TypeError: - self.a12 = 0 - try: - self.b11 = sciscipy.read("b11") - print "I am b11", self.b11 - except TypeError: - self.b11 = 0 - try: - self.b12 = sciscipy.read("b12") - except TypeError: - self.b12 = 0 - try: - self.c11 = sciscipy.read("c11") - print "I am c11\n", self.c11 - except TypeError: - self.c11 = 0 - try: - self.c12 = sciscipy.read("c12") - print "I am c12\n", self.c12 - except TypeError: - self.c12 = 0 - try: - self.d11 = sciscipy.read("d11") - print "I am d11\n", self.d11 - except TypeError: - self.d11 = 0 - try: - self.d12 = sciscipy.read("d12") - except TypeError: - self.d12 = 0 - try: - self.e11 = sciscipy.read("e11") - except TypeError: - self.e11 = 0 - try: - self.e12 = sciscipy.read("e12") - except TypeError: - self.e12 = 0 - - def work(self, input_items, output_items): - -# print "I am here\n", output_items - k = self.order - for i in range(0,k): - self.b[i] = input_items[0][i] - - self.find_roots(self.b) - - - self.out[0] = numpy.float32(self.a11) - self.out[1] = numpy.float32(self.b11) - self.out[2] = numpy.float32(self.a12) - self.out[3] = numpy.float32(self.b12) - self.out[4] = numpy.float32(self.c11) - self.out[5] = numpy.float32(self.c12) - self.out[6] = numpy.float32(self.d11) - self.out[7] = numpy.float32(self.d12) - self.out[8] = numpy.float32(self.e11) - self.out[9] = numpy.float32(self.e12) - - - for i in range (0,self.number): - output_items[i][:]= self.out[i] - print "I am out item",output_items - - return len(output_items[0]) - - diff --git a/gr-input/python/Transfer_Function.py b/gr-input/python/Transfer_Function.py deleted file mode 100644 index d53c55e48..000000000 --- a/gr-input/python/Transfer_Function.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2015 <+YOU OR YOUR COMPANY+>. -# -# This is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# This software is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this software; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# - -import time -import numpy -from gnuradio import gr -import sciscipy - -class Transfer_Function(gr.sync_block): - """ - docstring for block add_python - """ - def __init__(self,order,itype,tstart,tstop,tstep): - a = [] - self.b = [0,0,0,0,0,0] - self.c = [0,0,0,0,0,0] - self.i = 0 - self.order=int(order)+1 - self.itype = itype - self.tstart = tstart - self.tstop = tstop - self.tstep = tstep - gr.sync_block.__init__(self, - name="tf_rises", - in_sig=[numpy.float32,numpy.float32], - out_sig=[numpy.float32]) - - #print "I am over slept" - #print len(self.ret_array) - - def find_resp(self,b,c): - if (self.itype == 11): - typo = "'imp'" - elif (self.itype == 12): - typo = "'step'" - else: - typo = "t" -# print "self b",self.b - string1 = "s=%s; h=syslin('c'," - string2 = str(b[4])+"*s^4+"+str(b[3])+"*s^3+"+str(b[2])+"*s^2+"+str(b[1])+"*s+"+str(b[0])+"," - string3 = str(c[4])+"*s^4+"+str(c[3])+"*s^3+"+str(c[2])+"*s^2+"+str(c[1])+"*s+"+str(c[0])+");" - string4 = "t="+str(self.tstart)+":"+str(self.tstep)+":"+str(self.tstop)+";" - string5 = "deff('u=input(t)','u=50');" - string6 = "r=tf2ss(h); a=csim("+typo+",t,r);" - string = string1+string2+string3+string4+string5+string6 - print "I am strin g",string - sciscipy.eval(string) - self.a = sciscipy.read("a") - print "value of a\n",self.a - - - - - - def work(self, input_items, output_items): - - print "input value:\n",input_items - for i in range(0,5): - self.b[i] = input_items[0][i] - # print "I am b[i]", b[i] - #print "I am BBBBB", self.b - - for j in range(0,5): - self.c[j] = input_items[1][j] - #print "I am c[j]", c[j] - #print "I am CCCCC", self.c - self.find_resp(self.b,self.c) - - - out = output_items[0] - self.i+=1 - print "I am self i\n",self.i - if self.i >= len(self.a): - self.i = 0 - print "len of out\n",len(out) - #time.sleep(0.125) - out[:] = numpy.float32(self.a[self.i]) - #print - print "i am out\n",out - - return len(output_items[0]) - - diff --git a/gr-input/python/__init__.py b/gr-input/python/__init__.py deleted file mode 100644 index 6e8ef1f55..000000000 --- a/gr-input/python/__init__.py +++ /dev/null @@ -1,53 +0,0 @@ -# -# Copyright 2008,2009 Free Software Foundation, Inc. -# -# This application is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# This application is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# - -# The presence of this file turns this directory into a Python package - -''' -This is the GNU Radio SCIGEN module. Place your Python package -description here (python/__init__.py). -''' - -# ---------------------------------------------------------------- -# Temporary workaround for ticket:181 (swig+python problem) -import sys -_RTLD_GLOBAL = 0 -try: - from dl import RTLD_GLOBAL as _RTLD_GLOBAL -except ImportError: - try: - from DLFCN import RTLD_GLOBAL as _RTLD_GLOBAL - except ImportError: - pass - -if _RTLD_GLOBAL != 0: - _dlopenflags = sys.getdlopenflags() - sys.setdlopenflags(_dlopenflags|_RTLD_GLOBAL) -# ---------------------------------------------------------------- - - -# import any pure python here -import serial - -# - -# ---------------------------------------------------------------- -# Tail of workaround -if _RTLD_GLOBAL != 0: - sys.setdlopenflags(_dlopenflags) # Restore original flags -# ---------------------------------------------------------------- diff --git a/gr-input/python/gr_ramp_source.py b/gr-input/python/gr_ramp_source.py deleted file mode 100644 index 574f9f70b..000000000 --- a/gr-input/python/gr_ramp_source.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/python - -import gras -import numpy -# Serial is imported in __init__ -class ramp(gras.Block): - - - def __init__(self): - gras.Block.__init__(self, - name="ser", - in_sig=[numpy.float32], - out_sig=[numpy.float32]) - self.i = 0 - self.flag=True - - def set_parameters(self, ramp_slope, height_Offset, width_Offset): - self.slope = ramp_slope - self.width = width_Offset - self.offset = height_Offset - - def work(self, input_items, output_items): - - out = output_items[0][0:1] - input_stream = input_items[0][0] - - if self.flag: - for j in range(self.width): - out = self.offset - print "OUT", out - - self.produce(0,1) # Produce from port 0 output_items - self.consume(0,1) # Consume from port 0 input_items - - self.flag = False - - else: - - self.i = self.i + 1 - out[:1] =self.offset + self.i*input_stream*self.slope - - print "OUT", out - - self.produce(0,1) # Produce from port 0 output_items - self.consume(0,1) # Consume from port 0 input_items - diff --git a/gr-input/python/gr_step_source.py b/gr-input/python/gr_step_source.py deleted file mode 100644 index 904f89292..000000000 --- a/gr-input/python/gr_step_source.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/python - -import gras -import numpy -# Serial is imported in __init__ -class step(gras.Block): - - - def __init__(self): - gras.Block.__init__(self, - name="ser", - in_sig=[numpy.float32], - out_sig=[numpy.float32]) - self.flag=True - - def set_parameters(self, step_size, offset, width): - self.step_size = step_size - self.width = width - self.offset = offset - - def work(self, input_items, output_items): - - out = output_items[0][0:1] - input_stream = input_items[0][0] - - if self.flag: - for i in range(self.width): - out[:1] = self.offset - print "OUT", out - - self.produce(0,1) # Produce from port 0 output_items - self.consume(0,1) # Consume from port 0 input_items - - self.flag = False - - else: - out[:1] = self.offset + input_stream*self.step_size - - print "OUT", out - - self.produce(0,1) # Produce from port 0 output_items - self.consume(0,1) # Consume from port 0 input_items - diff --git a/gr-input/python/matplotsink.py b/gr-input/python/matplotsink.py deleted file mode 100755 index 105009b4d..000000000 --- a/gr-input/python/matplotsink.py +++ /dev/null @@ -1,312 +0,0 @@ -""" -$$ - -Modified for working as a GNU Radio block -Rakesh Peter (rakesh.peter@gmail.com) -Last modified: 07.05.2010 - -$$ - -This demo demonstrates how to draw a dynamic mpl (matplotlib) -plot in a wxPython application. - -It allows "live" plotting as well as manual zooming to specific -regions. - -Both X and Y axes allow "auto" or "manual" settings. For Y, auto -mode sets the scaling of the graph to see all the data points. -For X, auto mode makes the graph "follow" the data. Set it X min -to manual 0 to always see the whole data from the beginning. - -Note: press Enter in the 'manual' text box to make a new value -affect the plot. - -Eli Bendersky (eliben@gmail.com) -License: this code is in the public domain -Last modified: 31.07.2008 -""" - -import os -import pprint -import random -import sys -import wx -import gnuradio.grc.gui -from gnuradio.grc.gui import Actions,ActionHandler -# The recommended way to use wx with mpl is with the WXAgg -# backend. -# -import matplotlib -import matplotlib.pyplot as plt -import matplotlib.animation as animation -#matplotlib.use('WXAgg') -from matplotlib.figure import Figure -from matplotlib.backends.backend_wxagg import \ - FigureCanvasWxAgg as FigCanvas, \ - NavigationToolbar2WxAgg as NavigationToolbar -import numpy as np -import pylab - - -class DataGen(object): - """ A silly class that generates pseudo-random data for - display in the plot. - """ - def __init__(self, init=50): - self.data = self.init = init - - def next(self): - self._recalc_data() - #return self.data - return [0.0,1.1,2.2,3.3] - - def _recalc_data(self): - delta = random.uniform(-0.5, 0.5) - r = random.random() - - if r > 0.9: - self.data += delta * 15 - elif r > 0.8: - # attraction to the initial value - delta += (0.5 if self.init > self.data else -0.5) - self.data += delta - else: - self.data += delta - - - -class matplotsink(wx.Panel): - - def __init__(self, parent, title, queue,gsz,zoom): - wx.Panel.__init__(self, parent, wx.SIMPLE_BORDER) - - self.gsz = gsz - self.parent = parent - self.title = title - self.q = queue - self.zoom=zoom - self.paused = False - -# self.create_menu() -# self.create_status_bar() - self.create_main_panel() - - - def create_menu(self): - self.menubar = wx.MenuBar() - - menu_file = wx.Menu() - m_expt = menu_file.Append(-1, "&Save plot\tCtrl-S", "Save plot to file") - self.Bind(wx.EVT_MENU, self.on_save_plot, m_expt) - menu_file.AppendSeparator() - m_exit = menu_file.Append(-1, "E&xit\tCtrl-X", "Exit") - self.Bind(wx.EVT_MENU, self.on_exit, m_exit) - self.menubar.Append(menu_file, "&File") - self.SetMenuBar(self.menubar) - - - def create_main_panel(self): - self.panel = self - - self.init_plot() - self.canvas = FigCanvas(self.panel, -1, self.fig) - self.scroll_range = 400 - self.canvas.SetScrollbar(wx.HORIZONTAL,0,5,self.scroll_range) - self.canvas.Bind(wx.EVT_SCROLLWIN,self.OnScrollEvt) - - - self.pause_button = wx.Button(self.panel, -1, "Pause") - self.Bind(wx.EVT_BUTTON, self.on_pause_button, self.pause_button) - self.Bind(wx.EVT_UPDATE_UI, self.on_update_pause_button, self.pause_button) - - self.cb_grid = wx.CheckBox(self.panel, -1, - "Show Grid", - style=wx.ALIGN_RIGHT) - self.Bind(wx.EVT_CHECKBOX, self.on_cb_grid, self.cb_grid) - self.cb_grid.SetValue(True) - - self.cb_xlab = wx.CheckBox(self.panel, -1, - "Show X labels", - style=wx.ALIGN_RIGHT) - self.Bind(wx.EVT_CHECKBOX, self.on_cb_xlab, self.cb_xlab) - self.cb_xlab.SetValue(True) - - self.hbox1 = wx.BoxSizer(wx.HORIZONTAL) - self.hbox1.Add(self.pause_button, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) - self.hbox1.AddSpacer(20) - self.hbox1.Add(self.cb_grid, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) - self.hbox1.AddSpacer(10) - self.hbox1.Add(self.cb_xlab, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) - - - self.vbox = wx.BoxSizer(wx.VERTICAL) - self.vbox.Add(self.canvas, 1, flag=wx.LEFT | wx.TOP | wx.GROW) - self.vbox.Add(self.hbox1, 0, flag=wx.ALIGN_LEFT | wx.TOP) - - self.panel.SetSizer(self.vbox) - self.vbox.Fit(self) - self.ani=animation.FuncAnimation(self.fig,self.draw_plot,interval=100) - - def OnScrollEvt(self,event): - self.i_start = event.GetPosition() - self.i_end = self.i_window + event.GetPosition() - self.draw_plot(0) - - def create_status_bar(self): - self.statusbar = self.CreateStatusBar() - - def draw_test(self,event): - self.xar=np.arange(len(self.q.queue)) - self.yar=np.array(self.q.queue) - self.axes.plot(self.xar,self.yar) - - def init_plot(self): - self.dpi = 100 - self.fig = Figure((3.0, 3.0), dpi=self.dpi) - self.fig.set_size_inches(7.0,4.0) - self.fig.set_dpi(self.dpi) - - self.axes = self.fig.add_subplot(111) - self.axes.set_axis_bgcolor('black') - self.axes.set_title(self.title, size=12) - - pylab.setp(self.axes.get_xticklabels(), fontsize=8) - pylab.setp(self.axes.get_yticklabels(), fontsize=8) - self.i_window = self.gsz - self.i_start = 0 - self.i_end = self.i_start + self.i_window - # plot the data as a line series, and save the reference - # to the plotted line series - # - self.plot_data = self.axes.plot( - [], - linewidth=1, - color=(1, 1, 0), - )[0] - - - def draw_plot(self,event): - """ Redraws the plot - """ - if len(list(self.q.queue))>1 and not self.paused: - - if self.zoom: - xmax = len(list(self.q.queue)) if len(list(self.q.queue)) > 50 else 50 - - xmin = xmax - 50 - # for ymin and ymax, find the minimal and maximal values - # in the data set and add a mininal margin. - # - # note that it's easy to change this scheme to the - # minimal/maximal value in the current display, and not - # the whole data set. - # - ymin = round(min(list(self.q.queue)), 0) - 1 - - ymax = round(max(list(self.q.queue)), 0) + 1 - - self.axes.set_xbound(lower=xmin, upper=xmax) - self.axes.set_ybound(lower=ymin, upper=ymax) - - # anecdote: axes.grid assumes b=True if any other flag is - # given even if b is set to False. - # so just passing the flag into the first statement won't - # work. - # - if self.cb_grid.IsChecked(): - self.axes.grid(True, color='gray') - else: - self.axes.grid(False) - - # Using setp here is convenient, because get_xticklabels - # returns a list over which one needs to explicitly - # iterate, and setp already handles this. - # - pylab.setp(self.axes.get_xticklabels(), - visible=self.cb_xlab.IsChecked()) - - - self.plot_data.set_xdata(np.arange(len(list(self.q.queue)))) - self.plot_data.set_ydata(np.array(list(self.q.queue))) - self.canvas.draw() - - else: - if self.cb_grid.IsChecked(): - self.axes.grid(True, color='gray') - else: - self.axes.grid(False) - - # Using setp here is convenient, because get_xticklabels - # returns a list over which one needs to explicitly - # iterate, and setp already handles this. - - pylab.setp(self.axes.get_xticklabels(), - visible=self.cb_xlab.IsChecked()) - - self.plot_data.set_xdata(np.arange(len(list(self.q.queue)))[self.i_start:self.i_end]) - self.plot_data.set_ydata(np.array(list(self.q.queue))[self.i_start:self.i_end]) - self.axes.set_xlim(min(np.arange(len(list(self.q.queue)))[self.i_start:self.i_end]),max(np.arange(len(list(self.q.queue)))[self.i_start:self.i_end])) - # if self.zoom: - self.axes.set_ylim(min(np.array(list(self.q.queue))),max(np.array(list(self.q.queue)))) - - self.canvas.draw() - - - - def on_pause_button(self, event): - self.paused = not self.paused - - def on_update_pause_button(self, event): - label = "Resume" if self.paused else "Pause" - self.pause_button.SetLabel(label) - - def on_cb_grid(self, event): - self.draw_plot(0) - - def on_cb_xlab(self, event): - self.draw_plot(0) - - def on_save_plot(self, event): - file_choices = "PNG (*.png)|*.png" - - dlg = wx.FileDialog( - self, - message="Save plot as...", - defaultDir=os.getcwd(), - defaultFile="plot.png", - wildcard=file_choices, - style=wx.SAVE) - - if dlg.ShowModal() == wx.ID_OK: - path = dlg.GetPath() - self.canvas.print_figure(path, dpi=self.dpi) - self.flash_status_message("Saved to %s" % path) - - def on_redraw_timer(self, event): - # if paused do not add data, but still redraw the plot - # (to respond to scale modifications, grid change, etc.) - # - if not self.paused: - self.data += self.datagen.next() - self.draw_plot(0) - - - def on_exit(self, event): - self.Destroy() - - def flash_status_message(self, msg, flash_len_ms=1500): - self.statusbar.SetStatusText(msg) - self.timeroff = wx.Timer(self) - self.Bind( - wx.EVT_TIMER, - self.on_flash_status_off, - self.timeroff) - self.timeroff.Start(flash_len_ms, oneShot=True) - - def on_flash_status_off(self, event): - self.statusbar.SetStatusText('') - - - - - diff --git a/gr-input/python/plot_sink.py b/gr-input/python/plot_sink.py deleted file mode 100755 index 1c1def3fc..000000000 --- a/gr-input/python/plot_sink.py +++ /dev/null @@ -1,57 +0,0 @@ -# Hacked from blks2/variable_sink.py -# Requires modified Matplotsink code - -from gnuradio import gr -import threading -import numpy -import matplotsink -import Queue - -class _plot_sink_base(gr.hier_block2, threading.Thread): - """ - The thread polls the message queue for values and writes to matplotsink callback - """ - - def __init__(self, parent, title, vlen, decim,gsz,zoom): - self._vlen = vlen - self._parent = parent - self._title = title - print "Initing block: %s" % title - - self.plotQueue = Queue.Queue() - self.win = matplotsink.matplotsink(parent,title, self.plotQueue,gsz,zoom) - - self._item_size = self._size*self._vlen - #init hier block - gr.hier_block2.__init__( - self, 'plot_sink', - gr.io_signature(1, 1, self._item_size), - gr.io_signature(0, 0, 0), - ) - #create blocks - self._msgq = gr.msg_queue(2) - message_sink = gr.message_sink(self._item_size, self._msgq, False) - #connect - self.connect(self, message_sink) - #setup thread - threading.Thread.__init__(self) - self.setDaemon(True) - self.start() - - def set_decim(self, decim): self._decimator.set_n(decim) - - def run(self): - while True: #truncate to item size, convert to array, callback - msg = self._msgq.delete_head().to_string()[-self._item_size:] - arr = map(self._cast, numpy.fromstring(msg, self._numpy)) - print "Sending value:" , arr - self.plotQueue.put(self._vlen > 1 and arr or arr[0]) - - def print_callback(self, array): - print array - -class plot_sink_b(_plot_sink_base): _numpy, _size, _cast = numpy.int8, gr.sizeof_char, int -class plot_sink_s(_plot_sink_base): _numpy, _size, _cast = numpy.int16, gr.sizeof_short, int -class plot_sink_i(_plot_sink_base): _numpy, _size, _cast = numpy.int32, gr.sizeof_int, int -class plot_sink_f(_plot_sink_base): _numpy, _size, _cast = numpy.float32, gr.sizeof_float, float -class plot_sink_c(_plot_sink_base): _numpy, _size, _cast = numpy.complex64, gr.sizeof_gr_complex, complex diff --git a/gr-input/python/plzr_plot.py b/gr-input/python/plzr_plot.py deleted file mode 100644 index e1b0ff3fc..000000000 --- a/gr-input/python/plzr_plot.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2015 <+YOU OR YOUR COMPANY+>. -# -# This is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3, or (at your option) -# any later version. -# -# This software is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this software; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# -import sys -import time -import numpy -from gnuradio import gr -import sciscipy - -class plzr_plot(gr.sync_block): - """ - docstring for block add_python - """ - def __init__(self,order): - sys.setrecursionlimit(2000) - a = [] -# self.flag = 0 - self.b = [0,0,0,0,0,0] - self.c = [0,0,0,0,0,0] - self.i = 0 - self.order=int(order)+1 - gr.sync_block.__init__(self, - name="plzr_plot", - in_sig=[numpy.float32,numpy.float32], - out_sig=None) - - def plot(self,b,c): - string1 = "s=%s; h=syslin('c'," - string2 = str(b[4])+"*s^4+"+str(b[3])+"*s^3+"+str(b[2])+"*s^2+"+str(b[1])+"*s+"+str(b[0])+"," - string3 = str(c[4])+"*s^4+"+str(c[3])+"*s^3+"+str(c[2])+"*s^2+"+str(c[1])+"*s+"+str(c[0])+");" - string4 = "plzr(h);" - - string = string1 + string2 +string3 + string4 - sciscipy.eval(string) - - - - def work(self, input_items, output_items): - print "I am input", input_items - print "I am output", output_items - k = self.order - for i in range(0,k): - self.b[i] = input_items[0][i] - print "I am value of b\n",self.b - - - for j in range(0,k): - self.c[j] = input_items[1][j] - print "I am vlaue of c\n", self.c - - self.plot(self.b,self.c) - in0 = input_items[0] - # <+signal processing here+> - return len(input_items[0]) - diff --git a/gr-input/python/ramp_hierblock.py b/gr-input/python/ramp_hierblock.py deleted file mode 100644 index 950615142..000000000 --- a/gr-input/python/ramp_hierblock.py +++ /dev/null @@ -1,19 +0,0 @@ -import gras -import numpy -from gnuradio import gr -from gnuradio import blocks - -# Source block1 import -import gr_ramp_source -from gnuradio import blocks - -class HierBlock(gr.hier_block2): - def __init__(self,ramp_slope, height_Offset, width_Offset): - gr.hier_block2.__init__(self,"HierBlock",gr.io_signature(1,1,gr.sizeof_float), gr.io_signature(1,2,gr.sizeof_float)) - #constant_block initialized - self.constant_block = gr.sig_source_f(0,gr.GR_CONST_WAVE,0,0,1) - #ramp_source block initialized - self.ramp_source=gr_ramp_source.ramp() - self.ramp_source.set_parameters(ramp_slope, height_Offset, width_Offset) - self.connect(self,(self.constant_block,0),(self.ramp_source,0),self) - diff --git a/gr-input/python/step_hierblock.py b/gr-input/python/step_hierblock.py deleted file mode 100644 index 4243606d6..000000000 --- a/gr-input/python/step_hierblock.py +++ /dev/null @@ -1,22 +0,0 @@ -import gras -import numpy -from gnuradio import gr -from gnuradio import blocks - -# Source block1 import -import gr_step_source -from gnuradio import blocks - -class HierBlock(gr.hier_block2): - def __init__(self, step_size, H_Off, W_Off): - gr.hier_block2.__init__(self, "HierBlock", - gr.io_signature(1,1,gr.sizeof_float), - gr.io_signature(1,2,gr.sizeof_float)) - - # constant_block initialized - self.constant_block = gr.sig_source_f(0, gr.GR_CONST_WAVE,0,0,1) - # step_source block initialized - self.step_source = gr_step_source.step() - self.step_source.set_parameters(step_size, H_Off, W_Off) - self.connect(self, (self.constant_block,0) , (self.step_source,0), self) - -- cgit From d00a8dd67dcdc3650f344396425933424813baba Mon Sep 17 00:00:00 2001 From: Ashwini Date: Tue, 10 Mar 2015 17:25:45 +0530 Subject: Plot sink added --- gr-input/CMakeLists.txt | 55 ++++ gr-input/doc/CMakeLists.txt | 23 ++ gr-input/doc/README.input | 2 + gr-input/doc/input.dox | 29 ++ gr-input/grc/CMakeLists.txt | 77 +++++ gr-input/grc/Calculation_Calculator.xml | 65 +++++ gr-input/grc/Calculation_Roots.xml | 34 +++ gr-input/grc/Transfer_Function_Denominator.xml | 33 +++ gr-input/grc/Transfer_Function_Numerator.xml | 33 +++ .../grc/Transfer_Function_Transfer_Function.xml | 66 +++++ gr-input/grc/Transfer_function_Denominator.xml | 49 ++++ gr-input/grc/Transfer_function_Numerator.xml | 48 ++++ gr-input/grc/Transfer_function_Response.xml | 80 ++++++ gr-input/grc/plot_sink.xml | 112 ++++++++ gr-input/grc/plzr_plot.xml | 37 +++ gr-input/grc/ramp_source.xml | 87 ++++++ gr-input/grc/step_source.xml | 88 ++++++ gr-input/python/CMakeLists.txt | 128 +++++++++ gr-input/python/Calculator.py | 99 +++++++ gr-input/python/Denominator.py | 91 ++++++ gr-input/python/Numerator.py | 90 ++++++ gr-input/python/Response.py | 98 +++++++ gr-input/python/Roots.py | 126 +++++++++ gr-input/python/Transfer_Function.py | 100 +++++++ gr-input/python/__init__.py | 53 ++++ gr-input/python/gr_ramp_source.py | 46 +++ gr-input/python/gr_step_source.py | 43 +++ gr-input/python/matplotsink.py | 312 +++++++++++++++++++++ gr-input/python/plot_sink.py | 57 ++++ gr-input/python/plzr_plot.py | 71 +++++ gr-input/python/ramp_hierblock.py | 19 ++ gr-input/python/step_hierblock.py | 22 ++ 32 files changed, 2273 insertions(+) create mode 100644 gr-input/CMakeLists.txt create mode 100644 gr-input/doc/CMakeLists.txt create mode 100644 gr-input/doc/README.input create mode 100644 gr-input/doc/input.dox create mode 100644 gr-input/grc/CMakeLists.txt create mode 100644 gr-input/grc/Calculation_Calculator.xml create mode 100644 gr-input/grc/Calculation_Roots.xml create mode 100644 gr-input/grc/Transfer_Function_Denominator.xml create mode 100644 gr-input/grc/Transfer_Function_Numerator.xml create mode 100644 gr-input/grc/Transfer_Function_Transfer_Function.xml create mode 100644 gr-input/grc/Transfer_function_Denominator.xml create mode 100644 gr-input/grc/Transfer_function_Numerator.xml create mode 100644 gr-input/grc/Transfer_function_Response.xml create mode 100755 gr-input/grc/plot_sink.xml create mode 100644 gr-input/grc/plzr_plot.xml create mode 100644 gr-input/grc/ramp_source.xml create mode 100644 gr-input/grc/step_source.xml create mode 100644 gr-input/python/CMakeLists.txt create mode 100644 gr-input/python/Calculator.py create mode 100644 gr-input/python/Denominator.py create mode 100644 gr-input/python/Numerator.py create mode 100644 gr-input/python/Response.py create mode 100644 gr-input/python/Roots.py create mode 100644 gr-input/python/Transfer_Function.py create mode 100644 gr-input/python/__init__.py create mode 100644 gr-input/python/gr_ramp_source.py create mode 100644 gr-input/python/gr_step_source.py create mode 100755 gr-input/python/matplotsink.py create mode 100755 gr-input/python/plot_sink.py create mode 100644 gr-input/python/plzr_plot.py create mode 100644 gr-input/python/ramp_hierblock.py create mode 100644 gr-input/python/step_hierblock.py diff --git a/gr-input/CMakeLists.txt b/gr-input/CMakeLists.txt new file mode 100644 index 000000000..50babee29 --- /dev/null +++ b/gr-input/CMakeLists.txt @@ -0,0 +1,55 @@ +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +######################################################################## +# Setup dependencies +######################################################################## +#include(GrBoost) + +#find_package(SCIGENW3f) + +######################################################################## +# Register component +######################################################################## +include(GrComponent) + +GR_REGISTER_COMPONENT("gr-input" ENABLE_GR_INPUT + ENABLE_GRUEL + ENABLE_VOLK + Boost_FOUND + ENABLE_GR_CORE +) + +######################################################################## +# Begin conditional configuration +######################################################################## +if(ENABLE_GR_INPUT) + +######################################################################## +# Add subdirectories +######################################################################## +if(ENABLE_PYTHON) + add_subdirectory(python) + add_subdirectory(grc) +endif(ENABLE_PYTHON) +#add_subdirectory(examples) +add_subdirectory(doc) + + +endif(ENABLE_GR_INPUT) diff --git a/gr-input/doc/CMakeLists.txt b/gr-input/doc/CMakeLists.txt new file mode 100644 index 000000000..b10223aaf --- /dev/null +++ b/gr-input/doc/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +install( + FILES README.input + DESTINATION ${GR_PKG_DOC_DIR} +) diff --git a/gr-input/doc/README.input b/gr-input/doc/README.input new file mode 100644 index 000000000..1bd326897 --- /dev/null +++ b/gr-input/doc/README.input @@ -0,0 +1,2 @@ +Serial Python block + diff --git a/gr-input/doc/input.dox b/gr-input/doc/input.dox new file mode 100644 index 000000000..8843d0560 --- /dev/null +++ b/gr-input/doc/input.dox @@ -0,0 +1,29 @@ +/*! \page page_fft FFT Signal Processing Blocks + +\section Introduction + +This is the gr-scigen package. It contains signal processing blocks to +perform FFTs and FFT-related functionality. + +The Python namespace is in gnuradio.fft, which would be normally +imported as: + +\code + from gnuradio import scigen +\endcode + +See the Doxygen documentation for details about the blocks available +in this package. A quick listing of the details can be found in Python +after importing by using: + +\code + help(scigen) +\endcode + +\section Dependencies + +The scigen blocks require the following dependencies. + +\li fftw3f (>= 3.0) http://www.fftw.org/download.html + +*/ diff --git a/gr-input/grc/CMakeLists.txt b/gr-input/grc/CMakeLists.txt new file mode 100644 index 000000000..61b317f77 --- /dev/null +++ b/gr-input/grc/CMakeLists.txt @@ -0,0 +1,77 @@ +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +install(FILES + step_source.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "input_python" +) + +install(FILES + ramp_source.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "input_python" +) + +install(FILES + Transfer_function_Numerator.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "input_python" +) + + + +install(FILES + Transfer_function_Denominator.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "input_python" +) + + +install(FILES + Transfer_function_Denominator.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "input_python" +) + +install(FILES + Transfer_function_Response.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "input_python" +) + +install(FILES + Calculation_Roots.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "input_python" +) + +install(FILES + Calculation_Calculator.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "input_python" +) + + +install(FILES + plot_sink.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "input_python" +) + diff --git a/gr-input/grc/Calculation_Calculator.xml b/gr-input/grc/Calculation_Calculator.xml new file mode 100644 index 000000000..070712f57 --- /dev/null +++ b/gr-input/grc/Calculation_Calculator.xml @@ -0,0 +1,65 @@ + + + Calculator + Calculation_Calculator + Calculation + import gnuradio.input.Calculator + gnuradio.input.Calculator.Calculator($num_inputs) +self.$(id).set_parameters($Exp,$num_inputs) + + +Expression +Exp +string + + + +Num inputs +num_inputs +1 +int + + + + in0 + float + $num_inputs + + + + + + out + float + + + + +Variable names must be a0,a1,a2 and so on. + +You can use maximum 10 variables per block. + +Example to add 5 variables: + +"a0+a1+a2+a3+a4" + +To perform Exponential(power) calculations on operators use the following: + +a0**a1 + +To perform calculations like sqrt, log or exp use the following: + +sqrt(a4) + +log(a2) + +exp(a8) + + + + diff --git a/gr-input/grc/Calculation_Roots.xml b/gr-input/grc/Calculation_Roots.xml new file mode 100644 index 000000000..9871cad5a --- /dev/null +++ b/gr-input/grc/Calculation_Roots.xml @@ -0,0 +1,34 @@ + + + Roots + Calculation_Roots + Calculation + import gnuradio.input.Roots + gnuradio.input.Roots.Roots($order) + + + Order of transfer function + order + samp_rate + real + + + + + in + float + + + + + + out + float + 2*$order + + diff --git a/gr-input/grc/Transfer_Function_Denominator.xml b/gr-input/grc/Transfer_Function_Denominator.xml new file mode 100644 index 000000000..5ea581a98 --- /dev/null +++ b/gr-input/grc/Transfer_Function_Denominator.xml @@ -0,0 +1,33 @@ + + + Denominator + Transfer_Function_Denominator + Transfer Function + import gnuradio.input.Denominator + gnuradio.input.Denominator.Denominator($num_inputs) + + +Num inputs +num_inputs +1 +int + + + + in0 + float + $num_inputs + + + + + + out + float + + diff --git a/gr-input/grc/Transfer_Function_Numerator.xml b/gr-input/grc/Transfer_Function_Numerator.xml new file mode 100644 index 000000000..8bb367a62 --- /dev/null +++ b/gr-input/grc/Transfer_Function_Numerator.xml @@ -0,0 +1,33 @@ + + + Numerator + Transfer_Function_Numerator + Transfer Function + import gnuradio.input.Numerator + gnuradio.input.Numerator.Numerator($num_inputs) + + +Num inputs +num_inputs +1 +int + + + + in0 + float + $num_inputs + + + + + + out + float + + diff --git a/gr-input/grc/Transfer_Function_Transfer_Function.xml b/gr-input/grc/Transfer_Function_Transfer_Function.xml new file mode 100644 index 000000000..203fe4a7b --- /dev/null +++ b/gr-input/grc/Transfer_Function_Transfer_Function.xml @@ -0,0 +1,66 @@ + + + Transfer Function + Transfer_Function_Transfer_Function + Transfer Function + import gnuradio.input.Transfer_Function + gnuradio.input.Transfer_Function.Transfer_Function($order,$itype,$tstart,$tstop,$tstep) + + + Order of transfer function + order + 1 + real + + + + + + Input Types + itype + enum + + + + + + +tstart +tstart +0 +real + + + +tstop +tstop +0 +real + + + +tstep +tstep +0 +real + + + + + in + float + 2 + + + + + + out + float + + diff --git a/gr-input/grc/Transfer_function_Denominator.xml b/gr-input/grc/Transfer_function_Denominator.xml new file mode 100644 index 000000000..2ba936580 --- /dev/null +++ b/gr-input/grc/Transfer_function_Denominator.xml @@ -0,0 +1,49 @@ + + + Denominator + Transfer_function_Denominator + Transfer_function + import gnuradio.input.Denominator + gnuradio.input.Denominator.Denominator($num_inputs) + + +Order of Transfer Function +num_inputs +1 +int + + + + in0 + float + 1+$num_inputs + + + + + + out + float + + + + +This will take the coefficient values for the Denominator. + +in00 = value of the coefficient of s^0 + +in01 = value of the coefficient of s^1 + +in02 = value of the coefficient of s^2 + +and so on.. + + + + + diff --git a/gr-input/grc/Transfer_function_Numerator.xml b/gr-input/grc/Transfer_function_Numerator.xml new file mode 100644 index 000000000..1ad34f316 --- /dev/null +++ b/gr-input/grc/Transfer_function_Numerator.xml @@ -0,0 +1,48 @@ + + + Numerator + Transfer_function_Numerator + Transfer_function + import gnuradio.input.Numerator + gnuradio.input.Numerator.Numerator($num_inputs) + + +Order of Transfer Function +num_inputs +1 +int + + + + in0 + float + 1+$num_inputs + + + + + + out + float + + + + +This will take the coefficient values for the numerator. + +in00 = value of the coefficient of s^0 + +in01 = value of the coefficient of s^1 + +in02 = value of the coefficient of s^2 + +and so on.. + + + + diff --git a/gr-input/grc/Transfer_function_Response.xml b/gr-input/grc/Transfer_function_Response.xml new file mode 100644 index 000000000..cb08a4c2a --- /dev/null +++ b/gr-input/grc/Transfer_function_Response.xml @@ -0,0 +1,80 @@ + + + Response + Transfer_function_Response + Transfer_function + import gnuradio.input.Response + gnuradio.input.Response.Response($order,$itype,$tstart,$tstop,$tstep) + + + Order of transfer function + order + 1 + real + + + + + + Input Types + itype + enum + + + + + + +tstart +tstart +0 +real + + + +tstop +tstop +0 +real + + + +tstep +tstep +0 +real + + + + + in + float + 2 + + + + + + out + float + + + + +This block can perfrom three types of system responses. + +Step, Ramp and Impulse. + +in0 = Numerator Equation + +in1 = Denominator Equation + + + + + diff --git a/gr-input/grc/plot_sink.xml b/gr-input/grc/plot_sink.xml new file mode 100755 index 000000000..07022ea07 --- /dev/null +++ b/gr-input/grc/plot_sink.xml @@ -0,0 +1,112 @@ + + + + Plot Sink + plot_sink + Single Board Heater System + import gnuradio.input.plot_sink + #set $parent = $notebook() and 'self.%s.GetPage(%s)'%$notebook() or 'self' +gnuradio.input.plot_sink.plot_sink_$(type.fcn)( + $(parent).GetWin(), + title=$title, + vlen=$vlen, + decim=$decim, + gsz=$gsz, + zoom=$zoom, +) +#if not $grid_pos() +$(parent).Add(self.$(id).win) +#else +$(parent).GridAdd(self.$(id).win, $(', '.join(map(str, $grid_pos())))) +#end if + set_decim($decim) + + Type + type + enum + + + + + + + + Title + title + Scope Plot + string + + + Decimation + decim + 1 + int + + + Vec Length + vlen + 1 + int + + + + Graph size + gsz + 50 + int + + + History Required + zoom + 0 + int + + + + Grid Position + grid_pos + + grid_pos + + + Notebook + notebook + + notebook + + + $vlen > 0 + + in + $type + $vlen + + +Read samples from the input stream and \ +plot one in every decimation samples to the plot sink. + + diff --git a/gr-input/grc/plzr_plot.xml b/gr-input/grc/plzr_plot.xml new file mode 100644 index 000000000..833149ea5 --- /dev/null +++ b/gr-input/grc/plzr_plot.xml @@ -0,0 +1,37 @@ + + + plzr_plot + plzr_plot + Python_Blocks + import gnuradio.plzr_plot + gnuradio.plzr_plot.plzr_plot($order) + + + Order of transfer function + order + 1 + real + + + + + + + in + float + 2 + + + diff --git a/gr-input/grc/ramp_source.xml b/gr-input/grc/ramp_source.xml new file mode 100644 index 000000000..5cba29ae7 --- /dev/null +++ b/gr-input/grc/ramp_source.xml @@ -0,0 +1,87 @@ + + + + Ramp Input + ramp + Sources + + from gnuradio.input import ramp_hierblock as ramp_hierblock + ramp_hierblock.HierBlock($S,$H_Off,$W_Off) + + + IO Type + type + enum + + + + + + + Num Inputs + num_inputs + 1 + int + + + Vec Length + vlen + 1 + int + + + + + slope of ramp + S + 1 + real + + + + height of offset + H_Off + 0 + real + + + + width of offset + W_Off + 0 + real + + + + $num_inputs > 0 + $vlen > 0 + + + out + $(str($type).split('_')[1]) + $vlen + + + +Ramp Input block : + +Slope of ramp is the slope of ramp user wants to generate. +Height of Offset is the height of step user wants to generate as initial signal. +Width of Offset is the length upto which user wants to see the generated offset be. + +Default slope of ramp is 1 unit. +Default height and width of offset is 1 unit. + + + diff --git a/gr-input/grc/step_source.xml b/gr-input/grc/step_source.xml new file mode 100644 index 000000000..599980030 --- /dev/null +++ b/gr-input/grc/step_source.xml @@ -0,0 +1,88 @@ + + + + Step Input + step_offset + Sources + + from gnuradio.input import step_hierblock as step_hierblock + step_hierblock.HierBlock($S,$H_Off,$W_Off) + + + IO Type + type + enum + + + + + + + Num Inputs + num_inputs + 1 + int + + + Vec Length + vlen + 1 + int + + + + + step size + S + 1 + real + + + + height of offset + H_Off + 0 + real + + + + width of offset + W_Off + 0 + real + + + + + $num_inputs > 0 + $vlen > 0 + + + out + $(str($type).split('_')[1]) + $vlen + + + +Step Input block : + +Step size is the height of step user wants to generate. +Height of Offset is the height of step user wants to generate as initial signal. +Width of Offset is the length upto which user wants to see the generated offset before starting with the height equivalent to step size. + +Default step size is 1 unit. +Default height and width of offset is 1 unit + + + diff --git a/gr-input/python/CMakeLists.txt b/gr-input/python/CMakeLists.txt new file mode 100644 index 000000000..7c73fc59f --- /dev/null +++ b/gr-input/python/CMakeLists.txt @@ -0,0 +1,128 @@ +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +######################################################################## +include(GrPython) + +GR_PYTHON_INSTALL( + FILES + __init__.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + gr_ramp_source.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + gr_step_source.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + ramp_hierblock.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + step_hierblock.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + Numerator.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + + +GR_PYTHON_INSTALL( + FILES + Denominator.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + + +GR_PYTHON_INSTALL( + FILES + Response.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + Roots.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + Calculator.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + plot_sink.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + +GR_PYTHON_INSTALL( + FILES + matplotsink.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/input + COMPONENT "input_python" +) + + +######################################################################## +# Handle the unit tests +######################################################################## +if(ENABLE_TESTING) + +list(APPEND GR_TEST_PYTHON_DIRS + ${CMAKE_BINARY_DIR}/gr-input/python +) +list(APPEND GR_TEST_TARGET_DEPS gnuradio-input) + +include(GrTest) + + +file(GLOB py_qa_test_files "qa_*.py") +foreach(py_qa_test_file ${py_qa_test_files}) + get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE) + GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B} ${py_qa_test_file}) +endforeach(py_qa_test_file) +endif(ENABLE_TESTING) diff --git a/gr-input/python/Calculator.py b/gr-input/python/Calculator.py new file mode 100644 index 000000000..f2eaf0481 --- /dev/null +++ b/gr-input/python/Calculator.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# +# Copyright 2015 <+YOU OR YOUR COMPANY+>. +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import numpy +from numpy import log +from numpy import exp +from numpy import sqrt +from gnuradio import gr +import time + +class Calculator(gr.sync_block): + """ + docstring for block add_python + """ + def __init__(self,num_inputs): + number = num_inputs + a = [] + for i in range(0,number): + a.append(numpy.float32) +# print "value of a",a + gr.sync_block.__init__(self, + name="Calculator", + in_sig=a, + out_sig=[numpy.float32]) + + #print "I am over slept" + #print len(self.ret_array) + def set_parameters(self,Exp,num_inputs): + self.Exp = Exp + #print "This is EXP", Exp + self.num_inputs = num_inputs + + + def work(self, input_items, output_items): + try: + a0 = input_items[0] + except IndexError: + pass + try: + a1 = input_items[1] + except IndexError: + pass + try: + a2 = input_items[2] + except IndexError: + pass + try: + a3 = input_items[3] + except IndexError: + pass + try: + a4 = input_items[4] + except IndexError: + pass + try: + a5 = input_items[5] + except IndexError: + pass + try: + a6 = input_items[6] + except IndexError: + pass + try: + a7 = input_items[7] + except IndexError: + pass + try: + a8 = input_items[8] + except IndexError: + pass + try: + a9 = input_items[9] + except IndexError: + pass + #out = output_items[0][0] + print "This is self.Exp\n",self.Exp + + output_items[0][:] = eval(self.Exp) + #print "This is the output value\n", output_items[0][0] + #print "I am the oputput add python\n", eval(self.Exp) + return len(output_items[0]) + diff --git a/gr-input/python/Denominator.py b/gr-input/python/Denominator.py new file mode 100644 index 000000000..5d256f136 --- /dev/null +++ b/gr-input/python/Denominator.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# +# Copyright 2015 <+YOU OR YOUR COMPANY+>. +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import time +import numpy +from gnuradio import gr + +class Denominator(gr.sync_block): + """ + docstring for block add_python + """ + def __init__(self,num_inputs): + number = num_inputs + a = [] + for i in range(0,number): + a.append(numpy.float32) + gr.sync_block.__init__(self, + name="Denominator", + in_sig=a, + out_sig=[numpy.float32]) + + def work(self, input_items, output_items): + b=[0,0,0,0,0,0,0,0,0,0] + try: + b[0] = input_items[0][0] + except IndexError: + pass + try: + b[1] = input_items[1][0] + except IndexError: + pass + try: + b[2] = input_items[2][0] + except IndexError: + pass + try: + b[3] = input_items[3][0] + except IndexError: + pass + try: + b[4] = input_items[4][0] + except IndexError: + pass + try: + b[5] = input_items[5][0] + except IndexError: + pass + try: + b[6] = input_items[6][0] + except IndexError: + pass + try: + b[7] = input_items[7][0] + except IndexError: + pass + try: + b[8] = input_items[8][0] + except IndexError: + pass + try: + b[9] = input_items[9][0] + except IndexError: + pass + + var = len(input_items) + out = output_items[0][:var] + out_arr=[] + time.sleep(0.001) + + for i in range(0,len(input_items)): + out_arr.append(b[i]) + out[:] = out_arr + return len(output_items[0][:]) + diff --git a/gr-input/python/Numerator.py b/gr-input/python/Numerator.py new file mode 100644 index 000000000..90b44e285 --- /dev/null +++ b/gr-input/python/Numerator.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# +# Copyright 2015 <+YOU OR YOUR COMPANY+>. +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import time +import numpy +from gnuradio import gr + +class Numerator(gr.sync_block): + """ + docstring for block add_python + """ + def __init__(self,num_inputs): + number = num_inputs + a = [] + for i in range(0,number): + a.append(numpy.float32) + gr.sync_block.__init__(self, + name="Numerator", + in_sig=a, + out_sig=[numpy.float32]) + + def work(self, input_items, output_items): + b=[0,0,0,0,0,0,0,0,0,0] + try: + b[0] = input_items[0][0] + except IndexError: + pass + try: + b[1] = input_items[1][0] + except IndexError: + pass + try: + b[2] = input_items[2][0] + except IndexError: + pass + try: + b[3] = input_items[3][0] + except IndexError: + pass + try: + b[4] = input_items[4][0] + except IndexError: + pass + try: + b[5] = input_items[5][0] + except IndexError: + pass + try: + b[6] = input_items[6][0] + except IndexError: + pass + try: + b[7] = input_items[7][0] + except IndexError: + pass + try: + b[8] = input_items[8][0] + except IndexError: + pass + try: + b[9] = input_items[9][0] + except IndexError: + pass + var = len(input_items) + o1 = output_items[0][:var] + out_arr=[] + time.sleep(0.001) + + for i in range(0,len(input_items)): + out_arr.append(b[i]) + o1[:] = out_arr + return len(output_items[0][:]) + diff --git a/gr-input/python/Response.py b/gr-input/python/Response.py new file mode 100644 index 000000000..b895ca77c --- /dev/null +++ b/gr-input/python/Response.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python +# +# Copyright 2015 <+YOU OR YOUR COMPANY+>. +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# +import sys +import time +import numpy +from gnuradio import gr +import sciscipy + +class Response(gr.sync_block): + """ + docstring for block add_python + """ + def __init__(self,order,itype,tstart,tstop,tstep): + sys.setrecursionlimit(2000) + a = [] + self.b = [0.0,0.0,0.0,0.0,0.0,0.0] + [float(i) for i in self.b] + self.c = [0,0,0,0,0,0] + [float(i) for i in self.c] + self.i = 0 + self.order=int(order)+1 + self.itype = itype + self.tstart = tstart + self.tstop = tstop + self.tstep = tstep + gr.sync_block.__init__(self, + name="Response", + in_sig=[numpy.float32,numpy.float32], + out_sig=[numpy.float32]) + + def find_resp(self,b,c): + if (self.itype == 11): + typo = "'imp'" + elif (self.itype == 12): + typo = "'step'" + else: + typo = "t" + string1 = "s=%s; h=syslin('c'," + string2 = str(b[4])+"*s^4+"+str(b[3])+"*s^3+"+str(b[2])+"*s^2+"+str(b[1])+"*s+"+str(b[0])+"," + string3 = str(c[4])+"*s^4+"+str(c[3])+"*s^3+"+str(c[2])+"*s^2+"+str(c[1])+"*s+"+str(c[0])+");" + string4 = "t="+str(self.tstart)+":"+str(self.tstep)+":"+str(self.tstop)+";" + string5 = "deff('u=input(t)','u=50');" + string6 = "r=tf2ss(h); a=csim("+typo+",t,r);" + string = string1+string2+string3+string4+string5+string6 + sciscipy.eval(string) + self.a = sciscipy.read("a") + + def work(self, input_items, output_items): + #sys.setrecursionlimit(1500) + k = self.order + + for i in range(0,k): + + self.b[i] = input_items[0][i] + for n,i in enumerate(self.b): + if i == 'nan': + self.b[n] = 0 + + + print "I am value of b\n",self.b + + + for j in range(0,k): + self.c[j] = input_items[1][j] + + for m,i in enumerate (self.c): + if n == 'nan': + self.c[m] = 0 + + print "I am vlaue of c\n", self.c + self.find_resp(self.b,self.c) + + + out = output_items[0] + self.i+=1 + if self.i >= len(self.a): + self.i = 0 + out[:] = numpy.float32(self.a[self.i]) + return len(output_items[0]) + + diff --git a/gr-input/python/Roots.py b/gr-input/python/Roots.py new file mode 100644 index 000000000..1057c8d76 --- /dev/null +++ b/gr-input/python/Roots.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python +# +# Copyright 2015 <+YOU OR YOUR COMPANY+>. +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import time +import numpy +from gnuradio import gr +import sciscipy + +class Roots(gr.sync_block): + """ + docstring for block add_python + """ + def __init__(self,order): + self.out = [0,0,0,0,0,0,0,0,0,0] + a = [] + self.b = [0,0,0,0,0,0] + self.order=int(order)+1 + self.number = int(order)*2 + for i in range(0,self.number): + a.append(numpy.float32) + gr.sync_block.__init__(self, + name="Roots", + in_sig=[numpy.float32], + out_sig=a) + + def find_roots(self,n): + string1 = "s=%s;" + string2 = "h2="+str(n[3])+"*s^3+"+str(n[2])+"*s^2+"+str(n[1])+"*s+"+str(n[0])+";[E1]=roots(h2);a11=real(E1(1));a12=imag(E1(1));b11 = real(E1(2));b12 = imag(E1(2));c11 = real(E1(3));c12 = imag(E1(3)); d11 = real(E1(4)); d12 = imag(E1(4)); e11 = real(E1(5)); e12 = imag(E1(5));" + string = string1+string2 + print "This is string\n", string + sciscipy.eval(string) + + + try: + self.a11 = sciscipy.read("a11") + print "I am a11", self.a11 + except TypeError: + self.a11 = 0 + try: + self.a12 = sciscipy.read("a12") + print "I am a12", self.a12 + except TypeError: + self.a12 = 0 + try: + self.b11 = sciscipy.read("b11") + print "I am b11", self.b11 + except TypeError: + self.b11 = 0 + try: + self.b12 = sciscipy.read("b12") + except TypeError: + self.b12 = 0 + try: + self.c11 = sciscipy.read("c11") + print "I am c11\n", self.c11 + except TypeError: + self.c11 = 0 + try: + self.c12 = sciscipy.read("c12") + print "I am c12\n", self.c12 + except TypeError: + self.c12 = 0 + try: + self.d11 = sciscipy.read("d11") + print "I am d11\n", self.d11 + except TypeError: + self.d11 = 0 + try: + self.d12 = sciscipy.read("d12") + except TypeError: + self.d12 = 0 + try: + self.e11 = sciscipy.read("e11") + except TypeError: + self.e11 = 0 + try: + self.e12 = sciscipy.read("e12") + except TypeError: + self.e12 = 0 + + def work(self, input_items, output_items): + +# print "I am here\n", output_items + k = self.order + for i in range(0,k): + self.b[i] = input_items[0][i] + + self.find_roots(self.b) + + + self.out[0] = numpy.float32(self.a11) + self.out[1] = numpy.float32(self.b11) + self.out[2] = numpy.float32(self.a12) + self.out[3] = numpy.float32(self.b12) + self.out[4] = numpy.float32(self.c11) + self.out[5] = numpy.float32(self.c12) + self.out[6] = numpy.float32(self.d11) + self.out[7] = numpy.float32(self.d12) + self.out[8] = numpy.float32(self.e11) + self.out[9] = numpy.float32(self.e12) + + + for i in range (0,self.number): + output_items[i][:]= self.out[i] + print "I am out item",output_items + + return len(output_items[0]) + + diff --git a/gr-input/python/Transfer_Function.py b/gr-input/python/Transfer_Function.py new file mode 100644 index 000000000..d53c55e48 --- /dev/null +++ b/gr-input/python/Transfer_Function.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python +# +# Copyright 2015 <+YOU OR YOUR COMPANY+>. +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import time +import numpy +from gnuradio import gr +import sciscipy + +class Transfer_Function(gr.sync_block): + """ + docstring for block add_python + """ + def __init__(self,order,itype,tstart,tstop,tstep): + a = [] + self.b = [0,0,0,0,0,0] + self.c = [0,0,0,0,0,0] + self.i = 0 + self.order=int(order)+1 + self.itype = itype + self.tstart = tstart + self.tstop = tstop + self.tstep = tstep + gr.sync_block.__init__(self, + name="tf_rises", + in_sig=[numpy.float32,numpy.float32], + out_sig=[numpy.float32]) + + #print "I am over slept" + #print len(self.ret_array) + + def find_resp(self,b,c): + if (self.itype == 11): + typo = "'imp'" + elif (self.itype == 12): + typo = "'step'" + else: + typo = "t" +# print "self b",self.b + string1 = "s=%s; h=syslin('c'," + string2 = str(b[4])+"*s^4+"+str(b[3])+"*s^3+"+str(b[2])+"*s^2+"+str(b[1])+"*s+"+str(b[0])+"," + string3 = str(c[4])+"*s^4+"+str(c[3])+"*s^3+"+str(c[2])+"*s^2+"+str(c[1])+"*s+"+str(c[0])+");" + string4 = "t="+str(self.tstart)+":"+str(self.tstep)+":"+str(self.tstop)+";" + string5 = "deff('u=input(t)','u=50');" + string6 = "r=tf2ss(h); a=csim("+typo+",t,r);" + string = string1+string2+string3+string4+string5+string6 + print "I am strin g",string + sciscipy.eval(string) + self.a = sciscipy.read("a") + print "value of a\n",self.a + + + + + + def work(self, input_items, output_items): + + print "input value:\n",input_items + for i in range(0,5): + self.b[i] = input_items[0][i] + # print "I am b[i]", b[i] + #print "I am BBBBB", self.b + + for j in range(0,5): + self.c[j] = input_items[1][j] + #print "I am c[j]", c[j] + #print "I am CCCCC", self.c + self.find_resp(self.b,self.c) + + + out = output_items[0] + self.i+=1 + print "I am self i\n",self.i + if self.i >= len(self.a): + self.i = 0 + print "len of out\n",len(out) + #time.sleep(0.125) + out[:] = numpy.float32(self.a[self.i]) + #print + print "i am out\n",out + + return len(output_items[0]) + + diff --git a/gr-input/python/__init__.py b/gr-input/python/__init__.py new file mode 100644 index 000000000..6e8ef1f55 --- /dev/null +++ b/gr-input/python/__init__.py @@ -0,0 +1,53 @@ +# +# Copyright 2008,2009 Free Software Foundation, Inc. +# +# This application is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This application is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +# The presence of this file turns this directory into a Python package + +''' +This is the GNU Radio SCIGEN module. Place your Python package +description here (python/__init__.py). +''' + +# ---------------------------------------------------------------- +# Temporary workaround for ticket:181 (swig+python problem) +import sys +_RTLD_GLOBAL = 0 +try: + from dl import RTLD_GLOBAL as _RTLD_GLOBAL +except ImportError: + try: + from DLFCN import RTLD_GLOBAL as _RTLD_GLOBAL + except ImportError: + pass + +if _RTLD_GLOBAL != 0: + _dlopenflags = sys.getdlopenflags() + sys.setdlopenflags(_dlopenflags|_RTLD_GLOBAL) +# ---------------------------------------------------------------- + + +# import any pure python here +import serial + +# + +# ---------------------------------------------------------------- +# Tail of workaround +if _RTLD_GLOBAL != 0: + sys.setdlopenflags(_dlopenflags) # Restore original flags +# ---------------------------------------------------------------- diff --git a/gr-input/python/gr_ramp_source.py b/gr-input/python/gr_ramp_source.py new file mode 100644 index 000000000..574f9f70b --- /dev/null +++ b/gr-input/python/gr_ramp_source.py @@ -0,0 +1,46 @@ +#!/usr/bin/python + +import gras +import numpy +# Serial is imported in __init__ +class ramp(gras.Block): + + + def __init__(self): + gras.Block.__init__(self, + name="ser", + in_sig=[numpy.float32], + out_sig=[numpy.float32]) + self.i = 0 + self.flag=True + + def set_parameters(self, ramp_slope, height_Offset, width_Offset): + self.slope = ramp_slope + self.width = width_Offset + self.offset = height_Offset + + def work(self, input_items, output_items): + + out = output_items[0][0:1] + input_stream = input_items[0][0] + + if self.flag: + for j in range(self.width): + out = self.offset + print "OUT", out + + self.produce(0,1) # Produce from port 0 output_items + self.consume(0,1) # Consume from port 0 input_items + + self.flag = False + + else: + + self.i = self.i + 1 + out[:1] =self.offset + self.i*input_stream*self.slope + + print "OUT", out + + self.produce(0,1) # Produce from port 0 output_items + self.consume(0,1) # Consume from port 0 input_items + diff --git a/gr-input/python/gr_step_source.py b/gr-input/python/gr_step_source.py new file mode 100644 index 000000000..904f89292 --- /dev/null +++ b/gr-input/python/gr_step_source.py @@ -0,0 +1,43 @@ +#!/usr/bin/python + +import gras +import numpy +# Serial is imported in __init__ +class step(gras.Block): + + + def __init__(self): + gras.Block.__init__(self, + name="ser", + in_sig=[numpy.float32], + out_sig=[numpy.float32]) + self.flag=True + + def set_parameters(self, step_size, offset, width): + self.step_size = step_size + self.width = width + self.offset = offset + + def work(self, input_items, output_items): + + out = output_items[0][0:1] + input_stream = input_items[0][0] + + if self.flag: + for i in range(self.width): + out[:1] = self.offset + print "OUT", out + + self.produce(0,1) # Produce from port 0 output_items + self.consume(0,1) # Consume from port 0 input_items + + self.flag = False + + else: + out[:1] = self.offset + input_stream*self.step_size + + print "OUT", out + + self.produce(0,1) # Produce from port 0 output_items + self.consume(0,1) # Consume from port 0 input_items + diff --git a/gr-input/python/matplotsink.py b/gr-input/python/matplotsink.py new file mode 100755 index 000000000..105009b4d --- /dev/null +++ b/gr-input/python/matplotsink.py @@ -0,0 +1,312 @@ +""" +$$ + +Modified for working as a GNU Radio block +Rakesh Peter (rakesh.peter@gmail.com) +Last modified: 07.05.2010 + +$$ + +This demo demonstrates how to draw a dynamic mpl (matplotlib) +plot in a wxPython application. + +It allows "live" plotting as well as manual zooming to specific +regions. + +Both X and Y axes allow "auto" or "manual" settings. For Y, auto +mode sets the scaling of the graph to see all the data points. +For X, auto mode makes the graph "follow" the data. Set it X min +to manual 0 to always see the whole data from the beginning. + +Note: press Enter in the 'manual' text box to make a new value +affect the plot. + +Eli Bendersky (eliben@gmail.com) +License: this code is in the public domain +Last modified: 31.07.2008 +""" + +import os +import pprint +import random +import sys +import wx +import gnuradio.grc.gui +from gnuradio.grc.gui import Actions,ActionHandler +# The recommended way to use wx with mpl is with the WXAgg +# backend. +# +import matplotlib +import matplotlib.pyplot as plt +import matplotlib.animation as animation +#matplotlib.use('WXAgg') +from matplotlib.figure import Figure +from matplotlib.backends.backend_wxagg import \ + FigureCanvasWxAgg as FigCanvas, \ + NavigationToolbar2WxAgg as NavigationToolbar +import numpy as np +import pylab + + +class DataGen(object): + """ A silly class that generates pseudo-random data for + display in the plot. + """ + def __init__(self, init=50): + self.data = self.init = init + + def next(self): + self._recalc_data() + #return self.data + return [0.0,1.1,2.2,3.3] + + def _recalc_data(self): + delta = random.uniform(-0.5, 0.5) + r = random.random() + + if r > 0.9: + self.data += delta * 15 + elif r > 0.8: + # attraction to the initial value + delta += (0.5 if self.init > self.data else -0.5) + self.data += delta + else: + self.data += delta + + + +class matplotsink(wx.Panel): + + def __init__(self, parent, title, queue,gsz,zoom): + wx.Panel.__init__(self, parent, wx.SIMPLE_BORDER) + + self.gsz = gsz + self.parent = parent + self.title = title + self.q = queue + self.zoom=zoom + self.paused = False + +# self.create_menu() +# self.create_status_bar() + self.create_main_panel() + + + def create_menu(self): + self.menubar = wx.MenuBar() + + menu_file = wx.Menu() + m_expt = menu_file.Append(-1, "&Save plot\tCtrl-S", "Save plot to file") + self.Bind(wx.EVT_MENU, self.on_save_plot, m_expt) + menu_file.AppendSeparator() + m_exit = menu_file.Append(-1, "E&xit\tCtrl-X", "Exit") + self.Bind(wx.EVT_MENU, self.on_exit, m_exit) + self.menubar.Append(menu_file, "&File") + self.SetMenuBar(self.menubar) + + + def create_main_panel(self): + self.panel = self + + self.init_plot() + self.canvas = FigCanvas(self.panel, -1, self.fig) + self.scroll_range = 400 + self.canvas.SetScrollbar(wx.HORIZONTAL,0,5,self.scroll_range) + self.canvas.Bind(wx.EVT_SCROLLWIN,self.OnScrollEvt) + + + self.pause_button = wx.Button(self.panel, -1, "Pause") + self.Bind(wx.EVT_BUTTON, self.on_pause_button, self.pause_button) + self.Bind(wx.EVT_UPDATE_UI, self.on_update_pause_button, self.pause_button) + + self.cb_grid = wx.CheckBox(self.panel, -1, + "Show Grid", + style=wx.ALIGN_RIGHT) + self.Bind(wx.EVT_CHECKBOX, self.on_cb_grid, self.cb_grid) + self.cb_grid.SetValue(True) + + self.cb_xlab = wx.CheckBox(self.panel, -1, + "Show X labels", + style=wx.ALIGN_RIGHT) + self.Bind(wx.EVT_CHECKBOX, self.on_cb_xlab, self.cb_xlab) + self.cb_xlab.SetValue(True) + + self.hbox1 = wx.BoxSizer(wx.HORIZONTAL) + self.hbox1.Add(self.pause_button, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) + self.hbox1.AddSpacer(20) + self.hbox1.Add(self.cb_grid, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) + self.hbox1.AddSpacer(10) + self.hbox1.Add(self.cb_xlab, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL) + + + self.vbox = wx.BoxSizer(wx.VERTICAL) + self.vbox.Add(self.canvas, 1, flag=wx.LEFT | wx.TOP | wx.GROW) + self.vbox.Add(self.hbox1, 0, flag=wx.ALIGN_LEFT | wx.TOP) + + self.panel.SetSizer(self.vbox) + self.vbox.Fit(self) + self.ani=animation.FuncAnimation(self.fig,self.draw_plot,interval=100) + + def OnScrollEvt(self,event): + self.i_start = event.GetPosition() + self.i_end = self.i_window + event.GetPosition() + self.draw_plot(0) + + def create_status_bar(self): + self.statusbar = self.CreateStatusBar() + + def draw_test(self,event): + self.xar=np.arange(len(self.q.queue)) + self.yar=np.array(self.q.queue) + self.axes.plot(self.xar,self.yar) + + def init_plot(self): + self.dpi = 100 + self.fig = Figure((3.0, 3.0), dpi=self.dpi) + self.fig.set_size_inches(7.0,4.0) + self.fig.set_dpi(self.dpi) + + self.axes = self.fig.add_subplot(111) + self.axes.set_axis_bgcolor('black') + self.axes.set_title(self.title, size=12) + + pylab.setp(self.axes.get_xticklabels(), fontsize=8) + pylab.setp(self.axes.get_yticklabels(), fontsize=8) + self.i_window = self.gsz + self.i_start = 0 + self.i_end = self.i_start + self.i_window + # plot the data as a line series, and save the reference + # to the plotted line series + # + self.plot_data = self.axes.plot( + [], + linewidth=1, + color=(1, 1, 0), + )[0] + + + def draw_plot(self,event): + """ Redraws the plot + """ + if len(list(self.q.queue))>1 and not self.paused: + + if self.zoom: + xmax = len(list(self.q.queue)) if len(list(self.q.queue)) > 50 else 50 + + xmin = xmax - 50 + # for ymin and ymax, find the minimal and maximal values + # in the data set and add a mininal margin. + # + # note that it's easy to change this scheme to the + # minimal/maximal value in the current display, and not + # the whole data set. + # + ymin = round(min(list(self.q.queue)), 0) - 1 + + ymax = round(max(list(self.q.queue)), 0) + 1 + + self.axes.set_xbound(lower=xmin, upper=xmax) + self.axes.set_ybound(lower=ymin, upper=ymax) + + # anecdote: axes.grid assumes b=True if any other flag is + # given even if b is set to False. + # so just passing the flag into the first statement won't + # work. + # + if self.cb_grid.IsChecked(): + self.axes.grid(True, color='gray') + else: + self.axes.grid(False) + + # Using setp here is convenient, because get_xticklabels + # returns a list over which one needs to explicitly + # iterate, and setp already handles this. + # + pylab.setp(self.axes.get_xticklabels(), + visible=self.cb_xlab.IsChecked()) + + + self.plot_data.set_xdata(np.arange(len(list(self.q.queue)))) + self.plot_data.set_ydata(np.array(list(self.q.queue))) + self.canvas.draw() + + else: + if self.cb_grid.IsChecked(): + self.axes.grid(True, color='gray') + else: + self.axes.grid(False) + + # Using setp here is convenient, because get_xticklabels + # returns a list over which one needs to explicitly + # iterate, and setp already handles this. + + pylab.setp(self.axes.get_xticklabels(), + visible=self.cb_xlab.IsChecked()) + + self.plot_data.set_xdata(np.arange(len(list(self.q.queue)))[self.i_start:self.i_end]) + self.plot_data.set_ydata(np.array(list(self.q.queue))[self.i_start:self.i_end]) + self.axes.set_xlim(min(np.arange(len(list(self.q.queue)))[self.i_start:self.i_end]),max(np.arange(len(list(self.q.queue)))[self.i_start:self.i_end])) + # if self.zoom: + self.axes.set_ylim(min(np.array(list(self.q.queue))),max(np.array(list(self.q.queue)))) + + self.canvas.draw() + + + + def on_pause_button(self, event): + self.paused = not self.paused + + def on_update_pause_button(self, event): + label = "Resume" if self.paused else "Pause" + self.pause_button.SetLabel(label) + + def on_cb_grid(self, event): + self.draw_plot(0) + + def on_cb_xlab(self, event): + self.draw_plot(0) + + def on_save_plot(self, event): + file_choices = "PNG (*.png)|*.png" + + dlg = wx.FileDialog( + self, + message="Save plot as...", + defaultDir=os.getcwd(), + defaultFile="plot.png", + wildcard=file_choices, + style=wx.SAVE) + + if dlg.ShowModal() == wx.ID_OK: + path = dlg.GetPath() + self.canvas.print_figure(path, dpi=self.dpi) + self.flash_status_message("Saved to %s" % path) + + def on_redraw_timer(self, event): + # if paused do not add data, but still redraw the plot + # (to respond to scale modifications, grid change, etc.) + # + if not self.paused: + self.data += self.datagen.next() + self.draw_plot(0) + + + def on_exit(self, event): + self.Destroy() + + def flash_status_message(self, msg, flash_len_ms=1500): + self.statusbar.SetStatusText(msg) + self.timeroff = wx.Timer(self) + self.Bind( + wx.EVT_TIMER, + self.on_flash_status_off, + self.timeroff) + self.timeroff.Start(flash_len_ms, oneShot=True) + + def on_flash_status_off(self, event): + self.statusbar.SetStatusText('') + + + + + diff --git a/gr-input/python/plot_sink.py b/gr-input/python/plot_sink.py new file mode 100755 index 000000000..1c1def3fc --- /dev/null +++ b/gr-input/python/plot_sink.py @@ -0,0 +1,57 @@ +# Hacked from blks2/variable_sink.py +# Requires modified Matplotsink code + +from gnuradio import gr +import threading +import numpy +import matplotsink +import Queue + +class _plot_sink_base(gr.hier_block2, threading.Thread): + """ + The thread polls the message queue for values and writes to matplotsink callback + """ + + def __init__(self, parent, title, vlen, decim,gsz,zoom): + self._vlen = vlen + self._parent = parent + self._title = title + print "Initing block: %s" % title + + self.plotQueue = Queue.Queue() + self.win = matplotsink.matplotsink(parent,title, self.plotQueue,gsz,zoom) + + self._item_size = self._size*self._vlen + #init hier block + gr.hier_block2.__init__( + self, 'plot_sink', + gr.io_signature(1, 1, self._item_size), + gr.io_signature(0, 0, 0), + ) + #create blocks + self._msgq = gr.msg_queue(2) + message_sink = gr.message_sink(self._item_size, self._msgq, False) + #connect + self.connect(self, message_sink) + #setup thread + threading.Thread.__init__(self) + self.setDaemon(True) + self.start() + + def set_decim(self, decim): self._decimator.set_n(decim) + + def run(self): + while True: #truncate to item size, convert to array, callback + msg = self._msgq.delete_head().to_string()[-self._item_size:] + arr = map(self._cast, numpy.fromstring(msg, self._numpy)) + print "Sending value:" , arr + self.plotQueue.put(self._vlen > 1 and arr or arr[0]) + + def print_callback(self, array): + print array + +class plot_sink_b(_plot_sink_base): _numpy, _size, _cast = numpy.int8, gr.sizeof_char, int +class plot_sink_s(_plot_sink_base): _numpy, _size, _cast = numpy.int16, gr.sizeof_short, int +class plot_sink_i(_plot_sink_base): _numpy, _size, _cast = numpy.int32, gr.sizeof_int, int +class plot_sink_f(_plot_sink_base): _numpy, _size, _cast = numpy.float32, gr.sizeof_float, float +class plot_sink_c(_plot_sink_base): _numpy, _size, _cast = numpy.complex64, gr.sizeof_gr_complex, complex diff --git a/gr-input/python/plzr_plot.py b/gr-input/python/plzr_plot.py new file mode 100644 index 000000000..e1b0ff3fc --- /dev/null +++ b/gr-input/python/plzr_plot.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# +# Copyright 2015 <+YOU OR YOUR COMPANY+>. +# +# This is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# This software is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this software; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# +import sys +import time +import numpy +from gnuradio import gr +import sciscipy + +class plzr_plot(gr.sync_block): + """ + docstring for block add_python + """ + def __init__(self,order): + sys.setrecursionlimit(2000) + a = [] +# self.flag = 0 + self.b = [0,0,0,0,0,0] + self.c = [0,0,0,0,0,0] + self.i = 0 + self.order=int(order)+1 + gr.sync_block.__init__(self, + name="plzr_plot", + in_sig=[numpy.float32,numpy.float32], + out_sig=None) + + def plot(self,b,c): + string1 = "s=%s; h=syslin('c'," + string2 = str(b[4])+"*s^4+"+str(b[3])+"*s^3+"+str(b[2])+"*s^2+"+str(b[1])+"*s+"+str(b[0])+"," + string3 = str(c[4])+"*s^4+"+str(c[3])+"*s^3+"+str(c[2])+"*s^2+"+str(c[1])+"*s+"+str(c[0])+");" + string4 = "plzr(h);" + + string = string1 + string2 +string3 + string4 + sciscipy.eval(string) + + + + def work(self, input_items, output_items): + print "I am input", input_items + print "I am output", output_items + k = self.order + for i in range(0,k): + self.b[i] = input_items[0][i] + print "I am value of b\n",self.b + + + for j in range(0,k): + self.c[j] = input_items[1][j] + print "I am vlaue of c\n", self.c + + self.plot(self.b,self.c) + in0 = input_items[0] + # <+signal processing here+> + return len(input_items[0]) + diff --git a/gr-input/python/ramp_hierblock.py b/gr-input/python/ramp_hierblock.py new file mode 100644 index 000000000..950615142 --- /dev/null +++ b/gr-input/python/ramp_hierblock.py @@ -0,0 +1,19 @@ +import gras +import numpy +from gnuradio import gr +from gnuradio import blocks + +# Source block1 import +import gr_ramp_source +from gnuradio import blocks + +class HierBlock(gr.hier_block2): + def __init__(self,ramp_slope, height_Offset, width_Offset): + gr.hier_block2.__init__(self,"HierBlock",gr.io_signature(1,1,gr.sizeof_float), gr.io_signature(1,2,gr.sizeof_float)) + #constant_block initialized + self.constant_block = gr.sig_source_f(0,gr.GR_CONST_WAVE,0,0,1) + #ramp_source block initialized + self.ramp_source=gr_ramp_source.ramp() + self.ramp_source.set_parameters(ramp_slope, height_Offset, width_Offset) + self.connect(self,(self.constant_block,0),(self.ramp_source,0),self) + diff --git a/gr-input/python/step_hierblock.py b/gr-input/python/step_hierblock.py new file mode 100644 index 000000000..4243606d6 --- /dev/null +++ b/gr-input/python/step_hierblock.py @@ -0,0 +1,22 @@ +import gras +import numpy +from gnuradio import gr +from gnuradio import blocks + +# Source block1 import +import gr_step_source +from gnuradio import blocks + +class HierBlock(gr.hier_block2): + def __init__(self, step_size, H_Off, W_Off): + gr.hier_block2.__init__(self, "HierBlock", + gr.io_signature(1,1,gr.sizeof_float), + gr.io_signature(1,2,gr.sizeof_float)) + + # constant_block initialized + self.constant_block = gr.sig_source_f(0, gr.GR_CONST_WAVE,0,0,1) + # step_source block initialized + self.step_source = gr_step_source.step() + self.step_source.set_parameters(step_size, H_Off, W_Off) + self.connect(self, (self.constant_block,0) , (self.step_source,0), self) + -- cgit