Friday, March 30, 2018

Re: [Discuss-gnuradio] Avoiding divide by zero in case of input being zero.

t: 1 In (0,0) Current: (0,0)
t: 1 Correlation: nan Avg: 0
t: 2 In (0,0) Current: (0,0)
t: 2 Correlation: nan Avg: nan
t: 3 In (0,0) Current: (0,0)
t: 3 Correlation: nan Avg: nan
t: 4 In (0,0) Current: (0,0)
t: 4 Correlation: nan Avg: nan
t: 5 In (0,0) Current: (0,0)
t: 5 Correlation: nan Avg: nan
t: 6 In (0,0) Current: (0,0)
t: 6 Correlation: nan Avg: nan
t: 7 In (0,0) Current: (0,0)
t: 7 Correlation: nan Avg: nan
t: 8 In (0,0) Current: (0,0)
t: 8 Correlation: nan Avg: nan
t: 9 In (0,0) Current: (0,0)
t: 9 Correlation: nan Avg: nan
t: 10 In (0,0) Current: (0,0)
t: 10 Correlation: nan Avg: nan
t: 11 In (0,0) Current: (0,0)
t: 11 Correlation: nan Avg: nan
t: 12 In (0,0) Current: (0,0)
t: 12 Correlation: nan Avg: nan
t: 13 In (0,0) Current: (0,0)
t: 13 Correlation: nan Avg: nan
t: 14 In (0,0) Current: (0,0)
t: 14 Correlation: nan Avg: nan
t: 15 In (0,0) Current: (0,0)
t: 15 Correlation: nan Avg: nan
t: 16 In (0,0) Current: (0,0)
t: 16 Correlation: nan Avg: nan
t: 17 In (0,0) Current: (0,0)
t: 17 Correlation: nan Avg: nan
t: 18 In (0,0) Current: (0,0)
t: 18 Correlation: nan Avg: nan
t: 19 In (0,0) Current: (0,0)
t: 19 Correlation: nan Avg: nan
t: 20 In (0,0) Current: (0,0)
t: 20 Correlation: nan Avg: nan
t: 21 In (0,0) Current: (0,0)
t: 21 Correlation: nan Avg: nan
t: 22 In (0,0) Current: (0,0)
t: 22 Correlation: nan Avg: nan
t: 23 In (0,0) Current: (0,0)
t: 23 Correlation: nan Avg: nan
t: 24 In (0,0) Current: (0,0)
t: 24 Correlation: nan Avg: nan
t: 25 In (0,0) Current: (0,0)
t: 25 Correlation: nan Avg: nan
t: 26 In (0,0) Current: (0,0)
t: 26 Correlation: nan Avg: nan
t: 27 In (0,0) Current: (0,0)
t: 27 Correlation: nan Avg: nan
t: 28 In (0,0) Current: (0,0)
t: 28 Correlation: nan Avg: nan
t: 29 In (0,0) Current: (0,0)
t: 29 Correlation: nan Avg: nan
t: 30 In (0,0) Current: (0,0)
t: 30 Correlation: nan Avg: nan
t: 31 In (0,0) Current: (0,0)
t: 31 Correlation: nan Avg: nan
t: 32 In (0,0) Current: (0,0)
t: 32 Correlation: nan Avg: nan
t: 33 In (0,0) Current: (0,0)
t: 33 Correlation: nan Avg: nan
t: 34 In (0,0) Current: (0,0)
t: 34 Correlation: nan Avg: nan
t: 35 In (0,0) Current: (0,0)
t: 35 Correlation: nan Avg: nan
t: 36 In (0,0) Current: (0,0)
t: 36 Correlation: nan Avg: nan
t: 37 In (0,0) Current: (0,0)
t: 37 Correlation: nan Avg: nan
t: 38 In (0,0) Current: (0,0)
t: 38 Correlation: nan Avg: nan
t: 39 In (0,0) Current: (0,0)
t: 39 Correlation: nan Avg: nan
t: 40 In (0,0) Current: (0,0)
t: 40 Correlation: nan Avg: nan
t: 41 In (0,0) Current: (0,0)
t: 41 Correlation: nan Avg: nan
t: 42 In (0,0) Current: (0,0)
t: 42 Correlation: nan Avg: nan
t: 43 In (0,0) Current: (0,0)
t: 43 Correlation: nan Avg: nan
t: 44 In (0,0) Current: (0,0)
t: 44 Correlation: nan Avg: nan
t: 45 In (0,0) Current: (0,0)
t: 45 Correlation: nan Avg: nan
t: 46 In (0,0) Current: (0,0)
t: 46 Correlation: nan Avg: nan
t: 47 In (0,0) Current: (0,0)
t: 47 Correlation: nan Avg: nan
t: 48 In (0,0) Current: (0,0)
t: 48 Correlation: nan Avg: nan
t: 49 In (0,0) Current: (0,0)
t: 49 Correlation: nan Avg: nan
t: 50 In (0,0) Current: (0,0)
t: 50 Correlation: nan Avg: nan
t: 51 In (0,0) Current: (0,0)
t: 51 Correlation: nan Avg: nan
t: 52 In (0,0) Current: (0,0)
t: 52 Correlation: nan Avg: nan
t: 53 In (0,0) Current: (0,0)
t: 53 Correlation: nan Avg: nan
t: 54 In (0,0) Current: (0,0)
t: 54 Correlation: nan Avg: nan
t: 55 In (0,0) Current: (0,0)
t: 55 Correlation: nan Avg: nan
t: 56 In (0,0) Current: (0.114258,-0.0864258)
t: 56 Correlation: 0 Avg: nan
t: 57 In (0,0) Current: (0.100586,-0.0454102)
t: 57 Correlation: 0 Avg: nan
t: 58 In (0,0) Current: (0.124512,-0.15332)
t: 58 Correlation: 0 Avg: nan
t: 59 In (0,0) Current: (0.293457,-0.193848)
t: 59 Correlation: 0 Avg: nan
t: 60 In (0,0) Current: (0.267578,0.0170898)
t: 60 Correlation: 0 Avg: nan
t: 61 In (0,0) Current: (-0.257324,0.100586)
t: 61 Correlation: 0 Avg: nan
t: 62 In (0,0) Current: (0.0385742,-0.078125)
t: 62 Correlation: 0 Avg: nan
t: 63 In (0,0) Current: (0.211914,-0.0322266)
t: 63 Correlation: 0 Avg: nan
t: 64 In (0,0) Current: (0.0200195,0.0834961)
t: 64 Correlation: 0 Avg: nan
t: 65 In (0,0) Current: (0.130859,0.0551758)
t: 65 Correlation: 0 Avg: nan
t: 66 In (0,0) Current: (-0.11377,-0.0424805)
t: 66 Correlation: 0 Avg: nan

