0

I'm working on a web application that uses an oscillator. It has a parameter that goes from 0 to 100 percent. I translate that percent into hertz using this equation: $$ \text{frequency} = 2^{(\lfloor 128*\text{percent} \rfloor - 69)/12}*440 $$

I am having some trouble solving the equation for percent so that given a frequency, I can get a percent value to send back to my app. Help please? :]

MPW
  • 43,638
Awk34
  • 208
  • 2
  • 12
  • Unfortunately, there is no way to determine the percent exactly as a function of frequency. The floor function you took is not invertible meaning you can only get a range of values for your percent, not a unique one. – Cameron Williams Mar 05 '14 at 21:11
  • Thanks for the answers guys. They helped me out and I was able to solve my problem. – Awk34 Mar 06 '14 at 01:41

3 Answers3

1

$$f = 2^{(x - 69)/12} \times 440$$ inverts into $$x = 69 + 12 \log_2(f/440)$$ but in your case $x = \lfloor 128p \rfloor$, which is impossible to invert exactly because it maps intervals to single numbers (i.e. the function is not one-to-one and so does not have an inverse).

For example, $p = 10^{-9}$ and $p = 10^{-8}$ would yield the same $x=0$, so if I tell you $x=0$, there is no way to imply what the original $p$ was directly.

EDIT You could bound it, however. $x$ must certainly be an integer and then, since you are rounding down, $x = \lfloor 128p \rfloor$ means $$ x \leq 128p < x+1 \Leftrightarrow \frac{x}{128} \leq p < \frac{x+1}{128} $$

gt6989b
  • 54,422
1

There will not be a unique answer because the $\lfloor\cdot\rfloor$ function is not 1-1. There will be a range of values. All of the values of $p$ will be (where $f$ denotes frequency and $p$ denotes percent) at least

$$(69 + 12\log_2(f/440))/128$$

but strictly less than

$$(70 + 12\log_2(f/440))/128,$$

I believe. The reason is that if $\lfloor x \rfloor = n$, then $n\leq x < n+1$. You should be able to test this pretty quickly (I'm lazy).

MPW
  • 43,638
-1

Since the floor function is not bijective, one can not invert this equation. Ignoring the floor function gives: $$p=\frac{69}{128}+\frac{12\ln\left(\frac{f}{440}\right)}{128\ln 2}$$ where $f$ is the frequency and $p$ is the percentage.

user5402
  • 3,006
  • 1
    I also believe we can ignore the floor function on p , just use the integer part of RHS ,.. BUT i'm not 100% sure. I'm upvoting your answer. :) – neofoxmulder Mar 05 '14 at 21:32
  • 1
    Guys, this isn't pure mathematics; the OP just want to build a web application. – user5402 Mar 05 '14 at 21:37