Skip to content

homeymusic/mami.codi.beaty.R

Repository files navigation

MaMi.CoDi.Beaty: A Model of Harmony Perception

The Behavioral Data

Manipulating Harmonic Frequencies

Harmonic ~ Partials: 10









Stretched ~ Partials: 10









Compressed ~ Partials: 10









Bonang ~ Partials: 4









5Partials ~ Partials: 5









5PartialsDoubled ~ Partials: 5









5PartialsNo3 ~ Partials: 5









Pure ~ Partials: 1









M3 ~ Partials: 10









M6 ~ Partials: 10









P8 ~ Partials: 10









m3 ~ Partials: 10









m6 ~ Partials: 10









P1 ~ Partials: 10









ExtraStretched ~ Partials: 10

p= 2.64







ExtraCompressed ~ Partials: 10

p= 1.52







2PartialsDoubled ~ Partials: 2









Fourier uncertainty principle in number‑theoretic form matches musical consonance perception

Heisenberg Uncertainty

$$ \boxed{\Delta x \Delta p \ge \frac{\hbar}{2}, \quad \lambda = \frac{h}{p}} $$

When de Broglie gave matter a wavelength, did he give us a pattern recognition problem?

Gabor Uncertainty

“Each of these areas, with its associated datum, represents, as it were, one elementary quantum of information, and it is proposed to call it a logon.” -Gabor, 1944

“…phase-space is subdivided in quantum blobs…” -de Gasson, 2002

$$ \boxed{\Delta t \Delta \omega \ge \frac{1}{2}} $$

Relative Uncertainty

Reference Time Period

$$ \Delta t = \tau T_{ref} = \tau \frac{2 \pi }{\omega_{ref}}, \quad \tau \enspace \text{periods} $$

$$ \tau \frac{2 \pi}{\omega_{ref}}\Delta \omega \ge \frac{1}{2} $$

Relative Frequency Uncertainty

$$ \frac{\Delta \omega}{\omega_{ref}} \ge \frac{1}{4 \pi \tau} $$

$$ \boxed { \frac{\Delta f}{f_{ref}} \ge \frac{1}{4 \pi \tau} } $$

Relative Rational Approximation Uncertainty

Idealized Frequency and Approximate Frequency

$$ \Delta f = \bigl| \widetilde f - f \bigr| $$

$$ \begin{align*} f \text{is an idealized frequency} \\ \widetilde f \text{is an approximate frequency} \\ \end{align*} $$

Rational Approximation

$$ \widetilde f = f_{ref} \frac{a}{b}, \quad a \in \mathbb{Z}, b \in \mathbb{N} $$

Rational Approximation Uncertainty

$$ \Delta f = \bigl| f_{ref} \frac{a}{b} - f\bigr| = \frac{f_{ref}}{f_{ref}} \bigl| f_{ref} \frac{a}{b} - f \bigr| = f_{ref} \bigl| \tfrac{a}{b} - \tfrac{f}{f_{ref}}\bigr| $$

$$ \frac{\Delta f}{f_{ref}} = \frac{f_{ref} \bigl| \frac{a}{b} - \frac{f}{f_{ref}} \bigr|}{f_{ref}} \ge \frac{1}{4 \pi \tau} $$

$$ \boxed { \bigl| \frac{a}{b} - \tfrac{f}{f_{ref}} \bigr| \ge \frac{1}{4 \pi \tau} } $$

Stern-Brocot: Traversal

$$ \begin{aligned} &\mathbf{WHILE} \boxed { \Bigl|\tfrac{a}{b} - \tfrac{f}{f_{\mathrm{ref}}}\Bigr| \ge \tfrac{1}{4\pi \tau} } \quad\mathbf{DO}\\ &\quad a \gets a_{\mathrm{left}} + a_{\mathrm{right}}\\ &\quad b \gets b_{\mathrm{left}} + b_{\mathrm{right}}\\ &\quad \mathbf{IF} \tfrac{f}{f_{\mathrm{ref}}} > \tfrac{a}{b} \mathbf{THEN}\\ &\quad\quad a_{\mathrm{left}} \gets a,\quad b_{\mathrm{left}} \gets b\\ &\quad \mathbf{ELSE}\\ &\quad\quad a_{\mathrm{right}} \gets a,\quad b_{\mathrm{right}} \gets b\\ &\quad \mathbf{END_IF}\\ &\quad d \gets d + 1\\ &\mathbf{END_WHILE} \end{aligned} $$

