Calculating a new range?

Discussion in 'Math' started by Art, Feb 5, 2012.

  1. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    785
    61
    Hi Guys,
    I have a value that can be between 680 to 830.
    I want to convert this value to a new range between
    1137 and 1377.

    Is there a formula I could use to convert any original value to the new value?
    Cheers, Art.
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,362
    Do you know how to use graph paper? Think of a graph.
    The horizontal scale is the x-axis. The vertical scale is the y-axis.
    Do you know the equation for a straight line?
    You have two points on the graph, (x1,y1) and (x2,y2).
    The points are (680,1137) and (830,1377). Take it from there.
    If you need more help, let me know.
     
  3. holnis

    Member

    Nov 25, 2011
    50
    4
    Yes! That's a simple linear conversion.

    So:

    NewValue = (((OriginalValue - OriginalMin) * (NewMax - NewMin)) / (OriginalMax - OriginalMin)) + NewMin


    Or to make it a little more readable:

    OriginalRange = (OriginalMax - OriginalMin)
    NewRange = (NewMax - NewMin)

    Thus :

    NewValue = (((OriginalValue - OriginalMin) * NewRange) / OriginalRange) + NewMin


    Hope this Helps :)
     
  4. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    785
    61
    Thanks :)
    Since the ranges are constant, it looks like some of that can
    be calculated just once and simplified.
    ie (Newmax - Newmin) which will make things easier.
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,446
    3,362
    The next question is are you doing this on a microcontroller? There are ways to avoid using floating-point arithmetic.
     
  6. Papabravo

    Expert

    Feb 24, 2006
    10,147
    1,791
    Being conversant with fractions is a great help in doing fixed point arithmetic on a microcontroller.
     
  7. Art

    Thread Starter Distinguished Member

    Sep 10, 2007
    785
    61
    Yes it is for a microcontroller, and I'm stuck with integers.
    volts = avoltage * 10 '
    volts = volts - 2550 '
    volts = volts * 10 '
    volts = volts / 575 '
    volts = volts * 93 '
    volts = volts + 4450 '

    This is the best I've come up with so far.
    There is some error, but the end display is never more
    than 0.1 Volt in error when within range according to my multimeter.
    avoltage is the original value, volts is the working variable being converted.

    1137 and 1377 (the range to convert to) is a reading
    from 11.37 volts to 13.77 volts, but since then, new samples have been taken in order to extend that range.
     
Loading...