0
$\begingroup$

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

$\endgroup$
  • $\begingroup$ So you are asking if it already has a name? $\endgroup$ – nabla Oct 17 '14 at 22:24
  • $\begingroup$ 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? $\endgroup$ – nabla Oct 17 '14 at 22:27
  • 1
    $\begingroup$ In numeric/signal flowcharts, such a function is typically called a "limiter", a "clipper", a "clamp", or a "saturation block". $\endgroup$ – COTO Oct 17 '14 at 22:29
  • $\begingroup$ 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()? $\endgroup$ – Tommy Oct 17 '14 at 22:30
  • $\begingroup$ 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:" $\endgroup$ – Tommy Oct 17 '14 at 22:43
1
$\begingroup$

In signal processing it's called clipping.

$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – Tommy Oct 17 '14 at 23:12
  • $\begingroup$ @Tommy The pictures in the article show both the top and bottom clipped. $\endgroup$ – user147263 Oct 17 '14 at 23:15
1
$\begingroup$

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

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

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
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.