# Simple equations that produce melodies?

I've previously seen simple equations that produce beautiful, complex shapes:

Is there an equivalent for music? I.e. a simple equation $$A(t)$$ that, when played as a sound, will produce a melody?

Or failing that, something in the Fourier domain that produces a surprisingly complex or beautiful melody with a simple equation?

I am trying to find a beautiful default for a little open-source utility I wrote that plays an equation as audio.

### How functions can be interpreted as music

You can represent music by modeling it as a function, amplitude, with respect to time. More often it is modeled as two functions, one for each ear, i.e. stereo. These functions can be graphed just as any other function can:

Now this is discrete (sampled around 48,000Hz), but can be approximated by a continuous function. So we can perform operations on it. For example, you can use the FFT to approximate a Fourier transform.

Unfortunately, because this function is a discrete function comprising millions of datapoints, it can not be written compactly. Just in the same way that the beautiful image at the top of the page is not compact if you represent it as pixel data, yet is compact if you look at the mathematical function that generates that data.

### Prototype

This is a proof of concept that you can make melodies with fairly simple equations:

\begin{align*} &\sin(440 \cdot 2 \pi t) \exp(-(t-1.1)^2 e^{(t-1.1)^2}) \\ + &\sin(554.365 \cdot 2 \pi t) \exp(-(t-3.0)^2 e^{(t-3.0)^2}) \\ + &\sin(659.225 \cdot 2 \pi t) \exp(-(t-4.9)^2 e^{(t-4.9)^2}) \end{align*}

It is somewhat ugly as it just combines the bump function with sinusoids to create an A-major arpeggio: A, C♯, E. The principle is that the function is varying in frequency and amplitude, and it's amplitude peaks when it hits pleasant frequencies.

I'm looking for a more natural version of this. Something similar to the equation at the top of this page that produces the surprisingly complex and beautiful image.

Hear it played as audio.

Here's a Desmos graph of the first couple of bump functions I used if you want to play around with this. You then just multiply the bump function by the periodic function you want. You can change the delay of each one by changing $$2.9$$ to the delay you want. Each bump function lasts about 2 seconds, but you can change the width and shape by playing around with bump the function.

• How do you play an equation as a sound? What does $t^2$ sound like? Commented May 20, 2023 at 1:36
• @GerryMyerson It has to have some periodic component to be audible. Check out equation audio to see what I mean.
– Zaz
Commented May 20, 2023 at 1:41
• OK, so, a function of the form $y=A\sin(Bt+C)$ gets interpreted as a single note of a particular pitch and loudness. Any periodic function can be written as a sum of sines and cosines (a Fourier series) so interpreted as a chord, a bunch of simultaneous notes. Not clear to me how you get a tune out of that. It would be helpful if you would explain in the body of your question how a function gets interpreted as music. Commented May 20, 2023 at 1:58
• I'll try to make a prototype of what I'm describing. But the proof that it's possible is that uncompressed audio files are time series of amplitude values.
– Zaz
Commented May 20, 2023 at 2:43
Here's a neat example: .2 sin((2000 pi + 10 sin(100 pi t)) t). I expected this to be a steady FM tone (a 1000 Hz wave, frequency-modulated by a 50 Hz wave), but I made a mistake: varying the frequency term also changes the instantaneous phase, and this phase error is proportional to the amount of time that has passed. It's clearer to view this as phase modulation: .2 sin(2000 pi t + 10 t sin(100 pi t)); if you remove the $$t$$ factor from the modulation amplitude, you get the expected steady tone.