{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " \n", "

# Intervals

\n", "
\n", "\n", "
\n", "\n", "

\n", "Following Section 5.1.1 of [Müller, FMP, Springer 2015], we introduce in this notebook some basic facts on musical intervals.\n", "\n", "

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction\n", "\n", "In music, an **interval** may be loosely defined as the difference between two [**pitches**](../C1/C1S1_MusicalNotesPitches.html). This definition is problematic in the sense that the underlying notion of pitch is already a rather vague one. As we discussed in the [FMP notebook on musical notes and pitches](../C1/C1S1_MusicalNotesPitches.html), pitch is a perceptual property that allows the ordering of sounds on a frequency-related logarithmic scale. When playing a note of a certain pitch on an instrument, the resulting musical tone is dominated by certain frequencies referred to as [**partials**](../C1/C1S3_Timbre.html). The frequency of the lowest partial is called the **fundamental frequency**, which is the frequency typically associated to the pitch. For harmonic sounds, the partials are (close to) integer multiples, the [**harmonics**](../C1/C1S3_HarmonicSeries.html), of the fundamental frequency. The most basic interval in music is the [**octave**](../C1/C1S3_HarmonicSeries.html), which is defined as the distance between a pitch and another one with half or double its fundamental frequency. Starting with this basic interval, one can define notions of other **intervals** by considering **frequency relations** of harmonics (physical approach), **geometric relations** (mathematical approach), or **note relations** (musical approach). These approaches lead to slightly different notions of intervals, which are however referred to by the same interval names. In this notebook, we will discuss some of these notions and the resulting inconsistencies. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Semitone Differences\n", "\n", "Assuming a [**twelve-tone equal-tempered scale**](../C1/C1S1_MusicalNotesPitches.html), an octave is subdivided into twelve scale steps that are equally spaced on a logarithmic frequency axis. The smallest possible interval in this scale is called a **semitone**, which is the difference between two subsequent scale steps. In terms of frequencies, a semitone describes a ratio (rather than a difference), which can be specified using the logarithmic unit of [**cents**](../C1/C1S3_FrequencyPitch.html). Recall that the difference in cents between two frequencies, say $\\omega_1$ and $\\omega_2$, is given by \n", "\n", "\\begin{equation}\n", "\\log_2\\left(\\frac{\\omega_1}{\\omega_2}\\right)\\cdot 1200.\n", "\\end{equation}\n", "\n", "Thus, in the equal-tempered scale, a semitone corresponds to $100$ cents. Based on the notion of a semitone, one can now specify other intervals that are used in Western music theory. The naming conventions for these intervals are based on historical practice. In particular, an interval name may not only describe the difference in semitones between the lower and upper notes, but also how the interval is specified in score notation. Different note symbols may refer to the same note, which is known as **enharmonic equivalence**. Similarly, there exists enharmonic equivalence between musically different intervals (referred to by different interval names) that correspond to the same distance when measured in semitones (assuming the equal-tempered scale). For example, the two intervals named \"augmented unison\" and \"minor second\" both express the difference of one semitone, while specified differently when using score notation.\n", "In the following, even though being an oversimplification, we think of an interval in terms of a distance between pitches (given in semitones) while disregarding their music notation. The following figure shows the most common interval names (using the note C4 as reference of the lower note) and their meaning in terms of semitone differences (indicated by $\\Delta$). \n", "\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Frequency Ratios\n", "\n", "The concept of intervals can be approached from a physical point of view by considering frequency relations that naturally occur between the harmonic partials of a pitched sound. Recall that the harmonics are the integer multiples of a fundamental frequency forming the [**harmonic series**](../C1/C1S3_HarmonicSeries.html) of a tone. In the physical approach, one derives the intervals from frequency relations between partials that occur within the same harmonic series. This is illustrated by the following figure, which shows the harmonic series of the note C2. \n", "\n", " \n", "\n", "For example, the octave occurs as an interval between the first two partials, the fifth as an interval between the second and third partial, the fourth as an interval between the third and fourth partial, and so on. This observation leads to a definition of intervals that is based on ratios of small whole numbers. Any interval defined in this way is also called a **pure** or **just interval**. Similarly, the musical tuning based on harmonics is known as **pure** or **just intonation**. \n", "\n", "Besides just intonation, there are many more tuning systems that may be used for defining intervals in terms of frequency ratios. The oldest known tuning system was introduced by the Greek philosopher and mathematician **Pythagoras** (sixth century BC). The geometrically motivated [**Pythagorean tuning**](../C1/C1E10_PythagoreanTuning.html) is based only on the frequency ratio $1:2$ of the octave and the ratio $2:3$ of the fifth. All other intervals are derived from these ratios by suitably adding and subtracting fifths and octaves. This results in intervals that can be expressed by frequency ratios that involve only **powers of two** or **powers of three**.\n", "\n", "In the following figure, we illustrate various definitions of intervals and their relations. The columns from left to right indicate the difference given in semitones ($\\Delta$), the name of the interval, the interval assuming C4 as the root note, as well as the ratios with respect to just intonation (JI), and the Pythagorean ratios (Pyt).\n", "\n", " \n", "\n", "In the following code cell, we provide a sinusoidal sonification of the various intervals with respect to equal temperament (ET), just intonation (JI), and Pythagorean tuning (Pyt). Furthermore, we specify the deviations (given in cents) between the ET-based and JI-based intervals (JI Dev) as well as between the ET-based and Pyt-based intervals (Pyt Dev)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
$\\Delta$Interval name IntervalET Sinusoid   JI RatioJI SinusoidJI Dev   Pyt RatioPyt SinusoidPyt Dev
0(Perfect) unisonC4–C4$1:1$0.0$1:1$0.0
1Minor secondC4–C$^\\sharp$4$15:16$11.7$3^5:2^8$-9.8
2Major secondC4–D4$8:9$3.9$2^3:3^2$3.9
3Minor ThirdC4–D$^\\sharp$4$5:6$15.6$3^3:2^5$-5.9
4Major ThirdC4–E4$4:5$-13.7$2^6:3^4$7.8
5(Perfect) fourthC4–F4$3:4$-2.0$3:2^2$-2.0
6TritoneC4–F$^\\sharp$4$32:45$-9.8$2^9:3^6$11.7
7(Perfect) fifthC4–G4$2:3$2.0$2:3$2.0
8Minor sixthC4–G$^\\sharp$4$5:8$13.7$3^4:2^7$-7.8
9Major sixthC4–A4$3:5$-15.6$2^4:3^3$5.9
10Minor seventhC4–A$^\\sharp$4$5:9$17.6$3^2:2^4$-3.9
11Major seventhC4–B4$8:15$-11.7$2^7:3^5$9.8
12(Perfect) octaveC4–C4$1:2$0.0$1:2$0.0
" ], "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from collections import OrderedDict\n", "import numpy as np\n", "import IPython.display as ipd\n", "import pandas as pd\n", "\n", "def f_pitch(p):\n", " frequency = 2 ** ((p - 69) / 12) * 440\n", " return frequency\n", "\n", "diff_semitones = ['0','1','2','3','4','5','6','7','8','9','10','11','12',]\n", "\n", "JI_frac = ['$1:1$', '$15:16$', '$8:9$', '$5:6$', '$4:5$', '$3:4$', '$32:45$', \n", " '$2:3$', '$5:8$', '$3:5$', '$5:9$', '$8:15$', '$1:2$']\n", "JI_ratio = np.asarray([1, 15/16, 8/9, 5/6, 4/5, 3/4, 32/45, 2/3, 5/8, 3/5, 5/9, 8/15, 1/2])\n", "\n", "pyt_frac = ['$1:1$', '$3^5:2^8$', '$2^3:3^2$', '$3^3:2^5$', '$2^6:3^4$', '$3:2^2$', '$2^9:3^6$', \n", " '$2:3$', '$3^4:2^7$', '$2^4:3^3$', '$3^2:2^4$', '$2^7:3^5$', '$1:2$']\n", "pyt_ratio = np.asarray([1, 243/256, 8/9, 27/32, 64/81, 3/4, 512/729, 2/3, 81/128, 16/27, 9/16, 128/243, 1/2])\n", "\n", "p = 60\n", "omega = f_pitch(p)\n", "freq_JI = omega / JI_ratio \n", "freq_pyt = omega / pyt_ratio\n", "notes = np.asarray(range(p, p + 13))\n", "freq_center = f_pitch(notes)\n", "freq_deviation_cents_JI = np.log2(freq_JI / freq_center) * 1200\n", "freq_deviation_cents_pyt = np.log2(freq_pyt / freq_center) * 1200\n", "\n", "duration = 1\n", "Fs = 4000\n", "N = int(duration * Fs)\n", "t = np.arange(0, N) / Fs\n", "\n", "def generate_sinusoid(omega, t):\n", " return np.sin(2 * np.pi * omega * t)\n", "\n", "def generate_sinusoid_list(freq_list, x_ref=[]):\n", " sinusoid_list = []\n", " for f in freq_list:\n", " s = generate_sinusoid(f, t)\n", " x = np.concatenate((x_ref, s))\n", " sinusoid_list.append(x)\n", " return sinusoid_list\n", "\n", "x_ref = generate_sinusoid(omega, t)\n", "sinusoid_center = generate_sinusoid_list(freq_center, x_ref)\n", "sinusoid_JI = generate_sinusoid_list(freq_JI, x_ref)\n", "sinusoid_pyt = generate_sinusoid_list(freq_pyt, x_ref) \n", "\n", "# Generation of html table\n", "def generate_audio_tag_html_list(sinusoid_list, Fs):\n", " audio_tag_html_list = []\n", " for i in range(len(sinusoid_list)):\n", " audio_tag = ipd.Audio( sinusoid_list[i], rate=Fs)\n", " audio_tag_html = audio_tag._repr_html_().replace('\\n', '').strip()\n", " audio_tag_html = audio_tag_html.replace('