Re: [Discuss-gnuradio] Dealing with `divide 0` or `Inf` in GNU Radio C++ code.
Hi Jeff, you could use a strcture like this MA_divisor = Divide: % =multiply = pad sink. |- threshold detector-^ i.e. take the divisor path in parallel into threshold detector and use the output (in {0,1}) in a multiplier for masking the dividing by zero cases. By adjusting the threshold to 0+eps (a small number of your choice), this also solves the problem of huge output if the divisor is _almost_ 0. Best regards Stephan Ludwig Robert Bosch GmbH Corporate Sector Research Advance Engineering, Communication Technology (CR/AEH4) Renningen 70465 Stuttgart GERMANY www.bosch.com Tel. +49(711)811-8809 Fax +49(711)811-1052 Mobile +49(172)5630639 stephan.ludw...@de.bosch.com Registered Office: Stuttgart, Registration Court: Amtsgericht Stuttgart, HRB 14000; Chairman of the Supervisory Board: Franz Fehrenbach; Managing Directors: Dr. Volkmar Denner, Dr. Stefan Asenkerschbaumer, Dr. Rolf Bulander, Dr. Stefan Hartung, Dr. Markus Heyn, Dr. Dirk Hoheisel, Christoph Kübel, Uwe Raschke, Dr. Werner Struth, Peter Tyroller -Ursprüngliche Nachricht- Von: discuss-gnuradio-bounces+stephan.ludwig2=de.bosch@gnu.org [mailto:discuss-gnuradio-bounces+stephan.ludwig2=de.bosch@gnu.org] Im Auftrag von Jeff Long Gesendet: Mittwoch, 19. August 2015 13:31 An: discuss-gnuradio@gnu.org Betreff: Re: [Discuss-gnuradio] Dealing with `divide 0` or `Inf` in GNU Radio C++ code. (That should be moving averages, not correlators). Also, subtracting instead of dividing might do what you want. Jeff On 08/19/2015 07:25 AM, Jeff Long wrote: Jeon, You can add an appropriate constant before the divide and compensate for it afterward. The exact math will depend on the values coming out of the correlators. Jeff On 08/19/2015 06:50 AM, Jeon wrote: Let's think about the following auto/cross correlator: http://i.imgur.com/Fy5hdVj.png I've placed `divide` because I need to normalize the correlation result. If we place `null source`, or `constant source with value of zero` right before the `pad source`, the simplified form of the correlator becomes 0 divided by 0. I've placed `time sink` right after the `pad sink` then, I can see the line hit the infinity. With a simplified flow graph: http://i.imgur.com/Msx9EQj.png Back to the my correlator, how can I handle such `infinity` value coming into the next block? My guess is that if a source block is a type of float, then `infinity` might have a maximum value of float. So, I think I can reject `infinity` value with `if (in[i] threshold)`, where `threshold` is big enough, for correlator it is fine to have a value just larger than one. Do you think what I guess is right? Or can some boost numeric types, or PMT help somehow to deal with it? In addition, not important. In pages http://en.cppreference.com/w/cpp/types/numeric_limits/infinity and http://en.cppreference.com/w/cpp/numeric/math/INFINITY, non floating point numeric types can't handle infinity. Is it also applied to GNU Radio? Regards, Jeon. ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
Re: [Discuss-gnuradio] Dealing with `divide 0` or `Inf` in GNU Radio C++ code.
Jeon, You can add an appropriate constant before the divide and compensate for it afterward. The exact math will depend on the values coming out of the correlators. Jeff On 08/19/2015 06:50 AM, Jeon wrote: Let's think about the following auto/cross correlator: http://i.imgur.com/Fy5hdVj.png I've placed `divide` because I need to normalize the correlation result. If we place `null source`, or `constant source with value of zero` right before the `pad source`, the simplified form of the correlator becomes 0 divided by 0. I've placed `time sink` right after the `pad sink` then, I can see the line hit the infinity. With a simplified flow graph: http://i.imgur.com/Msx9EQj.png Back to the my correlator, how can I handle such `infinity` value coming into the next block? My guess is that if a source block is a type of float, then `infinity` might have a maximum value of float. So, I think I can reject `infinity` value with `if (in[i] threshold)`, where `threshold` is big enough, for correlator it is fine to have a value just larger than one. Do you think what I guess is right? Or can some boost numeric types, or PMT help somehow to deal with it? In addition, not important. In pages http://en.cppreference.com/w/cpp/types/numeric_limits/infinity and http://en.cppreference.com/w/cpp/numeric/math/INFINITY, non floating point numeric types can't handle infinity. Is it also applied to GNU Radio? Regards, Jeon. ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
Re: [Discuss-gnuradio] Dealing with `divide 0` or `Inf` in GNU Radio C++ code.
(That should be moving averages, not correlators). Also, subtracting instead of dividing might do what you want. Jeff On 08/19/2015 07:25 AM, Jeff Long wrote: Jeon, You can add an appropriate constant before the divide and compensate for it afterward. The exact math will depend on the values coming out of the correlators. Jeff On 08/19/2015 06:50 AM, Jeon wrote: Let's think about the following auto/cross correlator: http://i.imgur.com/Fy5hdVj.png I've placed `divide` because I need to normalize the correlation result. If we place `null source`, or `constant source with value of zero` right before the `pad source`, the simplified form of the correlator becomes 0 divided by 0. I've placed `time sink` right after the `pad sink` then, I can see the line hit the infinity. With a simplified flow graph: http://i.imgur.com/Msx9EQj.png Back to the my correlator, how can I handle such `infinity` value coming into the next block? My guess is that if a source block is a type of float, then `infinity` might have a maximum value of float. So, I think I can reject `infinity` value with `if (in[i] threshold)`, where `threshold` is big enough, for correlator it is fine to have a value just larger than one. Do you think what I guess is right? Or can some boost numeric types, or PMT help somehow to deal with it? In addition, not important. In pages http://en.cppreference.com/w/cpp/types/numeric_limits/infinity and http://en.cppreference.com/w/cpp/numeric/math/INFINITY, non floating point numeric types can't handle infinity. Is it also applied to GNU Radio? Regards, Jeon. ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio ___ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio