Listening to data

Copyright 2014 by Evans M. Harrell II

Graph it or play it?

Descartes taught us that an arbitrary function can be understood geometrically as a graph, relating points to pairs of coordinates.  However, any such graph could also be perceived by the ear rather than the eye, if vertical axis is replaced by the relative pressure of a sound wave in air.  In Mathematica, the syntax is almost identical for auditory as for visual display:

Plot[BesselJ[0,2*Pi*440   t],{t,0.1,3}]

Before playing this sound, let’s zoom in:

Plot[BesselJ[0,2*Pi*440   t],{t,1,1.1}]

Play[BesselJ[0,2*Pi*440   t],{t,0.1,3}]

Detecting patterns in sound

The ear picks out patterns in a different way than the eye.  Usually, the sound of a regular pattern is pleasing, whereas chaos is dischordant.  Your mind likes sounds related by rational numbers, and the lower the denominator, the better.

Let’s compare, for example, a sine wave, combinations of a few sine waves, and the sound of random data:

ListPlay[Table[2 Cos[440 t],{t,8000}]]

If we add overtones - integer multiples k times the basic frequency - the sound is richer.

ListPlay[Table[Sum[Cos[440 k t]/k^2, {k, 1, 9}] ,{t,8000}]]

The notes in the 12-note chromatic scale are at logarithmically equal intervals, and the major chords are triples of notes that are nearly in rational multiples with low denominators 4 and 2:

{N[2^(4/12)],N[2^(7/12)]}

Sound[{Play[Sin[ Pi 523 t ],{t,0,1}],Play[Sin[ Pi 659 t ],{t,0,1}],Play[Cos[Pi 784 t ],{t,0,1}], Play[Sin[ Pi 523 t ]+Sin[ Pi 659  t ]+Cos[Pi 784  t ],{t,0,2}]}]

Sound[{Play[Sin[ Pi 523 t ],{t,0,1}],Play[Sin[ Pi 523 2^(1/3)  t ],{t,0,1}],Play[Cos[Pi 523 2^(7/12)  t ],{t,0,1}], Play[Sin[ Pi 523 t ]+Sin[ Pi 523 2^(1/3)  t ]+Cos[Pi 523 2^(7/12)  t ],{t,0,2}]}]

{1,N[2^(2/12)],N[2^(4/12)],N[2^(5/12)],N[2^(7/12)],N[2^(9/12)],N[2^(11/12)]}

Compare to numbers with denominators {1,9,4,3,2,3,9}:

{1,N[10/9],N[5/4],N[4/3],N[3/2],N[5/3],N[17/9]}

You don’t find the combination C-D-B very often, with those denominators of 9:

Sound[{Play[Sin[ Pi 523 t ],{t,0,1}],Play[Sin[ Pi 523 2^(2/12)  t ],{t,0,1}],Play[Cos[Pi 523 2^(11/12)  t ],{t,0,1}],Play[Sin[ Pi 523 t ]+Sin[ Pi 523 2^(2/12)  t ]+Cos[Pi 523 2^(11/12)  t ],{t,0,2}]}]

Compare major chord to a triple of notes with irrational ratios:

Sound[{Play[Sin[ Pi 523 t ],{t,0,1}],Play[Sin[ Pi 523 (Sqrt[5]-1)  t ],{t,0,1}],Play[Cos[Pi 523 Sqrt[2]  t ],{t,0,1}],Play[Sin[ Pi 523 t ]+Sin[ Pi 523 (Sqrt[5]-1)  t ]+Cos[Pi 523 Sqrt[2 ] t ],{t,0,2}]}]

The two-tone combination C F#, with a ratio of 2^(1/2) is known as the “diabolic tritone.”

Sound[{Play[Sin[ Pi 523 t ],{t,0,1}],Play[Sin[ Pi 523 Sqrt[2]  t ],{t,0,1}],Play[Sin[ Pi 523 t ]+Sin[ Pi 523 Sqrt[2]  t ],{t,0,2}]}]

Similar but not quite matching frequencies “beat”:

Play[Sin[2500 t]+Sin[2520 t],{t,0,2}]

Play[Sin[2500 t]+Sin[2520 t] +Sin[2540 t],{t,0,2}]

ListPlot[RandomReal[100, {8000}]]

ListPlay[RandomReal[100, {16000}]]

How do different dimensions sound?

1D

