def energyNormFunc(v, mean, stddev):
    """Energy normalizes the given value.
    For normally distributed data, 95% of it should lie within 2 stddev's of the mean.
    So we want to get 95% of the data between -127 and +127, and then we'll shift it
    up by 127 to get it from 0 to 255"""
    factor = 127.5/max(2*stddev, 0.01)
    ret = (v-mean)*factor + 127.5
    return ret