Stern-Brocot Example

Let’s find the rational approximation of two example frequencies that form a Major 7th interval:

$$ f_{\mathrm{ref}} = 261.6256\ \text{(C4)}, \quad f = 493.8833\ \text{(B4)} $$

We traverse the Stern–Brocot tree to a depth of 7 levels along the path RRLRRRR landing us on the fraction $\frac{11}{6}$.

$$ \bigl| \tfrac{493.8833}{261.6256} - \tfrac{11}{6}\bigr| = \bigl| 1.8877 - 1.8333 \bigr| = 0.0544 < \frac{1}{4 \pi} = 0.0796 $$



Stern–Brocot: Rational Fractions Lowest Terms

$$ \mathrm{gcd}(a,b)=1 \quad \Longrightarrow \quad a \perp b \quad \Longrightarrow \quad \frac{a}{b} \in \mathbb{Q_\perp} $$

Number-Theoretic Signal Processing

$$ f_0 = f_{ref}\frac{\mathrm{gcd}(a_1, a_2, \dots, a_N)}{\mathrm{lcm}(b_1, b_2, \dots, b_N)}, \quad f_{ref} = \mathrm{min}(f_1, f_2, \dots, f_N), \quad a_i \perp b_i $$

Rational Approximation Signal versus Idealized Signal

Idealized Frequencies:

$$\mathbf{f} = ( 261.63, 493.88 )$$

Equation for Rational Fraction Frequencies:

$$ \mathbf{f} = f_{ref} \cdot \bigl( \frac{a_i}{b_i},\frac{a_i}{b_i},\dots,\frac{a_N}{b_N} \bigr) $$

$$ \mathbf{f} = 261.6256 \cdot \bigl( \frac{1}{1},\frac{11}{6} \bigr) $$

M7 Signal from Coprime Spectrum:

$$\mathbf{f} = ( 261.63, 479.65 )$$


Major Triad Signal from Coprime Spectrum:

Is This a Bad Idea?

For $n = 1$, the resolution of pure-tone frequency ratios is poor. However, our auditory-system model explains how, despite this limitation, we can still perceive the difference between a unison (P1) and a minor second (m2).

Interval f ref Ratio Uncertainty
P1 261.626 261.626 1:1 1/4π
m2 277.183 261.626 1:1 1/4π

Fundamental Wavelength of a N-Tone Chord

$$ \lambda_0 = \lambda_{ref} \frac{\mathrm{lcm}(b_1, b_2, \dots, b_N)}{\mathrm{gcd}(a_1, a_2, \dots, a_N)}, \quad \lambda_{ref} = \mathrm{min}(\lambda_1, \lambda_2, \dots, \lambda_N), \quad a_i \perp b_i $$

Stolzenburg Harmonicity Perception

Fundamental Cycle Length of a N-Tone Chord

$$ L = \mathrm{lcm}(b_1,b_2,\dots,b_N) \quad\text{when}\quad \gcd(a_1,\dots,a_N)=1 $$

Harmonicity: Rational Approximation Cycle Length

$$ P_f = \log_2 \bigl(L_f\bigr) \quad \text{and} \quad P_\lambda = \log_2 \bigl(L_\lambda\bigr) \quad \text{[Proposed Units: Sz]} $$

Bonang: MaMi.CoDi.Beaty Harmonicity with Harrison & Pearce 2018

We use a simulated Bonang spectrum. Here is an example unison P1 pitch at C4.

Roughness: Stern-Brocot Traversal Depth

Stern–Brocot: Total Traversal Depth for All Tones in a N-Tone Chord

$$ D = \sum_{i=1}^{N} d_{i} $$

Stern–Brocot: Psychophysical Measure of Roughness

