The spectral lines characteristic of hydrogen are spaced according to the Rydberg formula, $\displaystyle\frac{1}{\lambda} = R\left(\frac{1}{n_1^2} - \frac{1}{n_2^2}\right)$.

The wavelengths $\lambda$ given by the formula can be given as frequencies $\displaystyle f = \frac{c}{\lambda} = R\left(\frac{1}{n_1^2} - \frac{1}{n_2^2}\right)$ which can be rescaled into *musical* frequencies, which we will play. This has been done before, but I will give more attention to the science and musical perception and less attention to the programming.

## Play a pure tone

```
from IPython.display import Audio
from numpy import sin, pi
```

```
amplitude = 2**13
rate = 41000 # Hz
duration = 2.5 # seconds
time = np.linspace(0, duration, num=rate*duration)
def tone(freq):
return amplitude*sin(2*pi*freq*time)
```

As a test drive, let's just play a single pitch, Concert A.

```
A = 440 # frequency of Concert A
Audio(tone(A), rate=rate)
```

## Play the spectral lines

An "audible" Rydberg formula in Python:

```
scaling = 4*A # rescale the frequencies into an audible range
def freq(n1, n2):
return scaling*(1./n1**2 - 1./n2**2)
```

Generate a spectrum of frequencies for $n_1 = 1, 2, 3$, corresponding to the yellow, black, and maroon lines in the illustration above. Verify that the lowest and highest frequencies are within the audible range of 20-20,000 Hz.

```
series = [1, 2, 3] # Lyman, Balmer, Paschen series
spectrum = [freq(n1, n2) for n1 in series for n2 in range(n1 + 1, 9)]
min(spectrum), max(spectrum)
tones = [tone(f) for f in spectrum]
composite_tone = np.sum(tones, axis=0)
```

Listen.

```
Audio(composite_tone, rate=rate)
```

The sound is eerie and disssonant, but more musical than one might expect. Why?

Most natural sounds, especially musical ones, consist of several frequencies (i.e., pitches) related to each other by the *harmonic series*: $\frac{1}{2}, \frac{1}{3}, \frac{1}{4}, \frac{1}{5}$, etc. Our brains usually group tones related by the harmonic series together, interpreting them as part of the same sound. Further, we perceive the differences between these frequencies as *beating*, a pulsing sensation that is particularly obvious when two tones are almost but not quite in unison.

Each tone in the sound above corresponds exactly to one of beating patterns. The Rydberg formula takes the difference between two fractions from the harmonic series. (To be specific, the fractions are from the series $\frac{1}{2}, \frac{1}{4}, \frac{1}{9}$ …, a subset of the harmonic series.)

Although the spectrum of hydrogen is unrelated to music or acoustics, it happens to follow a pattern that also occurs is musical sound, and so it makes more sense to our ears than random tones or noise.