"compression" transform

47 Views Asked by At

Is there a mathematical transform that cuts off a signal at two extreme values? Here is code to do what I want:

def validTrans(inputValue, upper, lower):
if inputValue > upper:
   return upper
elif inputValue < lower:
   return lower
else:
   return inputValue

It seems common enough to need to compress a range (alternatively put, cut off extreme values at some threshold) that I thought this might have a name, like "someGuysNameTransform(input, u, l)". I can do this using a lambda function if needed, just wondering if this is reinventing the wheel.

Edit: nothing here seems to be it http://en.wikipedia.org/wiki/List_of_transforms

3

There are 3 best solutions below

2
On BEST ANSWER

In signal processing it's called clipping.

1
On

This is most often (in my experience) referred to as clamping the input value.

0
On

Your function is fine. If you insist on using fancy functions, then notice that an equivalent formulation would be:

def validTrans(inputValue, upper, lower):
    temp = max(lower, inputValue)
    return min(upper,       temp)

Translating to absolute values, we can use something like:

def validTrans(inputValue, upper, lower):
    temp = (lower + inputValue + abs(lower - inputValue)) / 2
    return (upper +       temp - abs(upper -       temp)) / 2