Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: brownian motion in harmonic/other potential #41

Open
glocke01 opened this issue Mar 1, 2024 · 7 comments
Open

request: brownian motion in harmonic/other potential #41

glocke01 opened this issue Mar 1, 2024 · 7 comments

Comments

@glocke01
Copy link

glocke01 commented Mar 1, 2024

Hi. Fellow physics+audio nerd.

I'd love to see a smooth-random LFO module based on simple Brownian motion. Basically, add a random nudge at regular (or exponentially distributed intervals) with, say, normal magnitude and uniformly distributed angle. Then just simulated orbit around a harmonic potential. Parameters would be potential strength and nudge strength. Additional possibilities include damping terms, nudge-on-trigger, inputs that insert force, bias in nudge angle (prefer tangential motion), non-trivial potentials, e.g. bistable.

Alternatively, simple brownian motion with no potential (with/without damping) on periodic boundary conditions would also be interesting. (or periodic boundary conditions and periodic potential, etc. etc..)

Best,
George

@cosinekitty
Copy link
Owner

Very interesting! I like the idea of combining Brownian motion with a potential field. Without the field, the particle can just wander arbitrarily far away from the origin, which would probably not be very useful to people. I'm assuming that there is an inward force that gets stronger as the particle tries to leave the scene?

I'm not sure I know what you mean about periodic boundary conditions... can you explain that more?

I love the idea of a bistable (or tri, quad, ...?) potential field.

This idea does fit in well with my recent interest in 3D vector generators (Frolic, Glee, Hiss).

@glocke01
Copy link
Author

glocke01 commented Mar 5, 2024

Without the field, the particle can just wander arbitrarily far away from the origin, which would probably not be very useful to people.

The simplest solution, what's implemented by BogAudio Walk, is to just bounce against the boundary. (Walk is the simplest kind of Brownian motion with random displacements and no momentum, what you'd get in the limit with zero potential and infinite damping.)

I'm assuming that there is an inward force that gets stronger as the particle tries to leave the scene?

A "spherical harmonic potential" goes as |r|^2 leading to a recovery force of -r. Diffusion in this potential leads to a spherical bell curve. You'd probably want some way to prevent CV outputs larger than +-10V, which could be clipping, bouncing, or you could use another potential that created an infinite barrier, e.g. 1/cos(r).

I'm not sure I know what you mean about periodic boundary conditions... can you explain that more?

Like a portal connecting -10V to +10V, "wrapping" the ends together. It effectively simulates an infinite space when the potential field is periodic, like a crystal structure, or just absent (e.g. cosmological N-body simulations).

I got a Ph.D. doing stat mech years ago, and many of these ideas remain half-baked in my head.... This kind of motion is evidently known as Langevin dynamics and I'm sure you can find Monte Carlo code without too much trouble.

@cosinekitty
Copy link
Owner

I'm still thinking about this. What do you think about the following? I could think of Brownian motion as the result of constant random force vectors acting on a particle. Divide force by (adjustable) particle mass to get an acceleration vector. Integrate to get velocity, again to get position. Essentially the double integral acts as a low-pass filter.

Then we add on a friction damping coefficient (adjustable decay).

When I think of it this way, I wonder if it makes sense to have a generic particle module that accepts a force vector input. Then we just use the Hiss module I just released to provide the directionally unbiased random vectors. Or maybe that's what we always want, so the equivalent of Hiss is already built in?

I'm still thinking about using a potential well to sort-of confine the particle to a reasonable radius of the origin. It's basically a combination of inward attraction with at least a tiny amount of friction for damping.

@cosinekitty
Copy link
Owner

A little expansion ...

generic particle module that accepts a force vector input

What I'm thinking about is the possibility of a separate module that does the adjustable double-integral as a filter for any 3D vector input. This follows what I'm affectionately calling the Vector Manifesto. The idea is, if physical simulations can lead to interesting sounds, and physical systems are all about vectors, matrices, etc., why not make a collection of synth modules that operate in the 3D vector/matrix world?

Frolic, Glee, Hiss, and Polynucleus are all heading that direction where I represent 3D vector streams as 3-channel polymorphic cables. I will likewise use 9-channel cables to represent rotation matrices in some future module(s).

Anyway, if you have Hiss, and you have this other hypothetical filter module, they can be chained to make essentially a Brownian motion generator. I have already dealt many times with the maddening constraint that a simulation must not diverge into NAN/infinity. It's too much to go into right now, but I think keeping it within 10V is certainly possible using some slight departures from real physics.

