Up front: I'm just a hobbyist, and I know zero about signal processing; I'm trying to write a simple(?) javascript algorithm and hoping I don't need a PhD in DSP to make progress on it.

I have an input signal that often shows only the tiniest difference between the max value and the min value. I'm trying to figure out a way to convert the values such that the max is proportionally much larger than the min, with a steep curve in between. I've tried everything I can think of with exponents and logarithms, even just subtracting the min from the rest of the curve, but nothing seems to work. Part of the problem, as can be seen in my awesome diagrams below, is that the signal strength varies quite a bit; I don't know how to account for that. Also, sometimes the signal is already pretty spikey, and I don't know how to account for that either.

I've poked around with google, but I don't really know what questions to ask. I'm not sure whether there is a class of algorithms that does this sort of thing. I tried "signal unsmoothing", with no luck, and I don't know what else it could be called.

Some hand-drawn diagrams, placeholders while I try to learn how to draw curves on stackexchange. The two on the left show the kinds of signals I often get: varying strength, but the max is barely bigger than the min. The one on the right is what I'm trying to get: a big spike in the middle with a steep curve down to the min.

Is there a name for a class of algorithms that does this sort of thing? Is there a better way to formulate my questions so I can google more effectively? Is there a ridiculously trivial way to do this?

badly drawn diagrams

In case it helps, my ultimate goal: I'm modeling the movement of mosquitos. I'm working on getting them to move toward the smell of their prey while accounting for negative factors such as toxins in the air, or high temperature, as well as their jittery motions to avoid being squashed. It's going pretty well, except I have this chronic problem of the input signals being too flat for meaningful comparisons.

  • 1
    $\begingroup$ It looks like you need a highly non-linear response on the signal amplitude. What I'd try first is: normalize the signal so that the maximum value is 1 and the minimum is zero (or close to zero but positive). Then, raise the signal to a very large power; say 10. This will tend to attenuate anything that is not very close to 1. $\endgroup$
    – MBaz
    Nov 7, 2016 at 2:45

1 Answer 1


What you are trying to do is Contrast Enhancement. Contrast is the ratio of maximum to the minimum.

Lets consider as example that your signal's intensity is ranging from 30 to 40 but you need a range of 0 to 255 with good contrast.

  1. Lets consider your 1D signal as I(x). First find the minimum of the signal and subtract min from the whole curve. In our example 30 is the minimum.So subtract 30 from the whole curve.The signal will be ranging from 0 to 10 now.

J(x) = I(x) - Min(I(x))

  1. But we want the intensity of the signal from 0 to 255. So find the ratio between the maximum value allowed(255 in our case) to maximum of your signal(our signal max is 10 now) and multiply the whole curve with that factor. Now our signal's intensity will be ranging from 0 to 255.

K(x) = J(x)*(Max_value_allowed/Max(J(x))

  1. At this point you should have got the spikey curve you need. But if you feel the curve is not spikey enough, contrast can be increased by applying negative slope to intensities in first half of histogram(In our case 0 to 127) and positive slope to intensities in second half of histogram(128 to 255 in our case) which will make lower intensities much lower and the high intensities much higher.Good luck.Hope this helps you.

Added:Instead of above step3 you could also do,

L(x) = power(K(x),n)/power(Max(K(x)),n-1)

n should be greater than 1.As n increases the spikiness also increases. In your case choosing around 2 or 3 should be enough I guess.

  • $\begingroup$ This sounds like what I'm looking for. I was doing step #1, using the wrong fraction in #2, and never even thought of #3, which is the one I needed most. About applying slope, what should I use as the multiplier? Say I have points $P_1$ and $P_2$ with a slope of $m_1$ between them, and then $P_3$ and $P_4$ with slope $m_2$ between them, should I multiply $m_1$ and $m_2$ by some predetermined constant? Or by some function of the slope between each pair of points? Something else? Could you help me clarify that part? Thanks so much! $\endgroup$ Nov 7, 2016 at 5:36
  • 1
    $\begingroup$ I have added an alternative step 3 which will reduce the overhead of selecting slopes.. $\endgroup$ Nov 7, 2016 at 7:20
  • $\begingroup$ Just wanted to let you know: it took me a while to get it implemented properly, but it works great now. Thank you very much for this answer. $\endgroup$ Nov 7, 2016 at 23:34
  • $\begingroup$ Glad to help you! $\endgroup$ Nov 8, 2016 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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