Page 1 of 2

Math help

Posted: Wed Sep 16, 2020 3:42 pm
by adamszabo
Hey friends,

I have to revisit an old code with this nasty formula: 0.0001^( SampleRate / ( 10^(( x-1)*4.307) - 4.925e-005 )*600 ), and I have to rewrite this in stream form, which will use way too much CPU because there are too many powers and a division. Are there any math wizards that can help me rewrite this in a much simpler form? It doesnt matter if there are some errors, as long as its close to it. The only variable is the 'x' and a samplerate input.

Thank you!

Re: Math help

Posted: Wed Sep 16, 2020 6:22 pm
by aronb
Hi,

I might be able to help... BUT I have a few questions:

1) What are you calculating? Might be a more efficient way...
2) Otherwise is it just that EXACT formula?
3) What tolerances do you need? How exact does what you are calculating have to be...

Thank you,

Aron

Re: Math help

Posted: Wed Sep 16, 2020 6:25 pm
by juha_tp
Try Simplify[0.0001^( f / ( 10^(( x-1)*4.307) - 4.925e-005 )*600 )] at https://www.wolframalpha.com/

Re: Math help

Posted: Wed Sep 16, 2020 7:00 pm
by MichaelBenjamin
.

Re: Math help

Posted: Wed Sep 16, 2020 7:08 pm
by juha_tp
What is the range for variable "x" ?

Re: Math help

Posted: Wed Sep 16, 2020 8:18 pm
by adamszabo
Thanks guys. This is for a decay calculation on my envelope so it needs to be pretty accurate, but it depends on the formula on how much cpu I can save. The range for the x input is from 0-1 only.

Re: Math help

Posted: Wed Sep 16, 2020 8:36 pm
by martinvicanek
The formula that is implemented in the schematic should read

0.0001^{1/[600*SampleRate*(10^4.307*(x - 1) - 4.925e-5)]}

For x in the range between 0 and 1, a reasonable approximation for 44.1k is

1 - (0.9939 + 2914*x)/(1 + x*(3102 + x*4356980))

Relative error is less than 1%.

Re: Math help

Posted: Wed Sep 16, 2020 8:52 pm
by adamszabo
Thanks Martin!

The sample rate variable must be dynamic however, as the synth will get the samerate from the DAW. I cannot set it as fixed. Any ideas what to do in that case?

Re: Math help

Posted: Wed Sep 16, 2020 9:50 pm
by deraudrl
adamszabo wrote:Thanks Martin!

The sample rate variable must be dynamic however, as the synth will get the samerate from the DAW. I cannot set it as fixed. Any ideas what to do in that case?
Derive the constants in Martin's equation once when the sample rate changes, then use the simplified equation thereafter?

Or maybe just look them up from a table: I suspect the number of different values for sample rate that you need to be able to deal with is rather small.

Re: Math help

Posted: Thu Sep 17, 2020 8:25 am
by martinvicanek
Forget my previous post. If the quantity of interest is the decay factor per sample, you need much more accuracy. I can offer the attached implementation using fast powers.