Start testing: Mar 31 08:28 IST
----------------------------------------------------------
1/2 Testing: test_dvbt2
1/2 Test: test_dvbt2
Command: "/bin/sh" "/home/craft/Dropbox/PhD/SDR/GRC/gr-dvbt2/build/lib/test_dvbt2_test.sh"
Directory: /home/craft/Dropbox/PhD/SDR/GRC/gr-dvbt2/build/lib
"test_dvbt2" start time: Mar 31 08:28 IST
Output:
----------------------------------------------------------
.

<end of output>
Test time = 0.10 sec
----------------------------------------------------------
Test Passed.
"test_dvbt2" end time: Mar 31 08:28 IST
"test_dvbt2" time elapsed: 00:00:00
----------------------------------------------------------

2/2 Testing: qa_p1_detector
2/2 Test: qa_p1_detector
Command: "/bin/sh" "/home/craft/Dropbox/PhD/SDR/GRC/gr-dvbt2/build/python/qa_p1_detector_test.sh"
Directory: /home/craft/Dropbox/PhD/SDR/GRC/gr-dvbt2/build/python
"qa_p1_detector" start time: Mar 31 08:28 IST
Output:
----------------------------------------------------------
136383191
In constructor
t: 1 In (0,0) Current: (-0.16748,-0.0776367)
t: 1 Correlation: 0 Avg: 0
t: 2 In (0,0) Current: (-0.0864258,-0.109863)
t: 2 Correlation: 0 Avg: 0
t: 3 In (0,0) Current: (-0.144531,0.0864258)
t: 3 Correlation: 0 Avg: 0
t: 4 In (0,0) Current: (-0.0581055,0.043457)
t: 4 Correlation: 0 Avg: 0
t: 5 In (0,0) Current: (0.484863,-0.0273438)
t: 5 Correlation: 0 Avg: 0
t: 6 In (0,0) Current: (0.171875,0.185547)
t: 6 Correlation: 0 Avg: 0
t: 7 In (0,0) Current: (0.0268555,0.133789)
t: 7 Correlation: 0 Avg: 0
t: 8 In (0,0) Current: (0.0405273,-0.0151367)
t: 8 Correlation: 0 Avg: 0
t: 9 In (0,0) Current: (-0.39502,0.0942383)
t: 9 Correlation: 0 Avg: 0
t: 10 In (0,0) Current: (-0.0869141,0.090332)
t: 10 Correlation: 0 Avg: 0
t: 11 In (0,0) Current: (0.163086,0.0136719)
t: 11 Correlation: 0 Avg: 0
t: 12 In (0,0) Current: (0.104492,-0.019043)
t: 12 Correlation: 0 Avg: 0
t: 13 In (0,0) Current: (-0.0424805,0.00195312)
t: 13 Correlation: 0 Avg: 0
t: 14 In (0,0) Current: (-0.296387,-0.0620117)
t: 14 Correlation: 0 Avg: 0
t: 15 In (0,0) Current: (-0.12793,-0.23584)
t: 15 Correlation: 0 Avg: 0
t: 16 In (0,0) Current: (0.157227,-0.126465)
t: 16 Correlation: 0 Avg: 0
t: 17 In (0,0) Current: (0.0126953,0.105469)
t: 17 Correlation: 0 Avg: 0
t: 18 In (0,0) Current: (0.00830078,0.219238)
t: 18 Correlation: 0 Avg: 0
t: 19 In (0,0) Current: (0.10498,0.378906)
t: 19 Correlation: 0 Avg: 0
t: 20 In (0,0) Current: (-0.0395508,0.11377)
t: 20 Correlation: 0 Avg: 0
t: 21 In (0,0) Current: (-0.0112305,-0.284668)
t: 21 Correlation: 0 Avg: 0
t: 22 In (0,0) Current: (-0.0712891,-0.0488281)
t: 22 Correlation: 0 Avg: 0
t: 23 In (0,0) Current: (-0.18457,0.193359)
t: 23 Correlation: 0 Avg: 0
t: 24 In (0,0) Current: (0.125,-0.111328)
t: 24 Correlation: 0 Avg: 0
t: 25 In (0,0) Current: (0.0244141,-0.20166)
t: 25 Correlation: 0 Avg: 0
t: 26 In (0,0) Current: (-0.0507812,0.181152)
t: 26 Correlation: 0 Avg: 0
t: 27 In (0,0) Current: (0.319336,0.117188)
t: 27 Correlation: 0 Avg: 0
t: 28 In (0,0) Current: (0.102051,-0.24707)
t: 28 Correlation: 0 Avg: 0
t: 29 In (0,0) Current: (-0.0668945,0.081543)
t: 29 Correlation: 0 Avg: 0
t: 30 In (0,0) Current: (0.14209,0.342285)
t: 30 Correlation: 0 Avg: 0
t: 31 In (0,0) Current: (0.0673828,0.0957031)
t: 31 Correlation: 0 Avg: 0
t: 32 In (0,0) Current: (0.0380859,-0.111328)
t: 32 Correlation: 0 Avg: 0
t: 33 In (0,0) Current: (0.118164,-0.0585938)
t: 33 Correlation: 0 Avg: 0
t: 34 In (0,0) Current: (0.0878906,0.117188)
t: 34 Correlation: 0 Avg: 0
t: 35 In (0,0) Current: (0.0419922,0.129395)
t: 35 Correlation: 0 Avg: 0
t: 36 In (0,0) Current: (0.0419922,-0.00390625)
t: 36 Correlation: 0 Avg: 0
t: 37 In (0,0) Current: (0.140137,0.000976562)
t: 37 Correlation: 0 Avg: 0
t: 38 In (0,0) Current: (-0.0581055,0.0708008)
t: 38 Correlation: 0 Avg: 0
t: 39 In (0,0) Current: (-0.213379,0.125977)
t: 39 Correlation: 0 Avg: 0
t: 40 In (0,0) Current: (-0.0307617,0.121582)
t: 40 Correlation: 0 Avg: 0
t: 41 In (0,0) Current: (-0.043457,-0.0444336)
t: 41 Correlation: 0 Avg: 0
t: 42 In (0,0) Current: (-0.0107422,-0.059082)
t: 42 Correlation: 0 Avg: 0
t: 43 In (0,0) Current: (0.152832,-0.0253906)
t: 43 Correlation: 0 Avg: 0
t: 44 In (0,0) Current: (-0.0424805,-0.0849609)
t: 44 Correlation: 0 Avg: 0
t: 45 In (0,0) Current: (-0.0864258,-0.0258789)
t: 45 Correlation: 0 Avg: 0
t: 46 In (0,0) Current: (0.112305,0.0488281)
t: 46 Correlation: 0 Avg: 0
t: 47 In (0,0) Current: (0.112305,-0.103516)
t: 47 Correlation: 0 Avg: 0
t: 48 In (0,0) Current: (-0.00439453,0.113281)
t: 48 Correlation: 0 Avg: 0
t: 49 In (0,0) Current: (0.117676,0.132324)
t: 49 Correlation: 0 Avg: 0
t: 50 In (0,0) Current: (0.206543,-0.0297852)
t: 50 Correlation: 0 Avg: 0
t: 51 In (0,0) Current: (0.0449219,0.154297)
t: 51 Correlation: 0 Avg: 0
t: 52 In (0,0) Current: (0.110352,0.0512695)
t: 52 Correlation: 0 Avg: 0
t: 53 In (0,0) Current: (-0.0170898,-0.0288086)
t: 53 Correlation: 0 Avg: 0
t: 54 In (0,0) Current: (-0.0527344,0.194824)
t: 54 Correlation: 0 Avg: 0
t: 55 In (0,0) Current: (0.189941,0.0537109)
t: 55 Correlation: 0 Avg: 0
t: 56 In (0,0) Current: (0.114258,-0.0864258)
t: 56 Correlation: 0 Avg: 0
t: 57 In (0,0) Current: (0.100586,-0.0454102)
t: 57 Correlation: 0 Avg: 0
t: 58 In (0,0) Current: (0.124512,-0.15332)
t: 58 Correlation: 0 Avg: 0
t: 59 In (0,0) Current: (0.293457,-0.193848)
t: 59 Correlation: 0 Avg: 0
t: 60 In (0,0) Current: (0.267578,0.0170898)
t: 60 Correlation: 0 Avg: 0
t: 61 In (0,0) Current: (-0.257324,0.100586)
t: 61 Correlation: 0 Avg: 0
t: 62 In (0,0) Current: (0.0385742,-0.078125)
t: 62 Correlation: 0 Avg: 0
t: 63 In (0,0) Current: (0.211914,-0.0322266)
t: 63 Correlation: 0 Avg: 0
t: 64 In (0,0) Current: (0.0200195,0.0834961)
t: 64 Correlation: 0 Avg: 0
t: 65 In (0,0) Current: (0.130859,0.0551758)
t: 65 Correlation: 0 Avg: 0
t: 66 In (0,0) Current: (-0.11377,-0.0424805)
t: 66 Correlation: 0 Avg: 0

