Shop OBEX P1 Docs P2 Docs Learn Events
QLOG fixed point output versus SPIN2 floating point? — Parallax Forums

QLOG fixed point output versus SPIN2 floating point?

Has anyone come up with a slick way of converting QLOG's fixed point result to SPIN2 floating point format?

Comments

  • Have you tried using floating point log() in FlexC, compiling and looking at the disassembly? IIRC, FlexC uses the CORDIC unit for floating point math, at least QMUL, QDIV and SQRT. I haven't tested exp() and log(), so far.

  • ersmithersmith Posts: 6,270

    No need to look at the disassembly, the source code for __builtin_log2f and __builtin_exp2f are in the FlexProp include/libsys/powers.c file. They're not highly optimized, but I think they work OK.

  • cgraceycgracey Posts: 14,293

    The latest versions of Spin2 (found in PNut, Pnut-TS, and PropTools, I believe) have several new log and exp functions that work in floating point.

  • Thanks, Chip - that'll be used in the spectrum display on the radio receiver I'm working on. Log amplitude is the norm.

  • RaymanRayman Posts: 16,124

    Anybody know how qlog and qexp work?

    Was just testing it and doesn't make any sense to me..

    PUB Main()|x,y
    
        x:=2
        y:=qexp(x)
        debug(fdec(y))
    
        x:=256
        y:=qlog(x)
        debug(fdec(y))
    
    Cog0  y = 1.401298e-45
    Cog0  y = 2.000000e+00
    

    Getting similar results in PNut, FlexProp, and Spin Tools IDE, so guess that's good anyway...

  • QLOG and QEXP are fixed point

    PUB Main()|x,y
    
        x:=3<<27
        y:=qexp(x)
        debug(udec(y))
    
        x:=256
        y:=qlog(x)>>27
        debug(udec(y))
    
    Cog0  INIT $0000_0000 $0000_0000 load
    Cog0  INIT $0000_0F5C $0000_1850 jump
    Cog0  y = 8
    Cog0  y = 8
    
  • JonnyMacJonnyMac Posts: 9,723

    From the latest Spin2 docs

  • RaymanRayman Posts: 16,124

    Oh, I see .. thanks

  • RaymanRayman Posts: 16,124
    edited 2026-02-24 23:18

    It's a bit confusing as QLOG works in base 2 and log works in e... Think starting to get it now...
    Also have to remember what version of debug type to use... UDEC for qlog, and FDEC for log...

  • JonnyMacJonnyMac Posts: 9,723

    There is a LOG2 operator in that list. Does that match QLOG?

  • ersmithersmith Posts: 6,270

    @Rayman :

    QLOG is a fixed point logarithm using the cordic. Since it's an interface to P2 hardware it's not available on P1 (similarly for other cordic operations, like ROTXY and POLXY). However, the floating point LOG operators (LOG, LOG2, LOG10) are available on P1 in FlexSpin. On P1 they use the built in log tables in the ROM, so they're a little less accurate than the P2 versions. Ditto for QEXP vs EXP, EXP2, EXP10.

  • ersmithersmith Posts: 6,270

    Just thought I'd mention that in the latest flexspin QEXP and QLOG are supported on P1, albeit at reduced precision. It turns out that in the EXP and LOG calculations I was basically emulating QEXP and QLOG anyway (using the ROM tables rather than CORDIC), so I moved that code into the common area and provided interfaces. The tables are only accurate to 16 bits rather than 32, but at least programs using them can run.

  • RaymanRayman Posts: 16,124

    @ersmith that is for Spin2 on P1 right?

    Thanks for that.

  • bob_g4bbybob_g4bby Posts: 571
    edited 2026-03-09 18:57

    For P2, the 64/96/128 Math library on Obex has a 5/27 fixed point format to integer conversion but it's in Spin, not Pasm

  • In digital signal processing and embedded programming, choosing between QLOG fixed-point and SPIN2 floating-point represents a trade-off between computational efficiency and ease of use.

  • bob_g4bbybob_g4bby Posts: 571
    edited 2026-03-09 19:06

    Well, my primary concern was that the 5/27 fixed point format output from cordic qlog in my inline pasm method wasn't displayable in a debug SCOPE window. Any suggestions, please? I have logarray[1024] full of fixed point values, how to display them is the thing.
    It's the output of an fft; receiver spectrum displays are best with a log y-axis. I would have thought I could have simply plotted the array as if it was filled with unsigned integers - the numbers would be just scaled by the shift of the decimal point 27 places to the right, but the display doesn't look right.
    I'll have another go on those lines, perhaps with a very simple signal rather than the receiver adc output I've been using.
    The other thing to try initially is the debug FFT display, which should take the output from the receiver adc directly. That won't help later when the P2 is driving an lcd display of course.
    All good fun, bob

Sign In or Register to comment.