14 changed files with 3 additions and 674 deletions
@ -1,60 +0,0 @@
|
||||
<?xml version="1.0"?> |
||||
<block> |
||||
<name>diff_add_sync_decim</name> |
||||
<key>multirds_diff_add_sync_decim</key> |
||||
<category>[multirds]</category> |
||||
<import>import multirds</import> |
||||
<make>multirds.diff_add_sync_decim($threshold,$max_ratio_below_threshold, $log)</make> |
||||
<!-- Make one 'param' node for every Parameter you want settable from the GUI. |
||||
Sub-nodes: |
||||
* name |
||||
* key (makes the value accessible as $keyname, e.g. in the make node) |
||||
* type --> |
||||
<param> |
||||
<name>Log</name> |
||||
<key>log</key> |
||||
<value>False</value> |
||||
<type>bool</type> |
||||
<option> |
||||
<name>Enable</name> |
||||
<key>True</key> |
||||
</option> |
||||
<option> |
||||
<name>Disable</name> |
||||
<key>False</key> |
||||
</option> |
||||
</param> |
||||
<param> |
||||
<name>Threshold</name> |
||||
<key>threshold</key> |
||||
<value>0.5</value> |
||||
<type>float</type> |
||||
</param> |
||||
<param> |
||||
<name>max_ratio_below_threshold</name> |
||||
<key>max_ratio_below_threshold</key> |
||||
<value>0.8</value> |
||||
<type>float</type> |
||||
</param> |
||||
<check>0 < $max_ratio_below_threshold < 1</check> |
||||
|
||||
<!-- Make one 'sink' node per input. Sub-nodes: |
||||
* name (an identifier for the GUI) |
||||
* type |
||||
* vlen |
||||
* optional (set to 1 for optional inputs) --> |
||||
<sink> |
||||
<name>in</name> |
||||
<type>float</type> |
||||
</sink> |
||||
|
||||
<!-- Make one 'source' node per output. Sub-nodes: |
||||
* name (an identifier for the GUI) |
||||
* type |
||||
* vlen |
||||
* optional (set to 1 for optional inputs) --> |
||||
<source> |
||||
<name>out</name> |
||||
<type>float</type> |
||||
</source> |
||||
</block> |
||||
@ -1,55 +0,0 @@
|
||||
<?xml version="1.0"?> |
||||
<block> |
||||
<name>qtguitest</name> |
||||
<key>multirds_qtguitest</key> |
||||
<category>[multirds]</category> |
||||
<import>import multirds</import> |
||||
<import>from multirds.qtguitest import qtguitest, CRWidget,Signals</import> |
||||
<var_make>self.$(id) = $(id) = $value</var_make> |
||||
<make>#set $win = 'self._%s_win'%$id |
||||
#set $signals = 'self._%s_signals'%$id |
||||
#if not $label() |
||||
#set $label = '"%s"'%$id |
||||
#end if |
||||
$(signals) = Signals() |
||||
self.$(id) = multirds.qtguitest($(signals),$nPorts) |
||||
$(win) = CRWidget($signals, $label) |
||||
$(gui_hint()($win))</make> |
||||
|
||||
|
||||
<param> |
||||
<name>Label</name> |
||||
<key>label</key> |
||||
<value></value> |
||||
<type>string</type> |
||||
<hide>#if $label() then 'none' else 'part'#</hide> |
||||
</param> |
||||
<param> |
||||
<name>GUI Hint</name> |
||||
<key>gui_hint</key> |
||||
<value></value> |
||||
<type>gui_hint</type> |
||||
<hide>part</hide> |
||||
</param> |
||||
|
||||
<param> |
||||
<name>Number of Ports</name> |
||||
<key>nPorts</key> |
||||
<value>1</value> |
||||
<type>int</type> |
||||
<hide>part</hide> |
||||
</param> |
||||
<sink> |
||||
<name>in</name> |
||||
<type>message</type> |
||||
<nports>$nPorts</nports> |
||||
<optional>1</optional> |
||||
</sink> |
||||
<!-- |
||||
<sink> |
||||
<name>in1</name> |
||||
<type>message</type> |
||||
</sink> |
||||
--> |
||||
|
||||
</block> |
||||
@ -1,52 +0,0 @@
|
||||
<?xml version="1.0"?> |
||||
<block> |
||||
<name>smooth_vectors</name> |
||||
<key>multirds_smooth_vectors</key> |
||||
<category>[multirds]</category> |
||||
<import>import multirds</import> |
||||
<make>multirds.smooth_vectors($vec_len, $decim, $moving_avg_len)</make> |
||||
<!-- Make one 'param' node for every Parameter you want settable from the GUI. |
||||
Sub-nodes: |
||||
* name |
||||
* key (makes the value accessible as $keyname, e.g. in the make node) |
||||
* type --> |
||||
<param> |
||||
<name>vec_len</name> |
||||
<key>vec_len</key> |
||||
<value>1024</value> |
||||
<type>int</type> |
||||
</param> |
||||
<param> |
||||
<name>decim</name> |
||||
<key>decim</key> |
||||
<value>1</value> |
||||
<type>int</type> |
||||
</param> |
||||
<param> |
||||
<name>moving_avg_len</name> |
||||
<key>moving_avg_len</key> |
||||
<value>2</value> |
||||
<type>int</type> |
||||
</param> |
||||
|
||||
<!-- Make one 'sink' node per input. Sub-nodes: |
||||
* name (an identifier for the GUI) |
||||
* type |
||||
* vlen |
||||
* optional (set to 1 for optional inputs) --> |
||||
<sink> |
||||
<name>in</name> |
||||
<type>float</type> |
||||
<vlen>$vec_len</vlen> |
||||
</sink> |
||||
<!-- Make one 'source' node per output. Sub-nodes: |
||||
* name (an identifier for the GUI) |
||||
* type |
||||
* vlen |
||||
* optional (set to 1 for optional inputs) --> |
||||
<source> |
||||
<name>out</name> |
||||
<type>float</type> |
||||
<vlen>$vec_len</vlen> |
||||
</source> |
||||
</block> |
||||
@ -1,56 +0,0 @@
|
||||
/* -*- c++ -*- */ |
||||
/*
|
||||
* Copyright 2017 <+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. |
||||
*/ |
||||
|
||||
|
||||
#ifndef INCLUDED_CRFA_DIFF_ADD_SYNC_DECIM_H |
||||
#define INCLUDED_CRFA_DIFF_ADD_SYNC_DECIM_H |
||||
|
||||
#include <multirds/api.h> |
||||
#include <gnuradio/sync_decimator.h> |
||||
|
||||
namespace gr { |
||||
namespace multirds { |
||||
|
||||
/*!
|
||||
* \brief <+description of block+> |
||||
* \ingroup multirds |
||||
* |
||||
*/ |
||||
class CRFA_API diff_add_sync_decim : virtual public gr::sync_decimator |
||||
{ |
||||
public: |
||||
typedef boost::shared_ptr<diff_add_sync_decim> sptr; |
||||
|
||||
/*!
|
||||
* \brief Return a shared_ptr to a new instance of multirds::diff_add_sync_decim. |
||||
* |
||||
* To avoid accidental use of raw pointers, multirds::diff_add_sync_decim's |
||||
* constructor is in a private implementation |
||||
* class. multirds::diff_add_sync_decim::make is the public interface for |
||||
* creating new instances. |
||||
*/ |
||||
static sptr make(float threshold,float max_ratio_below_threshold,bool log); |
||||
}; |
||||
|
||||
} // namespace multirds
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_CRFA_DIFF_ADD_SYNC_DECIM_H */ |
||||
|
||||
@ -1,142 +0,0 @@
|
||||
/* -*- c++ -*- */ |
||||
/*
|
||||
* Copyright 2017 <+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. |
||||
*/ |
||||
|
||||
#ifdef HAVE_CONFIG_H |
||||
#include "config.h" |
||||
#endif |
||||
|
||||
#include <gnuradio/io_signature.h> |
||||
#include "diff_add_sync_decim_impl.h" |
||||
#define DECIM 2 |
||||
#define lout log && std::cout |
||||
|
||||
namespace gr { |
||||
namespace multirds { |
||||
|
||||
diff_add_sync_decim::sptr |
||||
diff_add_sync_decim::make(float threshold,float max_ratio_below_threshold,bool log) |
||||
{ |
||||
return gnuradio::get_initial_sptr |
||||
(new diff_add_sync_decim_impl(threshold,max_ratio_below_threshold,log)); |
||||
} |
||||
|
||||
/*
|
||||
* The private constructor |
||||
*/ |
||||
diff_add_sync_decim_impl::diff_add_sync_decim_impl(float threshold,float max_ratio_below_threshold,bool log) |
||||
: gr::sync_decimator("diff_add_sync_decim", |
||||
gr::io_signature::make(1, 1, sizeof(float)), |
||||
gr::io_signature::make(1, 1, sizeof(float)), DECIM), |
||||
threshold(threshold), |
||||
max_ratio_below_threshold(max_ratio_below_threshold), |
||||
log(log) |
||||
|
||||
{ |
||||
//nothing to do?
|
||||
|
||||
//init persistant vars
|
||||
last_input=0; |
||||
skip=0; |
||||
} |
||||
|
||||
/*
|
||||
* Our virtual destructor. |
||||
*/ |
||||
diff_add_sync_decim_impl::~diff_add_sync_decim_impl() |
||||
{ |
||||
} |
||||
|
||||
int |
||||
diff_add_sync_decim_impl::work(int noutput_items, |
||||
gr_vector_const_void_star &input_items, |
||||
gr_vector_void_star &output_items) |
||||
{ |
||||
|
||||
const float *in = (const float *) input_items[0]; |
||||
float *out = (float *) output_items[0]; |
||||
int values_below_threshold=0; |
||||
int values_below_threshold_skip=0; |
||||
int values_below_threshold_noskip=0; |
||||
float out_noskip; |
||||
float out_skip; |
||||
for (int i = 0; i < noutput_items; i++) { |
||||
//out[i]=in[DECIM*i];// keep 1 in DECIM
|
||||
if(i==0){ |
||||
out_skip=last_input-in[DECIM*i];} |
||||
else{ |
||||
out_skip=in[DECIM*i-1]-in[DECIM*i];} |
||||
|
||||
out_noskip=in[DECIM*i]-in[DECIM*i+1]; |
||||
|
||||
switch(skip){ |
||||
case 0: |
||||
out[i]=out_noskip; |
||||
break; |
||||
case 1: |
||||
out[i]=out_skip; |
||||
break; |
||||
default: |
||||
out[i]=out_noskip; |
||||
break; |
||||
} |
||||
|
||||
if(abs(out[i])<threshold){ |
||||
values_below_threshold++; |
||||
} |
||||
|
||||
if(abs(out_noskip)<threshold){ |
||||
values_below_threshold_noskip++; |
||||
}
|
||||
|
||||
if(abs(out_skip)<threshold){ |
||||
values_below_threshold_skip++; |
||||
} |
||||
} |
||||
last_input=in[(noutput_items-1)*DECIM+1];//to use for next iteration of work
|
||||
//if ((float)values_below_threshold / (float)noutput_items >0.5)
|
||||
if ((float)values_below_threshold / (float)noutput_items >max_ratio_below_threshold && values_below_threshold>8)//2/2(=100%) below threshold is not significant
|
||||
{ |
||||
//lout<<"resync:"<<values_below_threshold<<"/"<<noutput_items<<", skip:"<<skip<<", last_input:"<<last_input<<std::endl;
|
||||
lout<<"out_skip:"<<values_below_threshold_skip<<"/"<<noutput_items; |
||||
lout<<", out_noskip:"<<values_below_threshold_noskip<<"/"<<noutput_items; |
||||
lout<<", skip:"<<skip <<std::endl; |
||||
switch(skip){ |
||||
case 0:skip=1;break; |
||||
case 1:skip=0;break; |
||||
default:skip=0;break; |
||||
} |
||||
} |
||||
// if(noutput_items>9){
|
||||
// if(values_below_threshold_noskip>values_below_threshold_skip){
|
||||
// skip=1;
|
||||
// }
|
||||
// else{
|
||||
// skip=0;
|
||||
// }
|
||||
// }
|
||||
//lout << "noutput_items:"<< noutput_items <<", threshold:"<<threshold << std::endl;
|
||||
//lout << "out[0]:"<< out[0] <<", threshold:"<<threshold << std::endl;
|
||||
// Tell runtime system how many output items we produced.
|
||||
return noutput_items; |
||||
} |
||||
|
||||
} /* namespace multirds */ |
||||
} /* namespace gr */ |
||||
|
||||
@ -1,54 +0,0 @@
|
||||
/* -*- c++ -*- */ |
||||
/*
|
||||
* Copyright 2017 <+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. |
||||
*/ |
||||
|
||||
#ifndef INCLUDED_CRFA_DIFF_ADD_SYNC_DECIM_IMPL_H |
||||
#define INCLUDED_CRFA_DIFF_ADD_SYNC_DECIM_IMPL_H |
||||
|
||||
#include <multirds/diff_add_sync_decim.h> |
||||
|
||||
namespace gr { |
||||
namespace multirds { |
||||
|
||||
class diff_add_sync_decim_impl : public diff_add_sync_decim |
||||
{ |
||||
private: |
||||
// Nothing to declare in this block.
|
||||
|
||||
public: |
||||
diff_add_sync_decim_impl(float threshold,float max_ratio_below_threshold,bool log); |
||||
~diff_add_sync_decim_impl(); |
||||
|
||||
// Where all the action really happens
|
||||
int work(int noutput_items, |
||||
gr_vector_const_void_star &input_items, |
||||
gr_vector_void_star &output_items); |
||||
bool log; |
||||
float threshold; |
||||
float max_ratio_below_threshold; |
||||
float last_input; |
||||
//enum { SKIP, NOSKIP } d_state;
|
||||
unsigned int skip; |
||||
}; |
||||
|
||||
} // namespace multirds
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_CRFA_DIFF_ADD_SYNC_DECIM_IMPL_H */ |
||||
|
||||
@ -1,183 +0,0 @@
|
||||
#!/usr/bin/env python |
||||
# -*- coding: utf-8 -*- |
||||
# |
||||
# Copyright 2016 <+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 gnuradio import gr |
||||
import code,pmt |
||||
from PyQt4 import Qt, QtCore, QtGui |
||||
import pprint |
||||
pp = pprint.PrettyPrinter() |
||||
|
||||
from PyQt4.QtCore import QObject, pyqtSignal |
||||
|
||||
class Signals(QObject): |
||||
DataUpdateEvent = QtCore.pyqtSignal(dict) |
||||
def __init__(self, parent=None): |
||||
super(QtCore.QObject, self).__init__() |
||||
|
||||
class qtguitest(gr.sync_block): |
||||
""" |
||||
docstring for block qtguitest |
||||
""" |
||||
def __init__(self,signals,nPorts): |
||||
#QObject.__init__() |
||||
gr.sync_block.__init__(self, |
||||
name="qtguitest", |
||||
in_sig=None, |
||||
out_sig=None) |
||||
for i in range(0,nPorts): |
||||
self.message_port_register_in(pmt.intern('in%d'%i)) |
||||
self.set_msg_handler(pmt.intern('in%d'%i), self.handle_msg) |
||||
#self.message_port_register_in(pmt.intern('in1')) |
||||
#self.set_msg_handler(pmt.intern('in1'), self.handle_msg) |
||||
#code.interact(local=locals()) |
||||
self.signals=signals |
||||
def handle_msg(self, msg): |
||||
self.signals.DataUpdateEvent.emit({'string':pmt.to_python(msg)}) |
||||
print(msg) |
||||
class CRWidget(QtGui.QWidget): |
||||
def __init__(self, signals,label): |
||||
print("gui initializing") |
||||
self.signals = signals |
||||
self.signals.DataUpdateEvent.connect(self.display_data) |
||||
""" Creates the QT Range widget """ |
||||
QtGui.QWidget.__init__(self) |
||||
layout = Qt.QVBoxLayout() |
||||
self.label = Qt.QLabel(label) |
||||
layout.addWidget(self.label) |
||||
|
||||
self.setLayout(layout) |
||||
self.table=QtGui.QTableWidget(self) |
||||
self.table.setRowCount(5) |
||||
self.table.setColumnCount(6) |
||||
self.table.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) #disallow editing |
||||
#Data |
||||
|
||||
data = {'ID':range(1,6), |
||||
'freq':['97.0','101.3','104.6','107.7'], |
||||
'name':['foo','antenne1','bar','DieNeue'], |
||||
'AF':['7','8','9','5'], |
||||
'text':['bla','bli','blu',u'blä'], |
||||
'buttons':[]} |
||||
#Enter data onto Table |
||||
horHeaders = [] |
||||
for n, key in enumerate(['ID','freq','name','AF','text','buttons']): |
||||
#for n, key in enumerate(sorted(data.keys())): |
||||
horHeaders.append(key) |
||||
for m, item in enumerate(data[key]): |
||||
if type(item)==int:#convert ints to strings |
||||
newitem = QtGui.QTableWidgetItem(str(item)) |
||||
else: |
||||
newitem = QtGui.QTableWidgetItem(item) |
||||
self.table.setItem(m, n, newitem) |
||||
for i in range(0,4): |
||||
button=QtGui.QPushButton("play") |
||||
self.table.setCellWidget(i,5,button) |
||||
button.clicked.connect(self.onCLick) |
||||
|
||||
#Add Header |
||||
self.table.setHorizontalHeaderLabels(horHeaders) |
||||
layout.addWidget(self.label) |
||||
layout.addWidget(self.table) |
||||
|
||||
self.table.setHorizontalHeaderLabels(horHeaders) |
||||
self.table.setMaximumHeight(250)#TODO use dynamic value |
||||
test=""" |
||||
adkasldjkasd |
||||
#ad |
||||
asd |
||||
as |
||||
d |
||||
asd |
||||
asdas |
||||
d |
||||
as |
||||
f |
||||
as |
||||
fa |
||||
|
||||
sfasfasfasfasofsa |
||||
afasfasf |
||||
""" |
||||
self.tmc_message_label=QtGui.QLabel("TMC messages:") |
||||
#self.tmc_message_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByKeyboard|QtCore.Qt.TextSelectableByMouse) |
||||
#self.tmc_message_label.setMaximumHeight(100) |
||||
|
||||
self.event_filter=QtGui.QLineEdit()#QPlainTextEdit ? |
||||
self.location_filter=QtGui.QLineEdit() |
||||
|
||||
self.button = QtGui.QPushButton("i am a button") |
||||
self.button.clicked.connect(self.onCLick) |
||||
layout.addWidget(self.button) |
||||
|
||||
#self.filter_label=QtGui.QLabel() |
||||
filter_layout = Qt.QHBoxLayout() |
||||
filter_layout.addWidget(QtGui.QLabel("event filter:")) |
||||
filter_layout.addWidget(self.event_filter) |
||||
filter_layout.addWidget(QtGui.QLabel("location filter:")) |
||||
filter_layout.addWidget(self.location_filter) |
||||
#self.filter_label.setLayout(filter_layout) |
||||
self.tmc_message_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) |
||||
#self.tmc_message_label.setTextInteractionFlags(QtCore.Qt.NoTextInteraction) |
||||
layout.addLayout(filter_layout) |
||||
layout.addWidget(self.tmc_message_label) |
||||
|
||||
self.logOutput = Qt.QTextEdit(test) |
||||
self.logOutput.setReadOnly(True) |
||||
self.logOutput.setLineWrapMode(Qt.QTextEdit.NoWrap) |
||||
self.logOutput.setMaximumHeight(100) |
||||
font = self.logOutput.font() |
||||
font.setFamily("Courier") |
||||
font.setPointSize(10) |
||||
layout.addWidget(self.logOutput) |
||||
|
||||
|
||||
|
||||
def display_data(self, event): |
||||
#msg_type = event.data[0] |
||||
#msg = unicode(event.data[1], errors='replace') |
||||
#if (msg_type==0): #program information |
||||
# self.label.setText(msg) |
||||
#self.layout() |
||||
pp.pprint(event) |
||||
self.table.currentItem().setText(event['string']) |
||||
def onCLick(self): |
||||
print("button clicked") |
||||
#pp.pprint(event) |
||||
if __name__ == "__main__": |
||||
from PyQt4 import Qt |
||||
import sys |
||||
|
||||
# def valueChanged(frequency): |
||||
# print("Value updated - " + str(frequency)) |
||||
|
||||
app = Qt.QApplication(sys.argv) |
||||
# widget = RangeWidget(Range(0, 100, 10, 1, 100), valueChanged, "Test", "counter_slider", int) |
||||
mainobj= Signals() |
||||
#mainobj=None |
||||
widget = CRWidget(mainobj,"TestLabel") |
||||
widget.show() |
||||
widget.setWindowTitle("Test Qt gui") |
||||
widget.setGeometry(200,200,600,300) |
||||
#code.interact(local=locals()) |
||||
#sys.exit(app.exec_()) |
||||
app.exec_(code.interact(local=locals())) |
||||
widget = None |
||||
@ -1,60 +0,0 @@
|
||||
#!/usr/bin/env python |
||||
# -*- coding: utf-8 -*- |
||||
# |
||||
# Copyright 2016 <+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 as np |
||||
from gnuradio import gr |
||||
import code |
||||
|
||||
class smooth_vectors(gr.decim_block): |
||||
""" |
||||
docstring for block smooth_vectors |
||||
""" |
||||
def __init__(self, vec_len,decim,moving_avg_len): |
||||
gr.decim_block.__init__(self, |
||||
name="smooth_vectors", |
||||
in_sig=[(np.float32,vec_len)], |
||||
out_sig=[(np.float32,vec_len)], |
||||
decim=decim) |
||||
self.vec_len=vec_len |
||||
self.decim=decim |
||||
self.moving_avg_len=moving_avg_len |
||||
self.last_inputs=[] |
||||
#self.count=1 |
||||
|
||||
|
||||
def work(self, input_items, output_items): |
||||
in0 = input_items[0]#0th input port? |
||||
out = output_items[0] |
||||
#self.last_inputs.insert(0,in0) |
||||
#code.interact(local=locals()) |
||||
for i in range(0,self.decim): |
||||
self.last_inputs.insert(0,in0[i]) |
||||
|
||||
|
||||
out[:] =np.mean( np.array(self.last_inputs), axis=0 ) |
||||
# <+signal processing here+> |
||||
|
||||
if len(self.last_inputs)>self.moving_avg_len: |
||||
self.last_inputs.pop(len(self.last_inputs)-1)#remove last |
||||
#out[:] = in0 |
||||
#self.count += 1 |
||||
return len(output_items[0]) |
||||
|
||||
Loading…
Reference in new issue