Search code examples
gnuradiosoftware-defined-radiognuradio-companion

How to implement a 4 quadrant atan2 function in gnuradio


I have recently begun experimenting with SDR and have been using the GNU Radio platform.

More specifically the 'gnuradio-companion' graphical interface.

I have a need to determine a 4 quadrant arcTangent function and have run into some trouble. Within a 'GRC' file I have been able to successfully evaluate an ATAN function but, although python supports ATAN2, I have not been able to figure out how to implement this function.

I have read that there is a lookup table function included in GNU Radio called fast_atan2f but I do not know if this is accessible from within the blocks contained in the standard gnuradio-companion setup. I was able to access the python expression 'math.atan2(arg1,arg2)' from within a constant source block but I don't need this as a constant value, I'm looking for a block with two floating point inputs (or a single complex input) that will fit within a flow graph to properly evaluate the ATAN2 function.

I have included a sample 'GRC' file that may help to illustrate the issue in case my description is unclear.

link to the GNU Radio companion example file

Screenshot of the Flow Graph


Solution

  • The block gnuradio.blocks.complex_to_arg (Complex to Arg in GRC) is an atan2 operation.

    If you need two separate floating point inputs as you described, then just precede it with a Float To Complex block.

    Depending on your specific application, you may also be interested in gnuradio.analog.quadrature_demod (Quadrature Demod in GRC). This block produces essentially the derivative of atan2, but without any discontinuities at 180° or 360°. This is appropriate for e.g. demodulating FM signals.