#!/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 vdecimate(gr.decim_block): """ Vector decimate any size of input docstring for block vdecimate """ def __init__(self, vectorsize=1024, nave=4): gr.decim_block.__init__(self, "vdecimate", [(numpy.float32, vectorsize)], [(numpy.float32, vectorsize)], nave) self.vectorsize = int(vectorsize) self.sum = numpy.zeros(self.vectorsize) self.count = 0 self.nave = 0 def work(self, input_items, output_items): in0 = input_items[0] nin = len(in0) # if change in the vector size, must restart sum if (nin != self.vectorsize) or (self.count == 0): self.vectorsize = nin self.sum = numpy.zeros(nin) # initialize sum and count self.sum = in0 self.count = 1 else: self.sum = self.sum + in0 self.count = self.count + 1 #if time to output vector if self.count >= self.nave: out = output_items[0] out[:] = self.sum/float(self.count) self.count = 0 return len(out[:]) else: return 0