Michael, Marcus,

Right now, the code is a work in progress so I haven't made a git repository out of it. However, I have it on dropbox. Here's the link to the source folder(p1_detector_impl.cc is the source in question):

https://www.dropbox.com/sh/blfmxsaidrkh28t/AAArp8IHavzCGFlJs6E6-Hrca?dl=0

As for Marcus's question regarding why use a circular buffer?

It isn't exactly a circular buffer now, but more of a shift register. The reasons are as follows:
1. I needed running sums for correlations in B-Branch and C-Branch correlators, and Power Sums (for average power) to normalize them. Then, I also needed a finite delay buffer to delay the C-Branch before it gets multiplied with the B-Branch.
2. It kind of carried over from the last implementation attempt:

Assertion: If a peak is detected after the multiplication, the signal boundary is 1024 samples behind that index. 

Once the correlations crossed a threshold (the code entered state=1), instead of looking back, I then needed to look forward to see if it were a false alarm or not. So, I compute the correlations across all available current inputs and try to find a peak. If a peak is found, enter state=3 where we do a correlation with the carrier distribution sequence after FFT of all signals of interest. So, here, I not only needed just the single value (the running sum), but the entire state of the delay register and the B-Branch correlator.

I hope I am able to convey the reason for implementing one myself.

In the current implementation, I make an assumption that the threshold is so high that only the desired signals would cross it (100-150 times the average). So I skip the state=1 logic and directly go into state=2 logic of aggressively doing a FFT and correlation with the CDS.