$$ R_f = \log_2 \bigl(D_f\bigr) \quad \text{and} \quad R_\lambda = \log_2 \bigl(D_\lambda\bigr) $$

Bonang: MaMi.CoDi.Beaty Roughness with Hutchinson & Knopoff 1978

Overall Frequency Dissonance

$$ \psi_f = P_f + R_f $$

Overall Wavelength Dissonance

$$ \psi_\lambda = P_\lambda + R_\lambda $$

Consonance-Dissonance: Frequency and Wavelength Dissonance Sum

$$ \boxed{ \Psi_{CoDi} = \psi_\lambda + \psi_f } $$

Major-Minor: Frequency and Wavelength Dissonance Difference

$$ \boxed { \Psi_{MaMi} = \psi_\lambda - \psi_f } $$

Beating: Frequency and Wavelength Roughness

$$ \boxed{ \Psi_{Beaty} = R_\lambda + R_f } $$

Pseudo-Octaves: Stretching and Compressing Harmonics

$$ \boxed{\Delta t \Delta \omega \ge \frac{1}{2}} $$

Harmonic Reference Time Period

$$ \Delta t = \tau \frac{T_{ref}}{n} = \tau \frac{2 \pi }{n \omega_{ref}}, \quad \tau \enspace \text{periods}, \quad n \in \mathbb{Z} \quad \text{harmonic number} $$

$$ \tau \frac{2 \pi}{n \omega_{ref}}\Delta \omega \ge \frac{1}{2} $$

Relative Harmonic Frequency Uncertainty

$$ \frac{\Delta \omega}{n \omega_{ref}} \ge \frac{1}{4 \pi \tau} $$

$$ \boxed { \frac{\Delta f}{n f_{ref}} \ge \frac{1}{4 \pi \tau} } $$

Idealized Frequency and Harmonic Frequency

$$ \Delta f = \bigl| \widetilde f - f \bigr| $$

$$ \begin{align*} f \text{is an idealized frequency} \\ \widetilde f \text{is a harmonic frequency} \\ \end{align*} $$

Harmonic Template (aka Integers)

$$ n = \mathrm{round}(\frac{f}{f_{ref}}) $$

$$ \widetilde f = n f_{ref} $$

Rational Approximation Uncertainty

$$ \Delta f = \bigl| n f_{ref} - f\bigr| = \frac{f_{ref}}{f_{ref}} \bigl| n f_{ref} - f \bigr| = f_{ref} \bigl| n - \tfrac{f}{f_{ref}}\bigr| $$

$$ \frac{\Delta f}{ n f_{ref}} = \frac{f_{ref} \bigl| n - \frac{f}{f_{ref}} \bigr|}{n f_{ref} } \ge \frac{1}{4 \pi \tau} $$

$$ \boxed { \frac{\bigl| \mathrm{round}(\frac{f}{f_{ref}}) - \tfrac{f}{f_{ref}} \bigr|}{\mathrm{round}(\frac{f}{f_{ref}})} \ge \frac{1}{4 \pi \tau} } $$

Heuristic to Find Pseudo Octave of a N-Tone Chord from Harmonic Spacing within Uncertainty Limit

$$ \begin{aligned} &\mathbf{FOR}\ i\gets 1\ \mathbf{TO}\ N\ \mathbf{DO}\\ &\quad\mathbf{FOR}\ j\gets i+1\ \mathbf{TO}\ N\ \mathbf{DO}\\ &\quad\quad n \gets \mathrm{round}\bigl(\tfrac{f_{j}}{f_{i}}\bigr) \\ &\quad\quad \mathbf{IF}\ n < 2\ \mathbf{CONTINUE}\\ &\quad\quad \mathbf{UNLESS}\ \boxed { \frac{\bigl| n - \tfrac{f}{f_{ref}} \bigr|}{n} \ge \frac{1}{4 \pi \tau} }\ \mathbf{THEN}\\ &\quad\quad\quad\quad candidate_pseudo_octave \gets \exp_{2} \bigl(\frac{\log_2(f_j / f_i)}{\log_2(n)}\bigr)\\ &\quad\quad\quad\quad candidates \gets candidates \cup {pseudo_octave}\\ &\quad\quad\mathbf{END_UNLESS}\\ &\quad\mathbf{END_FOR}\\ &\mathbf{END_FOR}\\ &\mathbf{RETURN}\ \mathbf{most_frequent}(candidates) \end{aligned} $$

