A first approach to physical modelling


#21

I tried to get a little bit into that. You wrote about a spring mass solutionen. So what is the difference between your chaotic oscillator and a harmonic oscillator. As far as I know a harmonic oscillator is based on a spring mass system like described here (http://www.ryanjuckett.com/programming/damped-springs/)

Also nice is this description about modelling and instruments:

http://www.icacommission.org/Proceedings/ICA2001Rome/8_05.pdf


#22

Yeah, the idea was to build a chaotic oscillator, but actually a spring-mass system (even with two springs and two masses) is a harmonic oscillator.

A truly chaotic oscillator would be the double pendulum, however i felt the need to try something simpler before moving to that (because a double pendulum involves forces directed in two dimensions) and i still don't have proper padronance of trig functions.

What i did was more of a resonator (a sufficiently long chain of such objects with a working friction implementation could model a spring reverb).

Now, the problem is that i don't have a background in low-level programming, i'm improvising and surfing on the notions i learned on some courses in this semester (notions of numeric calculus and analytical mechanics).

The problem is that making the stuff work for a microcontroller involves using a limited set of instructions and optimizing the hell out of the code. (that's a lot of stuff!)

I recently got some ideas to overcome the integration problem (basically using a more refined method than euler's (which suffers heavily of rounding errors) like the midpoint method, see https://en.wikipedia.org/wiki/Euler_method for some insight) . I've read Johannes implemented runge-kutta integration for some object (i can't remember which one, though)


#23

Well this might help you:

http://www.codeforge.com/article/212966


#24

@johannes @Sputnki

I'm wondering if somebody tried to use matlab to generate code for the axoloti objects and how it works. Matlab has a code generator which can generate optimized code for the ARM Cortex M4. Might be easier to start with complex physical structures. At least it would be a good idea having complex physical calculation function within a lib.


#25

They're in the 1.0.10 community library: patches/jt/devel/filter-4pole-v2.axp, contains both a floating point and fixed point adaptation of Miller Puckette's Runge-Kutta 4-pole filter for comparison. Still work in progress, I think generally it sounds fine to my ears, but there is an upper limit on the cutoff frequency beyond which it is completely unstable. The cutoff frequency limit can be extended by "double pumping" the filter. To get it towards release I think the best approach is to make 2 separate objects, one "cheap" single iteration version with limited cutoff frequency, one more expensive double pumped version.

@Karpo72 I don't have a Matlab license, and I believe it's quite expensive.
Perhaps an alternative path is generating axoloti objects with Faust. @pierstitus has experience with Faust and made a Cortex M4 backend. There has been some discussion on this forum about generating axoloti objects from Faust, but I do not know the actual status of those efforts.


#26

test.axo (619.6 KB)

Hey found some c examples that were generated with mathlab...sorry to tricking that forum, but it is a zip file. Rename it to zip. I'm not sure why it is not allowed to upload zip files. The zip contains just public example code.It should run on ARM Cortex M4. Perhaps there are some pieces of code that are interesting for you.

@Sputnki by the way I have read now a lot of papers about a possible solution and compared also some tests with different solvers. If it is suitable you should look for a ode45 implementation. I guess that would be the best solution for the CPU


#27

Zip files could contain malware, copyrighted or inappropriate content. I'll tolerate this one for once... Hosting it somewhere else and linking to it is preferred.


#28

Really cool examples, thanks! I really need to learn simulink, it's so powerful.

I'm curious however, is that code directly usable in axoloti?
I mean, yes it's c, but aren't there external libs in the examples?


#29

Generating Axoloti objects from Faust would be nice indeed. In this case especially when combined with Synth-a-Modeler, a physical modelling framework built on Faust. See http://computermusic.us/samdesigner/

Faust does everything as float, which works fine for me on STM32F4, you just should be careful not to use any math function calls, as they are very costly, and also divides and square roots take 14 cycles versus 3 cycles for multiplication and 1 cycle for addition/subtraction.


#30

To tell you the truth I didn't step to deep in it. I think you know much more than me about it. I just try to support you somehow because physical modelling is quite a interesting function. It would be nice if we would find a solution to have some sort of harmonic oscillator, bowed string simulation, string hammer simulation, picked string simulation. I just read a project about piano http://www.acoustics.ed.ac.uk/wp-content/uploads/AMT_MSc_FinalProjects/2012__Teng__AMT_MSc_FinalProject_PianoSynthesis.pdf.

The guy implemented it in matlab. I ask a friend if it is possible to generate code from this experiment. But it uses to functions wihich don't allow code conversion out of the box http://de.mathworks.com/help/control/ref/tf.html http://de.mathworks.com/help/control/ref/tfdata.html. These functions seem to be a critical point within the script, because they need to be implemented very carefull because of cpu usage. There are possible ways to implement a Transfer Function :left_right_arrow: State Space function.

The script contains also a line which generates a error -> v=F/(2*R0); It seems that he make a division on a matrix, but v should be a verctor to process the data. Actually I wrote the guy if he may like to help and pointed him also on the axoloti project :wink:


#31

Yes, matlab works with matrix data types (which are not directly available in axoloti).
I can see a problem here: if you want to do 1-dimensional modeling, that's fine (because you have to calculate integrals in only one dimension).That might be the case for springs (or strings, if you want).
If instead you wish to model something like a plate (which is a 2-dimensional object), that brings in the need to calculate integrals in multidimensional space, which probably requires a jacobian matrix, and that goes way over my skills, both math and programming. I also think some more advanced trig functions are needed (like inverse functions, at least an arctan)

I see you're really interested in seeing something come out of my experiments, i promise i'll get back to this when i finish my current project!


#32

Hey have some input about the transfer function.... take a look at this generated code files, perhaps it helps:

https://drive.google.com/open?id=0B16rrKKNzh9WQjBvd3h0aERSUU0

@johannes I#ve learnd..the zip is now somewhere else :wink:


#33

I think the CMSIS library has both vector and matrix support, which should be available to you custom objects.

a|x


#34

I see. Does sombody ever tried this lib with axoloti object? Seems to have a lot of complex calculations.


#35

I lack the mathematical background to make sense of the functions, unfortunately.

a|x


#36

@Sputnki Would you please take a look at this example? https://drive.google.com/open?id=0B16rrKKNzh9WT3g4RTg1dGNPc3c


#37

Dammit, now I really want an axoloti, physical modeling in a standalone box has been one of my main interests in these open-ended software boxes. Had high hopes using aleph but developing code for that seems too hard..

Using matrices will always be computationally useful, even if you're just dealing in one dimension since then you can interpolate between parallel computations.


#38

@bafonso I've found an matlab example for a harmonic oscillator. I generated the code, but it uses it own defined data types, because of a generic code generation. Until now I didn't had time to step into the axoloti development. But if you like, it should'nt be not a problem to change the code and make it run. I think the first step might be a harmonic oscillator. It might take some weeks until I'mprepared to try my own development. Just take a look. I guess if you've some experience you could implement an axoloti object within some hours.

https://drive.google.com/open?id=0B16rrKKNzh9WTXdXZFJuN1IyX1E

By the way the ode45 implementation should work within the first step. It would be interesting to test the performance on the axoloti. As far as I know it is some kind of runge kutta implementation which is not very accurate, but perhaps fast enough in the calculation. As far I know it implents some values about error tolerance.

Steps to take: Make it run, test performance, optimizing :wink: I guess also @Sputnki has nothing against some help :wink: I compiled c++ files, if needed I can also generate c code. Perhaps it would be a good idea to seperate the ode45 function later in some kind of a own math function to give other developer the chance to reuse it.

The example has two outputs. If not needed I can remove one output. The v output is the velocity wave. It wasn't used in the example, but I wasn't shure if it may be needed.


#39

@Sputnki Hey I tried to get a overview about creating axoloti objects. It uses C operators but is it also C? Or is it some kind of own code implementation. What if I've a complex code? Are there any examples working with complex code? Or has every complex function to be included in the firmware? I.e: The harmonic oscillator would be a implementation within the firmware?


#40

Objects are coded in C/C++.

a|x