However, I don't think this has a binding on the incoming values. Use of buffers is internal to the implementation, I am just printing out the current values as they arrive.

For example, when I use the test file in 'make test', the values fed in are non-zero from t=1. However, when using gnuradio-companion, t=56 line is where the file source starts yielding proper inputs to my block. The stdout prints of the initial values in both GRC and make tests are attached. The gnuradio-companion version has my first 55 samples zeroed and the 56th input onward is then same for both.


P.S.: The source stream is a 1.2 Gigs file, so haven't uploaded it. If you'd like I can do that too. It was generated by using a DVB-T2 Tx block and writing the output into a file sink.

Warm regards,
Anshul Thakur

On 31 March 2018 at 02:27, Müller, Marcus (CEL) <mueller@kit.edu> wrote:
Hi Anshul,

you shouldn't have to have your own buffer for a running sum – can you
explain why you're doing that?
A running sum can trivially be implemented with the IIR filter block
with Feed-Forward taps (1,) and Feed-back taps (1,0)!
Where does in a running sum does a division take place?

> (a) Why am I getting the initial zero samples from the file block in
> gnuradio_companion and non-zero values when using a vector_source in
> unit tests?

If these zeros are not in the file you're reading, your block has a
bug!


> (b) What can I do about it (here specifically as a fix to the
> situation, and a general guideline to always remember)?