@glocke01
Copy link
Author

Frolic, Glee, Hiss, and Polynucleus are all heading that direction where I represent 3D vector streams as 3-channel polymorphic cables.

How much harder does the code get if the number of dimensions is parameterized? There are certain processes that don't behave right in less than 3 dimensions (e.g. no bounded, continuous chaos in <3D), but many can be generalized upward.

One problem with "overloading" polyphony to handle module-specific tasks is that it locks the user into a certain number of polyphony channels. If the modules are capable of handling higher dimensions, then they become more flexible. (Whatever, I can imagine computation time going as D^2, and handling a fixed 3D is probably already a handful as far as your development time is concerned.)

I will likewise use 9-channel cables to represent rotation matrices in some future module(s).

IDK if this is useful or new information but: a matrix representing 3D "rotation" is fully specified by three parameters. https://en.wikipedia.org/wiki/Rotation_matrix

Of course, you may wish to include all 3x3 elements of the matrix for full generality/future-proofing.

Anyway, if you have Hiss, and you have this other hypothetical filter module, they can be chained to make essentially a Brownian motion generator.

This makes sense. In the simplest case, a noise input would add a random force. I think properly implemented boundary conditions (e.g. what to do at +-10V and maybe a max speed) in the "double integrator" would handle any force input in principle.

I think keeping it within 10V is certainly possible using some slight departures from real physics.

A ball bouncing against a wall is effectively hitting an "infinite potential barrier". I don't think the physics police are going to bust down your door if you cut some corners :)

@cosinekitty
Copy link
Owner

cosinekitty commented Mar 14, 2024

How much harder does the code get if the number of dimensions is parameterized? There are certain processes that don't behave right in less than 3 dimensions (e.g. no bounded, continuous chaos in <3D), but many can be generalized upward.

Inside Nucleus/Polynucleus and Elastika, I use SIMD instructions to streamline floating point calculations. That means I can perform the same arithmetic operation (+, -, *, /) on 4 pairs of real numbers simultaneously to obtain 4 results. I use SIMD for adding and subtracting vectors, and for the multiplication part of a vector dot product (adding the products can't be done with SIMD and is slower). So I could go from 3D to 4D trivially in some places.

However, there is no way to use SIMD to speed up cross products. I have to do that the old fashioned way, one operation at a time.

Hiss defaults to generating 3D vectors, but you can change the dimensionality to any value from 1..16 in the right-click menu. Hiss doesn't use SIMD; I just keep generating normally distributed random numbers for the requested number of dimensions.

I have studied the code for some of the polyphonic VCV Rack Fundamental modules, including VCV VCO. They tend to round up the requested number of channels to the next multiple of 4 and use SIMD as much as possible. I think that's probably the best combination of efficiency and user flexibility for situations where the channels are completely independent.

I think in my case, I'm mostly interested in 3D vectors because I'm following the notion of creating mechanical simulations that produce sounds, and it is difficult to generalize cross products to higher dimensions. In fact, I'm not even sure it's possible! (I'll have to look that up; never thought about it before...)

As far as a brownian motion generator, I can easily see that scaling up to 16D, so long as the user accepts the required CPU burden.

I don't think the physics police are going to bust down your door if you cut some corners :)

LOL, don't be so sure! In Nucleus/Polynucleus I have a very strange relationship between velocity and position. Instead of integrating velocity to get position, I run the velocity magnitude through a bicubic limiter, then integrate that result. It's a nonlinear transform a little like Einstein's special relativistic postulates that there be a fastest possible speed, but not like the one in the real world...

$$\gamma = \sqrt {\frac {1} {1 - \frac{v^2}{c^2}}}$$

Instead, mine gradually flattens out as you reach the maximum speed.

@cosinekitty
Copy link
Owner

Incidentally, I'm also interested in making sounds based on the frequency spectra of black body radiators. Using Planck's Law, I imagine creating a frequency filter that matches that curve, only with wavelengths/frequencies reinterpreted at audible ranges instead of optical.

I would also want to scale the amplitude to keep a fixed peak, but allow the user to change the temperature with a knob. In real life, blue stars put out a lot more light than red stars, but I would have them both put out the same amount of light while keeping their respective spectrum shapes.

What do you think about this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants