Mathematical functions fit to polynomial expansions


#1

I think it would be nice to have more math functions into the library.
Since i don't have the knowledge to program such object but i know a bit of calculus i thought we could program some tables to do the work.

Trigonometric and hyperbolic functions

Arcsin: allocates a 16b table to sdram with size number of samples with an arcsine shape.
arcsin_t.axo (3.3 KB)

Arctan: allocates a 16b table to sdram with size number of samples with an arctan shape. The value attribute determines the x range of the function.
arctan_t.axo (3.9 KB)

Hyperbolic arcsine: allocates a 16b table to sdram with size number of samples with an inverse hyperbolic sine shape. The value attribute determines the x range of the function.
arcsinh_t.axo (3.8 KB)

Crossover functions

Hard crossover: allocates a 16b table to sdram with size number of samples with a hard crossover shape ( f(x)=0 for x€[-gap,gap], the function becomes linear outside that range). The value attribute determines the percent of the gap.
crossover_hard_t.axo (3.3 KB)

Parabolic crossover: allocates a 16b table to sdram with size number of samples with a parabolic crossover shape ( f(x)=x|x| for x€[-gap,gap], the function becomes linear outside that range). The value attribute determines the percent of the gap.
crossover_p_t.axo (3.3 KB)

Cubic crossover: allocates a 16b table to sdram with size number of samples with a cubic crossover shape ( f(x)=x^3 for x€[-gap,gap], the function becomes linear outside that range). The value attribute determines the percent of the gap.
crossover_c_t.axo (3.2 KB)

If anyone has the time/ the fancy (but also the knowledge!) to do some other functions help would be appreciated, just post the code here.


#2

for those of us who spent a lot of their life in remedial math (me), can you give a quick explanation of what this would be useful for??


#3

Functions (even the complicated ones like trigonometric ones) can be approximated in small regions with a polynomial expansion (a polynomial is a function like ax^2+bx+c, only with more terms, in the case of arcsin i did a 20th grade expansion).
You can find the coefficients for the polynomial with taylor's formula (or mclaurin, if you do it for x=0). Wolfram alpha can be used to find coefficients (i used it in fact), you could find other coefficients around the net, also, but you might not be able to find 20th grade expansions.

I then fit the polynomial to the axoloti range and voila. You can use it as a waveshape for distortion, or for lfos, or for math purposes. It's a table, you can use it in any way a table can be used (of course you should not overwrite it.

It might not be the most useful thing to have, but i think an axperienced user could find it handy


#4

playing around with both of these now, thanks for updating the thread.

what exactly does the "Size" in the alloc 16b refer to?


#5

Size refers to the number of elements in the table.
If you need a generic waveshaper maybe for k-rate operation i think you could use sizes down to 32-64.
If you need a waveshape for an oscillator to use with phasor instead i think you should go with higher values, like 256-512, the result will be crispier.

For distortion effects i'd use a higher size too.
The only downside in using these waveshaping method is aliasing, which can be quite prominent at high pitches.


#6

I have just added two crossover functions, just in case you want to do some transistor distortion emulation :wink:


#7

Big big big edit: i turned all that code into custom objects, to make them even more accessible :smiley:


Sputnki contributions