The normal modes in one-dimension are the wave forms of a vibrating string.  Assuming that the end points are fixed, the sine function must vanish at both ends, which means that the frequency is an integer multiple of a fixed value:

Plot[{Sin[t], Sin[2t], Sin[3 t], Sin[4 t], sin[5 t]}, {t, 0, Pi}]

2D

As representative cases, we could consider a square and a disk.  The eigenfunctions of the Laplace operator on a unit square (again, 0 on the boundary) are of the form Sin[j π x] Sin[k π y], so the eigenvalues are of the form (j^2+k^2) π^2, and the frequencies are therefore (j^2+k^2)^(1/2) π/c.  

Notice that because of the square root, except in very special circumstances (like comparing (j,k) and (2j, 2k)), the ratios of different frequencies are irrational.

Counting eigenvalues and exstimating the m-th frequency.

Up to a factor, the frequency corresponding to integers (j,k) is the distance from the origin of a point with two positive integer coordinates.  How many such frequencies will there be up to a given value (radius) f?

ANSWER

Approximately, #[≤f] = π f^2 /4.  Why? 

Inverting this function, we see that the m-th frequency is approximately (4 m/π)^(1/2), up to a constant involving the characteristic speed and the volume of the square.

The case of arbitrary rectangles works a lot like that of the square.  In fact, for the high frequencies, the shape doesn’t matter much.  Hence the Weyl law that f_m ~ C (m/A)^1/2

The normal modes for the disk, by the way, are of the form 
          e^(2πi j) J_k( cst r),
 where the functions J are the Bessel functions, and the possible constants that make the solutions vanish at the perimeter of the disk are the frequencies of the normal mode, up to constants.  The Bessel functions resemble sine functions times a decaying factor, but the possible frequencies are simply not in rational ratios.

To listen to the vibrating drum, we take sines of cosines of these numbers times t (and times physical and scale factors).

N[Table[BesselJZero[j,k], {j, 0, 3}, {k, 1, 5}]]

Sound[{Play[Sin[ 100Pi * 2.404825557695773 t ],{t,0,1}],Play[Sin[ 100Pi * 3.831705970207512 t ],{t,0,1}],Play[Sin[ 100Pi * 5.5200781102863115 t ],{t,0,1}],Play[Sin[ 100Pi * 8.41724414039981 t ],{t,0,1}], Play[Sin[ 100Pi * 2.404825557695773 t ]+Sin[ 100Pi * 3.831705970207512 t ]+Sin[ 100Pi * 5.5200781102863115 t ]+Sin[ 100Pi * 8.41724414039981 t ],{t,0,2}]}]

Those were the basic tones.  What really happens is that the tones damp out:

Play[4 (E^(-t)Sin[ 100Pi * 2.404825557695773 t ]+E^(-2t)Sin[ 100Pi * 3.831705970207512 t ]+E^(-5t)Sin[ 100Pi * 5.5200781102863115 t ]+E^(-8t)Sin[ 100Pi * 8.41724414039981 t ]),{t,0,2}]

Some more examples, including a square drum.

ListPlay[Table[E^(-t/2000)Sum[(Cos[40 BesselJZero[0,k]  t]+ .5 Sin[40 BesselJZero[1,k]  t])/k^2, {k, 1, 5}] ,{t,2000}]]

ListPlay[Table[Sum[E^(-t k/2000)(Cos[20 BesselJZero[0,k]  t]+ E^(-t k/2000).5 Sin[20 BesselJZero[1,k]  t])/k^2, {k, 1, 5}] ,{t,2000}]]

Play[4 (E^(-t)Sin[ 100Pi * Sqrt[2] t ]+E^(-2t)Sin[ 100Pi * Sqrt[5] t ]+E^(-3t)Sin[ 100Pi * Sqrt[8] t ]+E^(-4t)Sin[ 100Pi * Sqrt[10] t ] +E^(-5t)Sin[ 100Pi * Sqrt[13] t ]),{t,0,2}]

n D

It’s more like 2D than like 1D.  To count eigenvalues for the hypercube you need to look at n-tuples of positive integers, and the frequencies ar ethe square roots of the sums of squares.  When you again think of this as a distance from the origin, you end up measuring the volume of a fraction of a sphere.  At the end of the day you get the Weyl law,
       f_m ~ C_n (m/Vol)^(1/n).

This is best known of the statistical laws for the distribution of eigenvalues, and it means that a mathematician can hear the dimension of a musical instrument.