# adjust mean of signal using exponential

I have discrete signals whose values are between 0 and 1.

I wish to post-process such a signal such that the mean of its values equals 0.5, yet keeping maximum and minimum values 0/1 intact. Intuitively, I think an 'element-wise' exponential would be the right approach, yet I can't seem to come up with the method to determine the value of the appropriate exponential.

Fictive matlab example to illustrate:

>> s=[0.2 0.7 1 0.5 0.4 0.2 0 0.3];
>> mu=mean(s)
mu =  0.41250


What is the best method to determine the 0.69998 exponential ?

• This is not an exponential but a power law. – Yves Daoust Sep 21 '15 at 8:26
• @YvesDaoust: This is a subtlety that I don’t master. Can you please elaborate? – Stevo Sep 21 '15 at 12:44
• Subtle. You are performing an exponentiation of each of your samples $s$, with exponent or power $a$. It is defined as $s^a = \exp{a \log{s}}$ for $s>0$, a sort of exponential of a $\log{s}$, called a power-law. An "exponential" of your data could be thought to take a form like $\exp{a s}$. – Laurent Duval Sep 22 '15 at 17:31

You need to do it numerically, as a related toy problem $2^a + 3^a = 4$ appears to have no symbolic solution. Bisection method (binary search) is probably the easiest solver to implement:

minexponent = 0;
maxexponent = 2;
targetsum = 10;
precision = 32;
loop precision times {
exponent = (minexponent + maxexponent)*0.5;
if (sum(s.^exponent) < targetsum) {
maxexponent = exponent;
} else {
minexponent = exponent;
}
}
return exponent;


The smallest possible exponent value is 0 for your problem. If you are unsure about the largest possible exponent value, you can test the easy-to-check exponents 1, 2, 4, 8, 16 etc. (as many as needed before the sum goes below the target) before the above code, exponentiating into an auxiliary array by multiplying each element by itself.

Note that if all of the elements are zero, or if all of the elements are one, then you cannot get any other mean than that by exponentiation.

The plot below shows 1000 runs of the algorithm, and the value of exponent at each iteration. • Thanks for your answer. It makes it evident that I indeed would need to go down a numerical root-finding approach. The bisection method is probably good-enough for my purpose and indeed simplest (vs other root finding methods I've just read about) – Stevo Sep 21 '15 at 12:56