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:

&gt;&gt; s=[0.2 0.7 1 0.5 0.4 0.2 0 0.3];
&gt;&gt; mu=mean(s)
mu =  0.41250
&gt;&gt; s_adjusted=s.^0.69998;
&gt;&gt; mu_adjusted=mean(s_adjusted)
mu_adjusted =  0.50000


What is the best method to determine the 0.69998 exponential ?
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) &lt; 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.