If you have a problem or need to report a bug please email : support@dsprobotics.com
There are 3 sections to this support area:
DOWNLOADS: access to product manuals, support files and drivers
HELP & INFORMATION: tutorials and example files for learning or finding premade modules for your projects
USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here
Math help
11 posts
• Page 1 of 2 • 1, 2
Math help
Hey friends,
I have to revisit an old code with this nasty formula: 0.0001^( SampleRate / ( 10^(( x1)*4.307)  4.925e005 )*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!
I have to revisit an old code with this nasty formula: 0.0001^( SampleRate / ( 10^(( x1)*4.307)  4.925e005 )*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!
 Attachments

 formula.fsm
 (254.63 KiB) Downloaded 34 times
 adamszabo
 Posts: 554
 Joined: Sun Jul 11, 2010 7:21 am
Re: Math help
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
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

aronb  Posts: 133
 Joined: Sun Apr 17, 2011 3:08 am
 Location: Florida, USA
Re: Math help
Try Simplify[0.0001^( f / ( 10^(( x1)*4.307)  4.925e005 )*600 )] at https://www.wolframalpha.com/
 juha_tp
 Posts: 44
 Joined: Fri Nov 09, 2018 10:37 pm
Re: Math help
.
Last edited by MichaelBenjamin on Mon Sep 21, 2020 11:02 am, edited 1 time in total.
 MichaelBenjamin
 Posts: 276
 Joined: Tue Jul 13, 2010 1:32 pm
Re: Math help
What is the range for variable "x" ?
 juha_tp
 Posts: 44
 Joined: Fri Nov 09, 2018 10:37 pm
Re: Math help
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 01 only.
 adamszabo
 Posts: 554
 Joined: Sun Jul 11, 2010 7:21 am
Re: Math help
The formula that is implemented in the schematic should read
0.0001^{1/[600*SampleRate*(10^4.307*(x  1)  4.925e5)]}
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%.
0.0001^{1/[600*SampleRate*(10^4.307*(x  1)  4.925e5)]}
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%.

martinvicanek  Posts: 1122
 Joined: Sat Jun 22, 2013 8:28 pm
Re: Math help
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?
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?
 adamszabo
 Posts: 554
 Joined: Sun Jul 11, 2010 7:21 am
Re: Math help
Derive the constants in Martin's equation once when the sample rate changes, then use the simplified equation thereafter?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?
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.
I keep a pair of oven mitts next to my computer so I don't get a concussion from slapping my forehead while I'm reading the responses to my questions.
 deraudrl
 Posts: 165
 Joined: Thu Nov 28, 2019 9:12 pm
 Location: SoCal
Re: Math help
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.
 Attachments

 stream_formula.fsm
 (121.88 KiB) Downloaded 40 times

martinvicanek  Posts: 1122
 Joined: Sat Jun 22, 2013 8:28 pm
11 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: No registered users and 36 guests