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

# Frequency and Pitch

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

\n", "Following Section 1.3.2 of [Müller, FMP, Springer 2015], we cover in this notebook the relation between frequency and pitch. \n", "

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sinusoids\n", "\n", "A sound wave can be visually represented by a [waveform](../C1/C1S3_Waveform.html). If the points of high and low air pressure repeat in an alternating and regular fashion, the resulting waveform is called **periodic**. In this case, the *period* of the wave is defined as the time required to complete a cycle. The **frequency**, measured in **Hertz** (Hz), is the reciprocal of the period. The simplest type of periodic waveform is a **sinusoid**, which is completely specified by its **frequency**, its **amplitude** (the peak deviation of the sinusoid from its mean), and its **phase** (determining where in its cycle the sinusoid is at time zero). The following figure shows a sinusoid with frequency $4~\\mathrm{Hz}$.\n", "\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Audible Frequency Range\n", "\n", "The higher the frequency of a sinusoidal wave, the higher it sounds. The audible frequency range for humans is between about $20~\\mathrm{Hz}$ and $20000~\\mathrm{Hz}$ ($20~\\mathrm{kHz}$). Other species have different hearing ranges. For example, the top end of a dog's hearing range is about $45~\\mathrm{kHz}$, a cat's is $64~\\mathrm{kHz}$, while bats can even detect frequencies beyond $100~\\mathrm{kHz}$. This is why one can use a dog whistle, which emits **ultrasonic sound** beyond the human hearing capability, to train and to command animals without disturbing nearby people.\n", "\n", "In the following experiment, we generate a **chirp signal** which frequency increases by a factor of two (one octave) every second. Starting with $80~\\mathrm{Hz}$, the frequency raises to $20480~\\mathrm{Hz}$ over a total duration of $8$ seconds. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import IPython.display as ipd\n", "import numpy as np\n", "import sys\n", "\n", "sys.path.append('..')\n", "import libfmp.c1\n", "\n", "Fs = 44100\n", "dur = 1\n", "freq_start = 80 * 2**np.arange(8)\n", "for f in freq_start:\n", " if f==freq_start:\n", " chirp, t = libfmp.c1.generate_chirp_exp_octave(freq_start=f, dur=dur, Fs=Fs, amp=1)\n", " else:\n", " chirp_oct, t = libfmp.c1.generate_chirp_exp_octave(freq_start=f, dur=dur, Fs=Fs, amp=1)\n", " chirp = np.concatenate((chirp, chirp_oct))\n", "\n", "ipd.display(ipd.Audio(chirp, rate=Fs))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Similarly, we generate a chirp signal starting with $640~\\mathrm{Hz}$ and going down $20~\\mathrm{Hz}$ over a total duration of $10$ seconds." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "