#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright 2018 <+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 class vave(gr.decim_block): """ docstring for block vave """ def __init__(self, vsize, vdecimate): gr.decim_block.__init__(self, name="vave", in_sig=[(numpy.float32, int(vsize))], out_sig=[(numpy.float32, int(vsize))], decim=int(vdecimate)) self.vsize = int(vsize) self.vdecimate = int(vdecimate) self.sum = numpy.zeros(self.vsize) self.count = 0 self.oneovern = 1./float(self.vdecimate) def forecast( self, noutput_items, ninput_items): return self.vdecimate def work(self, input_items, output_items): """ Work averages all input vectors and outputs one vector for all inputs """ out = output_items[0] # get the number of input vectors n = len( input_items) print 'Number of work input vectors: ',n for j in range(n): # get the lenght of one input in0 = input_items[j] print 'Lenght of input ', len(in0),' for vectors: ',j # indicate consumption of a vector from input self.consume(0,len(in0)) # now save this vector until all are received self.sum = self.sum + in0 self.count = self.count + 1 if self.count >= self.vdecimate: # normalize output average out[:] = self.oneovern * self.sum[:] # now reset the count and restart the sum self.count = 0 self.sum = numpy.zeros( self.vdecimate) return len(output_items[0]) # end for all input vectors # if here, then not enough vectors input to produce an output return 0 # end vave()