good question, but we'd need to know your code, your motivation for a
circular buffer, and why you're implementing a running sum yourself!

Best regards,
Marcus

On Fri, 2018-03-30 at 23:19 +0530, Anshul Thakur wrote:
> Hi,
>
> I used a circular buffer of finite size to keep the past 'N' power
> values of the sample stream in my block as a part of creating a
> running sum. This buffer is initialized to 0 in the constructor.
> The running sum of powers is used to compute the average power used
> in computing signal correlation.
>
> I have a capture stream (cfile) to test the operation of the block.
> The test case uses a vector_source_c block to read the contents of
> the file into memory. The unit tests pass without error.
>
> However, when I use the block in a flowgraph in that reads the same
> file from a file source block gnuradio_companion, I am getting the
> first few sample values as 0 which cause a divide by zero
> problem. This messes up the rest of the running sum. I don't want to
> put an 'if' block that checks for the zero condition as it is not
> expected that a device/stream would ever spit out zero values.
>
> (a) Why am I getting the initial zero samples from the file block in
> gnuradio_companion and non-zero values when using a vector_source in
> unit tests?
>
> (b) What can I do about it (here specifically as a fix to the
> situation, and a general guideline to always remember)?
>
> I am using GNURadio version 3.7.12.
>
> Regards,
> Anshul
> _______________________________________________
> Discuss-gnuradio mailing list
> Discuss-gnuradio@gnu.org
> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

No comments:

Post a Comment