# Comparator block?

**URL:** <https://www.ruby-forum.com/t/comparator-block/232728>\
**Category:** GNU Radio\
**Created:** [October 24, 2014, 10:16am UTC](https://www.ruby-forum.com/t/comparator-block/232728 "2014-10-24T10:16:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [October 24, 2014, 10:16am UTC](https://www.ruby-forum.com/t/comparator-block/232728/1 "2014-10-24T10:16:28Z")

</div>

Hi,

I would like to have a comparator in my GRC block design to compair  
something like SNR or RMS or both on RX channels in my design.

Logic would be something like…

if channel A\>B then switch to channel B else use channel A.

I have found the ‘slector’ block which looks useful in switching the  
channel sources based on routing value…

I found threshold block which includes a comparator? but no comparator  
block.

Is there a reason there is no comparator block? I read the IF statement  
should be avoided in FPGA design although a comparator is quite standard  
in electronic design ?

Maybe there is a better way to achieve deversity and i’m missing  
something obvious? I want to have diversity switching in each differnt  
channel frequency / bandwidth and not just at the IQ source…

any ideas much welcome… or even a pointer to a comparator block !

I’m new at GNUradio and have’nt made a custom block yet… but maybe its  
time to try !!! ??

---

<div class="post-metadata">

**Author:** ![brblakley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f14d63/32.png) [@brblakley](https://www.ruby-forum.com/u/brblakley)\
**Post date:** [October 26, 2014, 6:25am UTC](https://www.ruby-forum.com/t/comparator-block/232728/2 "2014-10-26T06:25:31Z")

</div>

Looking into this more it seams I will just have to add ‘IF else  
statement’ to generated python code.. It would be nice if GNUradio had  
this built in so I could experiment without hacking code!!

Ah well, anyone know any reason why a comparator or an IF block was  
never included?

Ben B. wrote in post #1160904:

> Hi,
> 
> I would like to have a comparator in my GRC block design to compair  
> something like SNR or RMS or both on RX channels in my design.
> 
> Logic would be something like..
> 
> if channel A\>B then switch to channel B else use channel A.
> 
> I have found the ‘slector’ block which looks useful in switching the  
> channel sources based on routing value..
> 
> I found threshold block which includes a comparator? but no comparator  
> block.
> 
> Is there a reason there is no comparator block? I read the IF statement  
> should be avoided in FPGA design although a comparator is quite standard  
> in electronic design ?
> 
> Maybe there is a better way to achieve deversity and i’m missing  
> something obvious? I want to have diversity switching in each differnt  
> channel frequency / bandwidth and not just at the IQ source..
> 
> any ideas much welcome.. or even a pointer to a comparator block !
> 
> I’m new at GNUradio and have’nt made a custom block yet.. but maybe its  
> time to try !!! ??

---

<div class="post-metadata">

**Author:** ![brblakley](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f14d63/32.png) [@brblakley](https://www.ruby-forum.com/u/brblakley)\
**Post date:** [October 28, 2014, 5:56pm UTC](https://www.ruby-forum.com/t/comparator-block/232728/3 "2014-10-28T17:56:26Z")

</div>

Just in case anyone is interested !

I managed to get diversity switching between 2 channels with 2 RMS  
blocks with Probe of ‘VALUE’ in the RMS blocks. then used 2 Threshold  
blocks. Threshold block 1 with RMS\_Value2\>RMS\_Value1 as the the low and  
high threshold value. this passes a 0 or 1 to a variable that is used in  
the SELECTOR block to route the 2 SOURCE SINC BLOCKS on to demod etc…

Anyway, Its a very long way around just using a comparator ( if  
RMS1\>RMS2 router= XXX !!! )

well, maybe that will make sense to somebody one day !

So far I have’nt managed to add the line directly into .PY code to make  
this work. I’ll post it here if I get it to work in a more graceful way.  
Or if I eventually get around to making a comparator block.

Sidenote: the strem switches but theres an audiable crunch on the  
channel change after a few ms delay… tried switching audio and  
complex source ( same crunch noise ! ) Maybe I need a fast auto - pan on  
the audio channels to make a smoother switch!!

Tried same SDR source block as input in case they were running out of  
phase / sync… same crunch noise… Perhaps the selector block is a bit  
clunky ! ??

will look into other ways of dynamic stream routing… perhaps I can  
code this in python in the stream routing section.

will update here if I get anywhere with that
