# “compression” transform

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

• So you are asking if it already has a name? – nabla Oct 17 '14 at 22:24
• But it is a trivial function, which you actually defined in the question. Why do you want another one from a library which (if it exists) will have the same computational cost? – nabla Oct 17 '14 at 22:27
• In numeric/signal flowcharts, such a function is typically called a "limiter", a "clipper", a "clamp", or a "saturation block". – COTO Oct 17 '14 at 22:29
• I guess I just prefer using standard libraries when possible for cleanliness reasons instead of reinventing many small wheels, and it seemed common enough/applicable enough that it probably exists. I could also write my own function called abs, but wouldn't you rather just call math.abs()? – Tommy Oct 17 '14 at 22:30
• Also, I think that when I go to write up my methodology, its cleaner to say "we apply the blah transform to the input" rather than "heres a function we ran on the input:" – Tommy Oct 17 '14 at 22:43

In signal processing it's called clipping.

• Because I am actually doing this with voltage, this seems perfect! However, that article only seems to discuss the upper limit case. Regardless, thanks for the pointer! – Tommy Oct 17 '14 at 23:12
• @Tommy The pictures in the article show both the top and bottom clipped. – user147263 Oct 17 '14 at 23:15

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

• This also is perfect. I only accepted clipping since I am actually working with signals and it seems thats the industry term. – Tommy Oct 17 '14 at 23:25

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