[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] OOT Module Not Working Properly

From: CEL
Subject: Re: [Discuss-gnuradio] OOT Module Not Working Properly
Date: Fri, 12 Jan 2018 12:19:04 +0000

Hi Tellrell,

>    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

what your forecast does: it tells the GNU Radio runtime that your block
behaves like a sync block. So, you should've probably saved yourself
the hassle of implementing a forecast – and that source of bugs – by
simply using a sync_block instead!

>    def general_work(self, input_items, output_items):
>        in0 = input_items[0]
>        self.seen+=in0.shape[0]

Your logic misses one interesting case:
So, let's say self.num_samples = 1024. Then, let your block have
consumed 1000 items in the last work(), so that now self.seen == 1000.

Now, you're greeted with 1000 new items, self.seen == 2000. However,
let the first threshold-exceeding item be the first one of these 1000
new items (or, the absolute 1001. item). So, that is not an item that
came after the 1024, but before. Still, it counts!

There's a high chance that already your first call gets for example
2048 items. So, your program logic breaks down instantly! Even if all
but the first sample of these 2048 are smaller than your threshold,
your block will trigger :(. 

So, what you want is some kind of very simple state machine:

Let your block have a self.status variable, which can hold different
values. Often, these values are just integers or so from a constants
table, but it could be strings, whatever is unique. What your work()
does depends on which state your block currently has:

Start your block in the STATUS_IDLE state; in that state, you use a
variable that counts the number of items already consumed in that state
(your self.seen).
After consuming **exactly** self.num_samples items (not the whole
noutput_items, just how much is need to make
self.seen==self.num_samples!!), you switch to the STATUS_ARMED state.
Now, you look for samples that exceed your threshold, consume all
samples up to (and including) that one, and then switch back to
STATUS_IDLE (don't forget to reset self.seen).

Best regards,

On Fri, 2018-01-12 at 02:47 -0500, Tellrell White wrote:
> Hello Guys
> I'm creating a customized block in the GNU Radio framework using python that 
> takes in a number of input items and once that number of input items 
> surpasses a certain number, 1024 of the input items are taken and stored into 
> an array, and then those items are converted to dB and lastly compared to a 
> threshold value, 5 in this case. If any of the values are greater than the 
> threshold value, a message is printed indicating a signal is present, and if 
> none of the values are greater than 5, this is indicated with a message 
> stating "No signal is present".
> In the flow graph attached, I'm using a cosine source and a gaussian noise 
> source to test my block in two different scenarios. 
> In scenario 1, I run the flow graph with both signal sources and I expect to 
> receive a message stating "A signal is present" because the power of the 
> signal will be greater than the threshold. 
> In scenario 2, the cosine source is disabled and only the noise source is 
> runing. In this scenario I expect to get a message indicating no signal is 
> present because the calculated power will be lower than the threshold.
> Scenario 1 works, however, scenario 2 doesn't work no matter how high I raise 
> the threshold value and, at this point, I'm not quite sure as to why. 
> Any help would be appreciated. Both the .py script for the oot block and the 
> .grc file are included.
> Tellrell 
> _______________________________________________
> Discuss-gnuradio mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Attachment: smime.p7s
Description: S/MIME cryptographic signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]