A Piece of Code Related to DSP

Discussion in 'C Programming' started by narke, May 13, 2010.

  1. narke

    narke Guest

    Hi,

    I have a big code, and I cannot get understand some parts of it. Below
    is a piece of them:

    void determind_corr_value(void)
    {
    int8_t Leading0;
    uint32_t CorrValue;

    ...

    if( CorrValue>0)
    {
    // Detect bit number of MSB of CorrValue (Leading 0's are
    counted)
    Leading0 = 1;

    while(!(*((int16_t*) &CorrValue + 1) < 0)) // MS_Bit = 0
    {
    CorrValue <<= 1;
    Leading0++;
    }

    Leading0 -= 8;

    // increase the resolution for compensation steps to 0.5Bit by
    checking the 2nd bit
    //lint -save -e701
    Leading0 <<= 1;
    if(*((int16_t*) &CorrValue + 1) & 0x4000)
    {
    Leading0--;
    }

    // Calculate now the correction value
    if( Current < CalibrationData.I_Limit_Corr) {
    // low range
    Leading0-= (int8_t)Data.Leading0_Corr_Low;

    CorrValue = (unsigned)(long)(32768L + ((int16_t)
    (CalibrationData.Correction_Low * Leading0)));
    } else {
    // High range
    Leading0-= (int8_t)Data.Leading0_Corr_High;

    CorrValue = (unsigned)(long)(32768L + ((int16_t)
    (CalibrationData.Correction_High * Leading0)));
    }

    } else
    CorrValue = 32768;

    ...
    }


    I guess it was doing some kind of DSP, but not sure what was exactly
    going on. Especially, I hope some one have a guess and give me some
    hints for my below questions so far:

    1. Why Leading0 was assigned as 1 at begin of the process.
    2. Why 8 was substracted from the Leading0
    3. What means 0.5bit and checking for 2nd bit?
    4. Why 32768?

    I hope the code indeed implemented some algorithm that is familiar to
    some of you.


    Regards,
    woody
    narke, May 13, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Willem Oosthuizen

    DSP simulations

    Willem Oosthuizen, Jun 25, 2003, in forum: VHDL
    Replies:
    1
    Views:
    2,758
  2. Michael Gallen
    Replies:
    0
    Views:
    710
    Michael Gallen
    Nov 25, 2003
  3. Maxwell Hammer
    Replies:
    7
    Views:
    631
    Peter Hansen
    Jun 18, 2005
  4. narke

    A piece of code related to DSP

    narke, May 13, 2010, in forum: C Programming
    Replies:
    23
    Views:
    634
    narke
    May 20, 2010
  5. Patrick Plattes

    Download a file piece by piece

    Patrick Plattes, Nov 30, 2006, in forum: Ruby
    Replies:
    2
    Views:
    193
    Patrick Plattes
    Nov 30, 2006
Loading...

Share This Page