diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-controls/CMakeLists.txt | 55 | ||||
-rw-r--r-- | gr-controls/doc/CMakeLists.txt | 23 | ||||
-rw-r--r-- | gr-controls/doc/README.controls | 13 | ||||
-rw-r--r-- | gr-controls/doc/controls.dox | 29 | ||||
-rw-r--r-- | gr-controls/grc/CMakeLists.txt | 30 | ||||
-rw-r--r-- | gr-controls/grc/controls_csim.xml | 132 | ||||
-rw-r--r-- | gr-controls/grc/controls_dsim.xml | 138 | ||||
-rw-r--r-- | gr-controls/python/CMakeLists.txt | 94 | ||||
-rw-r--r-- | gr-controls/python/__init__.py | 55 | ||||
-rw-r--r-- | gr-controls/python/controls_csim.py | 1 | ||||
-rw-r--r-- | gr-controls/python/controls_dsim.py | 1 | ||||
-rw-r--r-- | gr-controls/python/csim.py | 44 | ||||
-rwxr-xr-x | gr-controls/python/csim_sci.py | 38 | ||||
-rw-r--r-- | gr-controls/python/dsim.py | 43 | ||||
-rw-r--r-- | gr-controls/python/dsim_sci.py | 36 | ||||
-rwxr-xr-x | gr-controls/python/qa_dsim.py | 69 |
17 files changed, 802 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index be47aab34..fefdaab75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -262,6 +262,7 @@ add_subdirectory(gr-utils) add_subdirectory(gr-wxgui) add_subdirectory(gr-blocks) add_subdirectory(gr-scigen) +add_subdirectory(gr-controls) #finalize cpack after subdirs processed include(GrPackage) diff --git a/gr-controls/CMakeLists.txt b/gr-controls/CMakeLists.txt new file mode 100644 index 000000000..d3a1f06a5 --- /dev/null +++ b/gr-controls/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-controls" ENABLE_GR_CONTROLS + ENABLE_GRUEL + ENABLE_VOLK + Boost_FOUND + ENABLE_GR_CORE +) + +######################################################################## +# Begin conditional configuration +######################################################################## +if(ENABLE_GR_SCIGEN) + +######################################################################## +# Add subdirectories +######################################################################## +if(ENABLE_PYTHON) + add_subdirectory(python) + add_subdirectory(grc) +endif(ENABLE_PYTHON) +#add_subdirectory(examples) +add_subdirectory(doc) + + +endif(ENABLE_GR_CONTROLS) diff --git a/gr-controls/doc/CMakeLists.txt b/gr-controls/doc/CMakeLists.txt new file mode 100644 index 000000000..3c0bc1a02 --- /dev/null +++ b/gr-controls/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.controls + DESTINATION ${GR_PKG_DOC_DIR} +) diff --git a/gr-controls/doc/README.controls b/gr-controls/doc/README.controls new file mode 100644 index 000000000..61e8f6bf8 --- /dev/null +++ b/gr-controls/doc/README.controls @@ -0,0 +1,13 @@ +This is the gr-scigen package. It contains signal processing blocks to +perform FFTs and FFT-related functionality. + +The Python namespace is in gnuradio.scigen, which would be normally +imported as: + + from gnuradio import scigen + +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: + + help(scigen) diff --git a/gr-controls/doc/controls.dox b/gr-controls/doc/controls.dox new file mode 100644 index 000000000..8843d0560 --- /dev/null +++ b/gr-controls/doc/controls.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-controls/grc/CMakeLists.txt b/gr-controls/grc/CMakeLists.txt new file mode 100644 index 000000000..6433376fa --- /dev/null +++ b/gr-controls/grc/CMakeLists.txt @@ -0,0 +1,30 @@ +# 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 + controls_dsim.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "controls_python" +) + +install(FILES + controls_csim.xml + DESTINATION ${GRC_BLOCKS_DIR} + COMPONENT "controls_python" +) diff --git a/gr-controls/grc/controls_csim.xml b/gr-controls/grc/controls_csim.xml new file mode 100644 index 000000000..0b2b38874 --- /dev/null +++ b/gr-controls/grc/controls_csim.xml @@ -0,0 +1,132 @@ +<?xml version="1.0"?> +<!-- +################################################### +## +CSIM Block: +## all types, 1 output, 2 to inf inputs +################################################### + --> +<block> + <name>csim</name> + <key>controls_csim</key> + <category>controls</category> + + <import>from gnuradio import controls_csim</import> + <make>controls_csim.csim() +self.$(id).set_parameters($P, $I, $D, $n0, $n1, $d0, $d1, $window) + </make> + <param> + <name>IO Type</name> + <key>type</key> + <type>enum</type> + <option><name>FC32_FC32</name><key>fc32_fc32</key></option> + <option><name>F32_F32</name><key>f32_f32</key></option> + <option><name>SC32_SC32</name><key>sc32_sc32</key></option> + <option><name>S32_S32</name><key>s32_s32</key></option> + <option><name>SC16_SC16</name><key>sc16_sc16</key></option> + <option><name>S16_S16</name><key>s16_s16</key></option> + <option><name>SC8_SC8</name><key>sc8_sc8</key></option> + <option><name>S8_S8</name><key>s8_s8</key></option> + </param> + <param> + <name>Num Inputs</name> + <key>num_inputs</key> + <value>1</value> + <type>int</type> + </param> + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + + <!-- + Desimulation options + --> + <param> + <name>Controller Gain(P)</name> + <key>P</key> + <value>0</value> + <type>real</type> + </param> + <param> + <name>Tau_I(I)</name> + <key>I</key> + <value>0</value> + <type>real</type> + </param> + <param> + <name>Tau_D(D)</name> + <key>D</key> + <value>0</value> + <type>real</type> + </param> + + <param> + <name>n0</name> + <key>n0</key> + <value>0</value> + <type>real</type> + </param> + + <param> + <name>n1</name> + <key>n1</key> + <value>0</value> + <type>real</type> + </param> + <param> + <name>d0</name> + <key>d0</key> + <value>0</value> + <type>real</type> + </param> + + <param> + <name>d1</name> + <key>d1</key> + <value>0</value> + <type>real</type> + </param> + + <param> + <name>window</name> + <key>window</key> + <value>0</value> + <type>real</type> + </param> + + + <!-- + Check if number of inputs are greater than 0, and if vector length + is greater than 0. + --> + <check>$num_inputs > 0</check> + <check>$vlen > 0</check> + <sink> + <name>in</name> + <type>$(str($type).split('_')[0])</type> + <vlen>$vlen</vlen> + <nports>$num_inputs</nports> + </sink> + <source> + <name>out</name> + <type>$(str($type).split('_')[1])</type> + <vlen>$vlen</vlen> + </source> + <doc> + +Continuous time simulation + +out[i] = in0[i] + in1[i] + in2[i] + +The math block adds an arbitrary number of input streams element by element, \ +and produces and single output stream. Elements may be single numbers, \ +or vectors of numbers, depending upon the value of the vec length parameter. + +The preload parameter allows users to implement feedback loops with this math block. \ +For example, to enable a feedback of 1 on the 2nd port, set preload to [0, 0, 1]. \ + </doc> +</block> + diff --git a/gr-controls/grc/controls_dsim.xml b/gr-controls/grc/controls_dsim.xml new file mode 100644 index 000000000..149f88186 --- /dev/null +++ b/gr-controls/grc/controls_dsim.xml @@ -0,0 +1,138 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Add Block: +## all types, 1 output, 2 to inf inputs +################################################### + --> +<block> + <name>dsim</name> + <key>controls_dsim</key> + <category>controls</category> + + <import>from gnuradio import controls_dsim</import> + <make>controls_dsim.dsim() +self.$(id).set_parameters($P, $I, $D, $n0, $n1, $step, $d0, $d1, $window) + </make> + <param> + <name>IO Type</name> + <key>type</key> + <type>enum</type> + <option><name>FC32_FC32</name><key>fc32_fc32</key></option> + <option><name>F32_F32</name><key>f32_f32</key></option> + <option><name>SC32_SC32</name><key>sc32_sc32</key></option> + <option><name>S32_S32</name><key>s32_s32</key></option> + <option><name>SC16_SC16</name><key>sc16_sc16</key></option> + <option><name>S16_S16</name><key>s16_s16</key></option> + <option><name>SC8_SC8</name><key>sc8_sc8</key></option> + <option><name>S8_S8</name><key>s8_s8</key></option> + </param> + <param> + <name>Num Inputs</name> + <key>num_inputs</key> + <value>1</value> + <type>int</type> + </param> + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + + <!-- + Desimulation options + --> + <param> + <name>Controller Gain(P)</name> + <key>P</key> + <value>0</value> + <type>real</type> + </param> + <param> + <name>Tau_I(I)</name> + <key>I</key> + <value>0</value> + <type>real</type> + </param> + <param> + <name>Tau_D(D)</name> + <key>D</key> + <value>0</value> + <type>real</type> + </param> + + <param> + <name>n0</name> + <key>n0</key> + <value>0</value> + <type>real</type> + </param> + + <param> + <name>n1</name> + <key>n1</key> + <value>0</value> + <type>real</type> + </param> + + <param> + <name>step</name> + <key>step</key> + <value>0</value> + <type>real</type> + </param> + + <param> + <name>d0</name> + <key>d0</key> + <value>0</value> + <type>real</type> + </param> + + <param> + <name>d1</name> + <key>d1</key> + <value>0</value> + <type>real</type> + </param> + + <param> + <name>window</name> + <key>window</key> + <value>0</value> + <type>real</type> + </param> + + + <!-- + Check if number of inputs are greater than 0, and if vector length + is greater than 0. + --> + <check>$num_inputs > 0</check> + <check>$vlen > 0</check> + <sink> + <name>in</name> + <type>$(str($type).split('_')[0])</type> + <vlen>$vlen</vlen> + <nports>$num_inputs</nports> + </sink> + <source> + <name>out</name> + <type>$(str($type).split('_')[1])</type> + <vlen>$vlen</vlen> + </source> + <doc> + +Discrete time simulation + +out[i] = in0[i] + in1[i] + in2[i] + +The math block adds an arbitrary number of input streams element by element, \ +and produces and single output stream. Elements may be single numbers, \ +or vectors of numbers, depending upon the value of the vec length parameter. + +The preload parameter allows users to implement feedback loops with this math block. \ +For example, to enable a feedback of 1 on the 2nd port, set preload to [0, 0, 1]. \ + </doc> +</block> diff --git a/gr-controls/python/CMakeLists.txt b/gr-controls/python/CMakeLists.txt new file mode 100644 index 000000000..b83cb675d --- /dev/null +++ b/gr-controls/python/CMakeLists.txt @@ -0,0 +1,94 @@ +# 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/controls + COMPONENT "controls_python" +) + +### CSIM BLOCKS ### +GR_PYTHON_INSTALL( + FILES + controls_csim.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/controls + COMPONENT "controls_python" +) + + +GR_PYTHON_INSTALL( + FILES + csim.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/controls + COMPONENT "controls_python" +) + +GR_PYTHON_INSTALL( + FILES + csim_sci.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/controls + COMPONENT "controls_python" +) + +### DSIM BLOCKS ### +GR_PYTHON_INSTALL( + FILES + controls_dsim.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/controls + COMPONENT "controls_python" +) + +GR_PYTHON_INSTALL( + FILES + dsim.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/controls + COMPONENT "controls_python" +) + +GR_PYTHON_INSTALL( + FILES + dsim_sci.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/controls + COMPONENT "controls_python" +) + + + + +######################################################################## +# Handle the unit tests +######################################################################## +if(ENABLE_TESTING) + +list(APPEND GR_TEST_PYTHON_DIRS + ${CMAKE_BINARY_DIR}/gr-controls/python +) +list(APPEND GR_TEST_TARGET_DEPS gnuradio-controls) + +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-controls/python/__init__.py b/gr-controls/python/__init__.py new file mode 100644 index 000000000..ed63150cf --- /dev/null +++ b/gr-controls/python/__init__.py @@ -0,0 +1,55 @@ +# +# 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 SCIMOD 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 swig generated symbols into the scimod namespace +from scimod_swig import * + +# import any pure python here +from dsim import dsim +# + +# ---------------------------------------------------------------- +# Tail of workaround +if _RTLD_GLOBAL != 0: + sys.setdlopenflags(_dlopenflags) # Restore original flags +# ---------------------------------------------------------------- diff --git a/gr-controls/python/controls_csim.py b/gr-controls/python/controls_csim.py new file mode 100644 index 000000000..45344b60d --- /dev/null +++ b/gr-controls/python/controls_csim.py @@ -0,0 +1 @@ +from csim import * diff --git a/gr-controls/python/controls_dsim.py b/gr-controls/python/controls_dsim.py new file mode 100644 index 000000000..aca638a40 --- /dev/null +++ b/gr-controls/python/controls_dsim.py @@ -0,0 +1 @@ +from dsim import * diff --git a/gr-controls/python/csim.py b/gr-controls/python/csim.py new file mode 100644 index 000000000..3d91eaf15 --- /dev/null +++ b/gr-controls/python/csim.py @@ -0,0 +1,44 @@ +#!/usr/bin/python +import gras +import numpy + +class csim(gras.Block): + + def __init__(self): + gras.Block.__init__(self, + name="csim", + in_sig=[numpy.float32], + out_sig=[numpy.float32]) + + def set_parameters(self,p,i,d,a,b,d1,e,f): + self.param1 = p + self.param2 = i + self.param3 = d + self.param4 = a #n0 + self.param5 = b #n1 + self.param6 = d1 #d0 + self.param7 = e #d1 + self.n = f #window + + def isIntegralWin(self, input_item, window): + if (len(input_item) % window ): + raise Exception("Value of Window should be an integral value of length of input items") + + def work(self, input_items, output_items): + + #n = min(len(input_items[0]), len(output_items[0])) + in0 = input_items[0] + out = output_items[0] + + from csim_sci import csim + #Processing + # Assuming n = 1 input_config(0)=1 + + out[:self.n] = csim(self.param1, self.param2, self.param3, self.param4, + self.param5, self.param6, self.param7, in0[:self.n].tolist()) # IMP: in0[:self.n].tolist() passes a python array, without which window cannot be raised above certain value | numpy.array bug + + print "OUT", out[:self.n] + + self.consume(0,self.n) # Consume from port 0 input_items + self.produce(0,self.n) # Produce from port 0 output_items + diff --git a/gr-controls/python/csim_sci.py b/gr-controls/python/csim_sci.py new file mode 100755 index 000000000..3d900bc40 --- /dev/null +++ b/gr-controls/python/csim_sci.py @@ -0,0 +1,38 @@ +#!/usr/bin/python + +import sciscipy + + +# u is a TUPLE vector of width w + +def csim(P,I,D,n0,n1,d0,d1,u): + code_string1 = "s=%s;" + code_string2 = "Gc=syslin('c',("+str(P*I+D)+"*s)"+","+str(I)+"*s);" + code_string3 = "G=syslin(" + code_string4 = "'c'"+","+str(n0)+"*s"+"+"+str(n1)+","+str(d0)+"*s"+"+"+str(d1)+");" + code_string5 = "r=tf2ss(G*Gc);" + code_string6 = "u="+str((u))+";" + code_string7 = "y=csim(u,1:length(u),r)" + code_string = code_string1+code_string2+code_string3+code_string4+code_string5+code_string6+code_string7 + print(code_string) + + import sciscipy + sciscipy.eval(code_string) + y = sciscipy.read("y") + return y + #print "y" + import matplotlib.pyplot as plt + plt.plot(y) + plt.show() + + +if __name__ == "__main__": + u = [0]*100 + u[50] = 1 + out = csim(2,0.5,0.6,1,1,2,1,u) + print out + + import matplotlib.pyplot as plt + plt.plot(out) + plt.show() + diff --git a/gr-controls/python/dsim.py b/gr-controls/python/dsim.py new file mode 100644 index 000000000..3e5e4c8ec --- /dev/null +++ b/gr-controls/python/dsim.py @@ -0,0 +1,43 @@ +import gras +import numpy + +class dsim(gras.Block): + + def __init__(self): + gras.Block.__init__(self, + name="dsim", + in_sig=[numpy.float32], + out_sig=[numpy.float32]) + + def set_parameters(self,p,i,d,a,b,c,d1,e,f): + self.param1 = p + self.param2 = i + self.param3 = d + self.param4 = a #n0 + self.param5 = b #n1 + self.param6 = c #st + self.param7 = d1 #d0 + self.param8 = e #d1 + self.n = f #window + + def isIntegralWin(self, input_item, window): + if (len(input_item) % window ): + raise Exception("Value of Window should be an integral value of length of input items") + + def work(self, input_items, output_items): + + #n = min(len(input_items[0]), len(output_items[0])) + in0 = input_items[0] + out = output_items[0] + + from dsim_sci import discrete_sim + #Processing + # Assuming n = 1 input_config(0)=1 + + out[:self.n] = discrete_sim(self.param1, self.param2, self.param3, self.param4, + self.param5, self.param6, self.param7, self.param8, in0[:self.n].tolist()) # IMP: in0[:self.n].tolist() passes a python array, without which window cannot be raised above certain value | numpy.array bug + + print out[:self.n], in0[:self.n] + + self.consume(0,self.n) # Consume from port 0 input_items + self.produce(0,self.n) # Produce from port 0 output_items diff --git a/gr-controls/python/dsim_sci.py b/gr-controls/python/dsim_sci.py new file mode 100644 index 000000000..115c802c4 --- /dev/null +++ b/gr-controls/python/dsim_sci.py @@ -0,0 +1,36 @@ +#!/usr/bin/python + +import sciscipy + + +# u is a TUPLE vector of width w + +def discrete_sim(P,I,D,n0,n1,st,d0,d1,u): + code_string1 = "s=%s;" + code_string2 = "Gc=syslin("+str(st)+",("+str(P*I+D)+"*s)"+","+str(I)+"*s);" + code_string3 = "G=syslin(" + code_string4 = str(st)+","+str(n0)+"*s"+"+"+str(n1)+","+str(d0)+"*s"+"+"+str(d1)+");" + code_string5 = "r=tf2ss(G*Gc);" + code_string6 = "u="+str((u))+";" + code_string7 = "y=dsimul(r,u)" + code_string = code_string1+code_string2+code_string3+code_string4+code_string5+code_string6+code_string7 + + # Check complete_code_string + #print code_string + + import sciscipy + sciscipy.eval(code_string) + y = sciscipy.read("y") + return y + +#print discrete_sim(1,1,0.1,2,1,"u=zeros(1,50);u(10)=1") + +if __name__ == "__main__": + u = [0]*100 + u[50] = 1 + out = discrete_sim(2,0.5,0.6,1,1,0.1,2,1,u) + print out + + #import matplotlib.pyplot as plt + #plt.plot(out) + #plt.show() diff --git a/gr-controls/python/qa_dsim.py b/gr-controls/python/qa_dsim.py new file mode 100755 index 000000000..8c0a6be4e --- /dev/null +++ b/gr-controls/python/qa_dsim.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# +# Copyright 2013 <+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. +# + +from gnuradio import gr, gr_unittest +#import mymod_swig as mymod +from dsim import dsim + + +class qa_dsim (gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001_t (self): + + src_data = [0]*100 + src_data1 = [1]*1000 + src_data = tuple(src_data+src_data1) + + expected_result = (-2.0, 0.0, 5.0, 8.0, 9.0, 11.0, 14.0, 18.0) + + src0 = gr.vector_source_f(src_data) + sqr = dsim() + sqr.set_parameters(2,0.5,0.6,1,1, 0.1, 2, 1, 1100) + + #Preload + sqr.input_config(1).preload_items = 1 + dst = gr.vector_sink_f() + + self.tb.connect(src0, (sqr,0)) # src0(vector_source) -> sqr_input_0 + #self.tb.connect((sqr,0), (sqr,1)) # sqr_output_0 -> sqr_input_1 + self.tb.connect(sqr,dst) # sqr_output_0 -> dst (vector_source) + + self.tb.run() + + result_data = dst.data() + #print str(result_data), "Result data" + #print str(expected_result), "expected " + + + import matplotlib.pyplot as plt + plt.plot(result_data) + plt.show() + #self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6) + + +if __name__ == '__main__': + gr_unittest.main() + #gr_unittest.run(qa_dsim, "qa_dsim.xml") |