# Which type of block do I use here?

**URL:** <https://www.ruby-forum.com/t/which-type-of-block-do-i-use-here/242008>\
**Category:** GNU Radio\
**Created:** [May 20, 2015, 7:38am UTC](https://www.ruby-forum.com/t/which-type-of-block-do-i-use-here/242008 "2015-05-20T07:38:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [May 20, 2015, 7:38am UTC](https://www.ruby-forum.com/t/which-type-of-block-do-i-use-here/242008/1 "2015-05-20T07:38:16Z")

</div>

Hi

Say I want to create an energy detect block that takes a certain number  
of input samples, measures the (signal) power and compares it against a  
threshold. Only if the power exceeds the threshold, the block has to  
make the decision that some genuine signal is being received and then  
move only those samples to the next block for further processing.

So if power \> threshold, send all the samples as is to the next block.  
In this case the block behaves as a sync block.

But if power \< threshold, the block has to flush the data and wait for  
the next set of samples. (I’m not sure what type of block fits the bill  
here)

Either way, i wanted to know how to get the same block to behave in two  
different ways in terms of the number of items that it outputs.

Thanks for your help  
Anil

---

<div class="post-metadata">

**Author:** ![anil\_y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anil\_y](https://www.ruby-forum.com/u/anil_y)\
**Post date:** [May 20, 2015, 10:04am UTC](https://www.ruby-forum.com/t/which-type-of-block-do-i-use-here/242008/2 "2015-05-20T10:04:19Z")

</div>

Hi,

It seems that you may need a Power Squelch filter, which can be found in  
Level Controllers category in GNR Radio Companion.

Best,

Su Li

2015-05-20 7:37 GMT+02:00 Anil K. Yerrapragada  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
:

---

<div class="post-metadata">

**Author:** ![anil\_y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anil\_y](https://www.ruby-forum.com/u/anil_y)\
**Post date:** [May 20, 2015, 6:07pm UTC](https://www.ruby-forum.com/t/which-type-of-block-do-i-use-here/242008/3 "2015-05-20T18:07:26Z")

</div>

If our squelch blocks don’t suffice, and you _do_ need to implement your  
own, you’d use a general gr::block.

M

---

<div class="post-metadata">

**Author:** ![anil\_y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anil\_y](https://www.ruby-forum.com/u/anil_y)\
**Post date:** [May 21, 2015, 4:01am UTC](https://www.ruby-forum.com/t/which-type-of-block-do-i-use-here/242008/4 "2015-05-21T04:01:30Z")

</div>

Hi

Thanks Su Li and Martin B..

Martin B. wrote in post #1173825:

> If our squelch blocks don’t suffice, and you _do_ need to implement your  
> own, you’d use a general gr::block.
> 
> M

I looked at the squelch block and source code. I probably need to make  
my own block because my algorithm is slightly different. I am buffering  
up data coming in through a USRP and sliding a window over it to  
calculate power in each window.

And I did get as far as deciding that the gr::block is the one to use.  
I’m coding in python by the way, using gr\_modtool, so the equivalent  
would be gr.basic block if I’m not mistaken.

My question is this and I find that this often throws me off:

Do I need to completely leave out the forecast and consume functions  
here because the number of output items is not really related to the  
number of input items?

Will something like this in the work function work do you think? (Not in  
any specific programming language):

while input\_items:  
buffer = in[0][buffer length] #this buffer is just an empty array i  
create.

slide window, do whatever i need to do

if power \< threshold:  
do nothing (how do i implement this sort of thing? Will a simple  
break statement work?)  
else:  
identify the number of windows that gave power \> threshold and  
return that many windows worth of items

update buffer

Thanks for your help  
Anil
