Chaotic Systems for Musical Parameters

I'm composing a movement for string quartet using algorithms and I've used Perlin noise to create continuous change in a natural, smooth, and unpredictable way. I'm not quite satisfied: as much of a miracle Perlin noise is, there is something for me that is lacking musically. Noise used for procedural generation relies on random or pseudo-random values, which are sampled directly (value noise) or used as gradients to generate values (gradient noise). The randomness is not really continuous: it is the means of sampling that makes Perlin noise continuous.

I want continuous unpredictability, but I want continuity and surprise to come from the same source. The best sources I've found for this kind of continuity are chaotic dynamic systems.

Chaotic Dynamic Systems

Chaos theory is well known and others have explained it well. Simple English Wikipedia does well for a brief explanation and the book by Steven Strogatz is good for a more in depth introduction. In brief, chaotic dynamic systems are mathematical systems that change over time in ways that are patterned, but these patterns can be surprisingly complex. Further, small changes in these systems may result in large changes to the patterns produced over time.

The Lorenz system is the original and most famous of these systems, but I am more drawn to the Thomas attractor (after Réne Thomas, the mathematician) for a number of reasons. For one, the equation for the system is very simple:

$$\begin{cases} \frac{dx}{dt} = \sin{y} - bx \\ \frac{dy}{dt} = \sin{z} - by \\ \frac{dz}{dt} = \sin{x} - bz \end{cases} $$

The visual appearance of the Thomas attractor varies more, with more curves and a more subtle appearance.

A demonstration of the visual differences between the Lorenz and Thomas attractors
The Lorenz attractor (left) and the Thomas attractor (right) visualized using a Python attractors library

I am also fascinated by what happens when the parameter \(b\) approaches zero. An unpredictable drift emerges:

The Thomas attractor simulated with b=0.09 and b=0.01
The Thomas attractor simulated with \(b=0.09\) (left) and \(b=0.01\) (right)

Sonification of the Thomas Attractor

What may not be apparent from the above graphics is that the images are in three dimensions. The Thomas attractor, for example, use the dimension x, y, and z. The values of the attractor in each of the three dimensions can be plotted as separate line plots.

This can be mapped to anything. It is tempting to map this to pitch, but it is important to try to resist that immediate temptation, as there are other elements of music. Here, however, we will yield to that temptation. Here, two virtual violins and a virtual cello have their pitch mapped to the value of the attractor:

audio-thumbnail
String trio using the Thomas attractor
0:00
/60

Pay careful attention to how the changes in pitch have a pattern, but the pattern never repeats exactly.

Attractors with more than three dimensions

As stated, I am working on a string quartet, making three dimensional attractors insufficient. We could deploy multiple attractors with slightly different parameters, but I require something more unified. Wikipedia's list of chaotic maps highlights a problem here: most chaotic maps have only three dimensions. This tradition is highlighted by the attractors library used for the above simulations in that it requires three dimensions for every attractor:

    if len(coord) != 3:
        raise ValueError("State vector must have length 3")

attractors library requires three dimensions

One exceptional attractor that does not require three dimensions is "Lorenz 96". It is defined by this formula:

$$
\frac{dx_i}{dt}=(x_{i+1}-x_{i-2})x_{i-1}+x_i+F
$$

Two things are interesting here. First, this attractor permits an arbitrary number of dimensions (where the current value of the subsequent dimension is specified by \(x_{i+n}\). Second, is that there is a non-linear relationship between dimensions. (Non-linearities are a requirement for chaos; the non-linearity in the Thomas attractor is expressed by the sine function.)

I haven't encountered this elsewhere, but it is possible to express the Thomas attractor in terms of its relationship to the next dimension, using the notation above:

$$\frac{dx_i}{dt}=\sin(x_{i+1}) + bx_i$$

With some help from an artificially intelligent colleague, we developed this code to simulate this attractor:

@jit(nopython=True)
def compute_derivative(state, b):
    N = len(state)

    dxdt = np.zeros_like(state)
    for i in range(N):
        x_i1 = state[(i+1) % N]
        dxdt[i] = np.sin(x_i1) - state[i]*b
    return dxdt

@jit(nopython=True)
def multidim_thomas_step(x, b, dt):
    
    # RK4 integration
    k1 = compute_derivative(x, b)
    k2 = compute_derivative(x + dt * k1 / 2, b)
    k3 = compute_derivative(x + dt * k2 / 2, b)
    k4 = compute_derivative(x + dt * k3, b)
    
    return x + dt * (k1 + 2 * k2 + 2 * k3 + k4) / 6

And here are the results with 6 dimensions, \(b=0.208\):

A graph of a Thomas attractor extended to six dimensions
A "Thomas attractor" with 6 dimensions

Importantly, I am not expert enough in Chaos Theory to be able to state whether the equations are still well poised or whether this actually comprises a chaotic system, or what the Lyapunov exponent is, and so on. I'm more interested in the musical applications of these systems.

Musical Application of a High Dimensional Thomas-like attractor

As stated earlier, I am composing a movement for string quartet that uses Perlin noise to vary different parameters for a physical model of string instruments. Rather than using pseudo-random noise, I would like something patterned, but still unpredictable. Here are some results of substituting Perlin noise with the modified Thomas attractor above.

As a reminder, here is the original composition that employs Perlin noise.

audio-thumbnail
Perlin Noise and Prime Durations
0:00
/130

Here is the same composition that uses a system like a Thomas Attractor:

audio-thumbnail
Thomas Type System
0:00
/131.064

The immediate difference here is that the pitch range is larger for the Thomas system. This is simply due to the Thomas system utilizing a larger part of its range, even when scaled between 0 and 1. Here is the same composition with the range scaled to 0.3 and 0.7, which seemed to be the range of my Perlin noise generator.

audio-thumbnail
Thomas Type System - Scaled Range
0:00
/131.76

Although from a superficial standpoint, these two sound very similar, I prefer the Thomas System because it seems as if the trajectory for each dimension is tied to the other. Perlin Noise seems to drift unaware from value to value, like the clouds it so expertly reproduces.

Recently, I released a track to uses this kind of attractor to automate musical parameters. Here is a virtual double bass duet that utilizes this parameter automation with slightly different initial conditions to turn a simple melody into a blooming soundscape:

Interstice I - for Synthetic Double Bass Duet, by florilegium mathematica sonus
from the album Kittens

A Thomas Attractor Max for Live Device

I made a Max for Live device that simulates a Thomas Attractor:

A Max for Live Thomas Attractor

This is my first attempt at distributing a M4L device, so I cannot guarantee the relative usefulness of this device. The main limitation I see is that because this uses a chaotic oscillator, it is extremely difficult to ensure that the simulation happens the same on every playback if playback (or rendering) happens in the middle. Also, the attractor may need to be reinitialized at the beginning of a Live set using parameter automation.

Anyway, this was all fun to make. Here is the device: