Any way to get Sin or other math function?

A place for developers to share ideas and assist each other in solving problems.

Moderators: valis, garyb

Post Reply
User avatar
Neutron
Posts: 2274
Joined: Sun Apr 29, 2001 4:00 pm
Location: Great white north eh
Contact:

Any way to get Sin or other math function?

Post by Neutron »

i just want to get a sin function with the simple math operators? or maybe with the FM operator.

i aint no math genius, but i think it might be possible.
Warp69
Posts: 679
Joined: Sun Jun 17, 2001 4:00 pm
Location: Denmark
Contact:

Post by Warp69 »

You could use polynomial approximation, like taylor series :

sin(x) = x - x^3/3! + x^5/5! - x^7/7! + x^9/9! - ...................................

You could optimize the coefficients with the Remez/Remes exchange algorithm - you will then get :

sin((pi/2)*x) = 1.5707963268 * x - 0.6459640619 * x^3 + 0.0796915849 * x^5 - 0.0046768800 * x^7 + 0.0001530302 * x^9

Remeber that x have the following range [-1 ; 1]

Or

Use the "fx LFO" module with the following parameters :

f = 0
Sel = 0
Gain = Max (2147483647)
WF = 1
RC = 3
RC = 3
P1 = Variable [-2147483647 ; 2147483647]
P2 = Same as the above

P1 = x, out1 = sin(x)

I used the above for the calculation of the width parameter in my reverbs.

Cheers
User avatar
Neutron
Posts: 2274
Joined: Sun Apr 29, 2001 4:00 pm
Location: Great white north eh
Contact:

Post by Neutron »

wow that LFO method looks great! i will try that tonight :D

thank you very much!
Warp69
Posts: 679
Joined: Sun Jun 17, 2001 4:00 pm
Location: Denmark
Contact:

Post by Warp69 »

I was hoping you would use the correct solution i.e. polynomial approximation and not the dirty LFO trick............................... :D

Cheers
User avatar
Neutron
Posts: 2274
Joined: Sun Apr 29, 2001 4:00 pm
Location: Great white north eh
Contact:

Post by Neutron »

Using a dirty hack of an existing device IS the "proper way" :D if it responds fast enough anyways. otherwise i might have no choice.
User avatar
hifiboom
Posts: 2057
Joined: Thu Aug 03, 2006 4:00 pm
Location: Germany, Munich
Contact:

Post by hifiboom »

polynomial approximation
quite dsp heavy, isn`t it?

it would be cool to have a realtime interpolated table and a SC SDK table tool to generate tables for different functions.
User avatar
Neutron
Posts: 2274
Joined: Sun Apr 29, 2001 4:00 pm
Location: Great white north eh
Contact:

Post by Neutron »

well that idea didnt work. i need to be able to input the signal i want to do the math on in realtime, and that only works with async.

yes a lookup table would be a great atom, as would "opamp", "resistor" and "capacitor" to go with "diode"

when im feeling a bit smarter maybe ill try that polynomial approximation. but i think it would be a mess.
Warp69
Posts: 679
Joined: Sun Jun 17, 2001 4:00 pm
Location: Denmark
Contact:

Post by Warp69 »

Neutron wrote:well that idea didnt work. i need to be able to input the signal i want to do the math on in realtime, and that only works with async.
Well it updates for every 14 samples.

If you need sample based calculation then polynomial approximation is the right solution.
Neutron wrote:when im feeling a bit smarter maybe ill try that polynomial approximation. but i think it would be a mess.
Someone is apparently lazy, eh? :lol:

Here's an example of a polynomial approximation : www.relab.dk/Sin.rar

I dont know what you need it for or the range of the parameters. Try connect the module to the Raw Tri osc and see the behaviour of the module.

Cheers
User avatar
Neutron
Posts: 2274
Joined: Sun Apr 29, 2001 4:00 pm
Location: Great white north eh
Contact:

Post by Neutron »

I just would like to understand how it works. i have been reading about them, and it seems like quite a few other functions could be made with polynomial approximations, as long as the DSP use is ok. ill have a look tonight thanks!
User avatar
hifiboom
Posts: 2057
Joined: Thu Aug 03, 2006 4:00 pm
Location: Germany, Munich
Contact:

Post by hifiboom »

yes a lookup table would be a great atom
something I really really miss in sdk. (sync lookup table )

there is the waveshaper atom, but it just has 128 entries and is not really highest quality.
User avatar
Neutron
Posts: 2274
Joined: Sun Apr 29, 2001 4:00 pm
Location: Great white north eh
Contact:

Post by Neutron »

This is great!
The wave made by "approximation" looks a lot better than i thought it would after reading about that method.
Tests so far indicate it will work for what i want to do do!
Post Reply