[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Discuss-gnuradio] How to predict output buffer size
From: |
Igor Volodin |
Subject: |
[Discuss-gnuradio] How to predict output buffer size |
Date: |
Sat, 28 Jan 2017 21:03:58 +0300 |
User-agent: |
Roundcube Webmail/1.1.2 |
Hi all,
I am creating a block which will count number of "1" values in a
sequence, and output it number (I am trying to convert PWM encoded
bits).
Block has 1 input (numpy.int32) and 1 output (it's also has numpy.int32
type)
So, it should work following way:
[1,1,1,0,0,1,0,0,0,1,1,1,1,1] -> [MyBlock] -> [3,1,5]
Documentation says that i should predict number of output items in a
forecast() method. But i can't predict how many sequences will be in
the input items.
Could anybody suggest a solution for this case?
Here is my Python code:
import numpy
from gnuradio import gr
class hold_and_sum(gr.basic_block):
"""
docstring for block hold_and_sum
"""
def __init__(self):
gr.basic_block.__init__(self, name="hold_and_sum",
in_sig=[numpy.int32], out_sig=[numpy.int32])
self.summary = numpy.int32(0)
self.in_accumulation = 0
self.out_bytes = [numpy.int32]
def forecast(self, noutput_items, ninput_items_required):
#setup size of input_items[i] for work call
for i in range(len(ninput_items_required)):
ninput_items_required[i] = noutput_items
def general_work(self, input_items, output_items):
in0 = input_items[0]
out = output_items[0]
for smpl in in0:
if smpl == 1:
self.in_accumulation = 1
self.summary = numpy.sum([self.summary, smpl],
dtype=numpy.int32)
else:
if (self.in_accumulation == 1): #previous sample was
1, and now we have 0, it's end of a pulse
print self.summary # print pulse length
self.out_bytes.append(self.summary)
self.summary = 0 #empty counter
self.in_accumulation = 0 #Reset flag
print self.out_bytes
if len(self.out_bytes) == 0:
self.out_bytes.append(0)
#out[:] = numpy.array(self.out_bytes) ???
del self.out_bytes[:]
#self.consume(0, len(input_items[0]))
self.consume_each(len(input_items[0]))
return (len(out))
Best regards,
Igor
- [Discuss-gnuradio] How to predict output buffer size,
Igor Volodin <=