Alignment with Sethares Plastic Range

For the $log_2$ form of the uncertainty limit

$$ \log_2 \bigl(1+\tfrac{1}{4 \pi \tau}\bigr) $$

$$ \log_2 \bigl(1+\tfrac{1}{4 \pi}\bigr) \approx 0.110467, \ \tau = 1 $$

we align well with Sethares range between $1.87$ and $2.2$.

$$ 2^{1 - 0.110467} \approx 1.85 \le \mathrm{pseudo_octave} \le 2^{1 + 0.110467} \approx 2.16 $$

Cubic Distortion Products

For all combinations of $f$ partials, we added the cubic distortion products to the stimuli.

$$ 2 f_{low} - f_{high}, \quad \text{where} \quad (f_{high} - f_{low}) < f_{min} $$ ### Pure Tone Spectra With and Without OAE


Appendix A: Relative Wavelength Uncertainty

$$ \Delta x \Delta k \ge \frac{1}{2} $$

$$ k = \frac{2\pi}{\lambda} = 2 \pi \lambda^-1 $$

$$ \Delta k = \left|\frac{dk}{d\lambda}\right|\Delta\lambda = \left|\frac{d (2 \pi \lambda^{-1})}{d\lambda}\right|\Delta\lambda = 2 \pi \lambda^{-2} \Delta \lambda = \frac{2\pi}{\lambda^2}\Delta\lambda $$

$$ \Delta x \frac{2\pi}{\lambda^2}\Delta\lambda \ge \frac{1}{2} $$

$$ \Delta x = l \lambda_{ref}, \quad l \enspace \text{wavelengths} $$

$$ \Delta x \frac{2\pi}{\lambda^2} \Delta\lambda = l \lambda_{ref} \frac{2\pi}{\lambda^2_{ref}} \Delta\lambda = l \frac{2 \pi \Delta \lambda}{\lambda_{ref}} \ge \frac{1}{2} $$

$$ \boxed{ \frac{\Delta \lambda}{\lambda_{ref}} \ge \frac{1}{4 \pi l} } $$

Appendix B: Related Theories

Gabor Wavelets from Rational Approximations


Daugman’s Gabor Wavelet in Computer Vision

John Daugman pioneered the use of Gabor wavelets for image analysis in computer vision.

Shamma’s Spectro-Temporal Analogy Between 2D Vision and 2D Hearing

Shamma proposed that the auditory system utilizes two-dimensional spectro-temporal receptive fields—processing sound across both time and frequency—analogous to how the visual system processes images in two spatial dimensions.

Weber’s law

$$ \frac{\Delta f}{f_{\rm ref}} = k, \quad k = \frac{1}{4\pi n} \quad \text{Weber's Constant} $$

Fechner’s law

$$ \psi = C \log_2 \bigl(\tfrac{\Lambda}{\Lambda_0}\bigr) $$

$$C = 1 \quad \text{and} \quad \Lambda_0 = 1$$

$$\psi = 1 \log_2 \bigl(\Lambda / 1\bigr) = \log_2(\Lambda)$$

Justification for C

We set $C=1$ because we are working with a purely relative scale—each doubling of $\Lambda$ maps to exactly one Sz unit with no additional gain factor.

Justification for $\Lambda_0$

We choose $\Lambda_0=1$ to anchor the zero‐point of perception at a single cycle, so that $\psi=0$ precisely when the stimulus contains one cycle.

Information-Theoretic Perspective

Bits of Harmonicity as Shannon Information

The Stern-Brocot Tree traversals give us many binary encodings:

RRLRRRR

Seems like this could be fertile ground for exploration.

About

A model of harmony perception

Resources

License

Stars

Watchers

Forks

Packages

No packages published