{ "cells": [ { "cell_type": "markdown", "id": "c000", "metadata": {}, "source": [ "# 01. Sampling and aliasing\n", "\n", "A digital audio signal is a sequence of samples taken at a fixed rate: 8 kHz for\n", "narrow-band telephone speech, 16 kHz for wide-band speech and most speech recognisers, 44.1 or\n", "48 kHz for music. The sample rate determines which frequencies the samples can represent.\n", "Frequencies above that limit are not removed: after sampling they appear at lower frequencies.\n", "This notebook shows where they appear, why, and how to prevent it.\n", "\n", "**Learning outcomes.** After working through this notebook you can\n", "\n", "* state the sampling theorem and compute the Nyquist frequency of a sample rate;\n", "* predict the alias frequency of any tone with the folding formula, and measure it with an FFT;\n", "* explain why naive decimation and naive waveform synthesis alias, and avoid both with\n", " `audio_samples` (`AudioSamples.resample`, `square_wave_bandlimited`);\n", "* reconstruct a band-limited signal between its samples with a sinc sum." ] }, { "cell_type": "code", "execution_count": null, "id": "c001", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "import audio_samples as aus\n", "\n", "rng = np.random.default_rng(seed=2026)\n", "F64 = np.dtype(\"float64\") # generators default to float32; we ask for float64 throughout" ] }, { "cell_type": "markdown", "id": "c002", "metadata": {}, "source": [ "## Concept\n", "\n", "**Sampling** reads an analogue signal every $T$ seconds:\n", "\n", "$$x[n] = x_a(nT), \\qquad T = 1 / f_s$$\n", "\n", "where $x_a(t)$ is the analogue signal (amplitude in units of full scale) at time $t$ in seconds,\n", "$n$ is the integer sample index, $T$ is the sampling period in seconds and $f_s$ is the sample\n", "rate in Hz (samples per second).\n", "\n", "**Why aliasing happens.** For any integer $m$,\n", "\n", "$$\\cos(2\\pi f n T) = \\cos(2\\pi (f + m f_s) n T)$$\n", "\n", "because the extra phase $2\\pi m f_s n T = 2\\pi m n$ is a whole number of turns. Here $f$ is a\n", "tone frequency in Hz. Since $\\cos$ is even, $-f$ gives the same samples too, so the tones $f$,\n", "$f + m f_s$ and $m f_s - f$ are indistinguishable once sampled.\n", "\n", "**Nyquist frequency and the sampling theorem.** The highest frequency that is represented\n", "unambiguously is the Nyquist frequency\n", "\n", "$$f_N = f_s / 2$$\n", "\n", "in Hz. If $x_a$ contains no energy at or above $f_N$, it is recovered exactly from its samples by\n", "sinc interpolation (Whittaker-Shannon):\n", "\n", "$$x_a(t) = \\sum_n x[n] \\, \\mathrm{sinc}\\!\\left(\\frac{t - nT}{T}\\right), \\qquad \\mathrm{sinc}(u) = \\frac{\\sin(\\pi u)}{\\pi u}$$\n", "\n", "where $u$ is a dimensionless time offset in sampling periods (this is NumPy's `np.sinc`).\n", "\n", "**Folding formula.** A tone at $f$ Hz appears after sampling at\n", "\n", "$$f_a = |f - k f_s|, \\qquad k = \\mathrm{round}(f / f_s)$$\n", "\n", "where $f_a$ is the alias frequency in Hz (always between 0 and $f_N$) and $k$ is the nearest\n", "integer multiple of the sample rate. Equivalently, the frequency axis is folded at $0$, $f_N$,\n", "$f_s$, $3f_N$, ..., which maps every frequency into $[0, f_N]$.\n", "\n", "Aliasing occurs in three places:\n", "\n", "* **acquisition**: an analogue anti-aliasing filter must remove energy above $f_N$ before the\n", " converter samples;\n", "* **downsampling**: keeping every $M$-th sample is sampling again at $f_s/M$, so content between\n", " the output's and the input's Nyquist frequencies must be filtered out first;\n", "* **synthesis**: a waveform with jumps (a hard square wave) has harmonics at every odd multiple\n", " $h f_0$ of its fundamental $f_0$, with amplitudes $4A/(\\pi h)$ for peak amplitude $A$. Computing\n", " it sample by sample samples those harmonics too, and the ones above $f_N$ fold back as\n", " inharmonic tones." ] }, { "cell_type": "markdown", "id": "c003", "metadata": {}, "source": [ "## With the library\n", "\n", "Generate an 11 kHz tone at 48 kHz, then reduce it to 16 kHz (Nyquist frequency 8 kHz) in two\n", "ways: naively, by keeping every third sample (written by hand), and with the library's\n", "resampler at each of its three quality tiers. The folding formula predicts\n", "$|11000 - 1 \\cdot 16000| = 5000$ Hz.\n", "\n", "Two conventions of this library matter here: `AudioSamples.rfft(n_fft)` returns **magnitudes**\n", "$|X[k]|$ (NumPy's `np.fft.rfft` returns complex values), shaped `(channels, n_fft // 2 + 1)`,\n", "and it does not normalise, so a bin-centred sine of amplitude $A$ gives $|X[k]| = A N / 2$." ] }, { "cell_type": "code", "execution_count": null, "id": "c004", "metadata": {}, "outputs": [], "source": [ "# 250 ms of an 11 kHz tone, amplitude 0.5, at 48 kHz: 12 000 samples.\n", "hi = aus.sine_wave(11_000.0, 0.25, sample_rate=48_000, amplitude=0.5, dtype=F64)\n", "assert hi.samples_per_channel() == 12_000\n", "\n", "# Naive decimation, written by hand: keep every third sample -> 4000 samples at 16 kHz.\n", "naive = aus.AudioSamples.new_mono(hi.to_numpy()[::3], sample_rate=16_000)\n", "assert naive.samples_per_channel() == 4000\n", "\n", "# A 4000-point DFT of 4000 samples at 16 kHz has 4 Hz bins.\n", "mag = naive.rfft(4000)[0]\n", "peak = int(np.argmax(mag))\n", "assert peak * 4.0 == 5_000.0 # the alias, exactly where predicted\n", "# A bin-centred sine of amplitude A gives |X| = A N / 2 = 0.5 * 4000 / 2 = 1000: full strength.\n", "assert abs(mag[peak] - 1000.0) < 1e-6\n", "\n", "\n", "# Every ResamplingQuality low-pass filters below 8 kHz before decimating. In the steady state\n", "# (middle 100 ms: 1600 samples, 500 whole periods of 5 kHz) one DFT bin measures what is left of\n", "# the alias, in dB relative to the tone's amplitude of 0.5.\n", "def level_db(y, f, fs, amp):\n", " n = np.arange(len(y))\n", " return 20 * np.log10(2 / len(y) * abs(np.sum(y * np.exp(-2j * np.pi * f * n / fs))) / amp)\n", "\n", "\n", "mid = slice(1_200, 2_800)\n", "alias_naive = level_db(naive.to_numpy()[mid], 5_000.0, 16_000, 0.5)\n", "tiers = {name: hi.resample(16_000, getattr(aus.ResamplingQuality, name)) for name in (\"fast\", \"medium\", \"high\")}\n", "steady = {name: level_db(y.to_numpy()[mid], 5_000.0, 16_000, 0.5) for name, y in tiers.items()}\n", "print(f\"alias at {peak * 4.0:.0f} Hz, |X| = {mag[peak]:.3f}\")\n", "print(f\"steady state at 5 kHz: naive {alias_naive:+.2f} dB, \"\n", " + \", \".join(f\"{name} {v:.1f} dB\" for name, v in steady.items()))\n", "assert abs(alias_naive) < 1e-6 # the alias at full strength\n", "assert all(y.samples_per_channel() == 4_000 for y in tiers.values())\n", "# Gone: for this 1 : 3 ratio the resampler drops everything above the output's Nyquist frequency\n", "# in the frequency domain instead of folding its filter's stopband back, so what is left is\n", "# float64 round-off, more than 180 dB down.\n", "assert all(v < -180 for v in steady.values())\n", "\n", "# Over the whole 250 ms the largest remaining component of the High output is not the alias:\n", "# the tone is switched on and off abruptly, and those edges leave broadband transients (the\n", "# first 50 output samples reach 0.12) that the filter passes below 8 kHz.\n", "y_high = tiers[\"high\"].to_numpy()\n", "mag_high = tiers[\"high\"].rfft(4000)[0]\n", "edge_db = 20 * np.log10(mag[peak] / mag_high.max())\n", "whole_alias_db = 20 * np.log10(mag[peak] / mag_high[peak])\n", "top_hz = np.argmax(mag_high) * 4.0\n", "print(f\"whole signal (High): 5 kHz bin {-whole_alias_db:.1f} dB, largest component {-edge_db:.1f} dB \"\n", " f\"at {top_hz:.0f} Hz\")\n", "# Strongest leftover at 7652 Hz, in the transition band between 0.913 x 8 kHz and 8 kHz.\n", "assert top_hz == 7_652.0 and 0.913 * 8_000 < top_hz < 8_000\n", "assert abs(edge_db - 74.55) < 0.05 and abs(whole_alias_db - 78.4) < 0.05\n", "assert abs(np.abs(y_high[:50]).max() - 0.12) < 0.005\n", "assert np.abs(y_high[mid]).max() < 1e-7" ] }, { "cell_type": "code", "execution_count": null, "id": "c005", "metadata": {}, "outputs": [], "source": [ "freqs = np.arange(mag.size) * 4.0\n", "fig, ax = plt.subplots(figsize=(8, 3))\n", "ax.plot(freqs, 20 * np.log10(mag / 1000.0 + 1e-12), label=\"keep every 3rd sample (naive)\")\n", "for name in (\"fast\", \"high\"):\n", " spec = tiers[name].rfft(4000)[0]\n", " ax.plot(freqs, 20 * np.log10(spec / 1000.0 + 1e-12), lw=0.8, label=f\"ResamplingQuality.{name}\")\n", "ax.set(xlabel=\"Frequency (Hz)\", ylabel=\"Level re full-strength tone (dB)\", ylim=(-160, 10),\n", " title=\"11 kHz tone resampled from 48 kHz to 16 kHz\")\n", "ax.legend(loc=\"lower left\")\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "c006", "metadata": {}, "source": [ "The naive version did not remove the tone; it moved it to 5 kHz at full strength, where it is\n", "indistinguishable from a genuine 5 kHz component. Every tier of the resampler removes it:\n", "in the steady state (the middle 100 ms) the 5 kHz residue is float64 round-off, more than 180 dB\n", "below the tone, for every tier: for this 1 : 3 ratio the resampler drops everything above the\n", "output's Nyquist frequency in the frequency domain (notebook 07 measures every tier this way).\n", "Measured over the whole 250 ms the `high` output appears much\n", "worse: the largest remaining component is only 74.5 dB down and is at 7652 Hz, not 5 kHz, and\n", "the 5 kHz bin is only 78.4 dB down. Both come from the abrupt start and end of the tone, not\n", "from aliasing, so measure alias rejection away from the edges.\n", "\n", "The same applies when a waveform is synthesised. A naive square wave (`aus.square_wave`)\n", "switches between $\\pm A$; the band-limited version (`aus.square_wave_bandlimited`) adds only the\n", "odd harmonics below $f_N$. With $f_0 = 700$ Hz and $f_s = 16$ kHz, one second holds exactly 700\n", "periods, so every harmonic and every alias falls on an integer-Hz bin of a 16 000-point DFT, and\n", "we can count the power that is *not* at an odd harmonic of 700 Hz." ] }, { "cell_type": "code", "execution_count": null, "id": "c007", "metadata": {}, "outputs": [], "source": [ "s_naive = aus.square_wave(700.0, 1.0, sample_rate=16_000, dtype=F64).rfft(16_000)[0] # 1 Hz bins\n", "s_clean = aus.square_wave_bandlimited(700.0, 1.0, sample_rate=16_000, dtype=F64).rfft(16_000)[0]\n", "\n", "k = np.arange(s_naive.size)\n", "odd_harmonic = (k % 700 == 0) & ((k // 700) % 2 == 1)\n", "\n", "def stray_db(s):\n", " # Power not at an odd harmonic of 700 Hz, relative to the total, in dB.\n", " return 10 * np.log10((s[~odd_harmonic] ** 2).sum() / (s ** 2).sum())\n", "\n", "print(f\"stray power: naive {stray_db(s_naive):.2f} dB, band-limited {stray_db(s_clean):.1f} dB\")\n", "# About 3.3 % of the naive wave's power is aliased (-14.77 dB) ...\n", "assert abs(stray_db(s_naive) + 14.77) < 0.01\n", "assert abs(10 ** (stray_db(s_naive) / 10) - 0.033) < 0.0005\n", "# ... and almost none of the band-limited wave's.\n", "assert stray_db(s_clean) < -200.0\n", "\n", "# The 13th harmonic (9100 Hz) is the first above 8 kHz: it folds to 6900 Hz, close to its ideal\n", "# level of 1/13 of the fundamental (-22.3 dB).\n", "rel_db = 20 * np.log10(s_naive[6900] / s_naive[700])\n", "assert abs(20 * np.log10(1 / 13) - (-22.3)) < 0.05\n", "assert abs(rel_db - 20 * np.log10(1 / 13)) < 0.3\n", "assert s_clean[6900] / s_clean[700] < 1e-9" ] }, { "cell_type": "code", "execution_count": null, "id": "c008", "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize=(8, 3))\n", "ax.plot(k, 20 * np.log10(s_naive / s_naive.max() + 1e-12), lw=0.8, label=\"square_wave (naive)\")\n", "ax.plot(k, 20 * np.log10(s_clean / s_clean.max() + 1e-12), lw=0.8, label=\"square_wave_bandlimited\")\n", "ax.set(xlabel=\"Frequency (Hz)\", ylabel=\"Level re fundamental (dB)\", ylim=(-120, 5),\n", " title=\"700 Hz square wave at 16 kHz: aliased harmonics fill the gaps\")\n", "ax.legend(loc=\"lower left\")\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "c009", "metadata": {}, "source": [ "The sample rate is stored with the data. Write the 48 kHz tone to a WAV file in a temporary\n", "directory and read it back: the header stores the rate, and the samples are preserved. (A\n", "float64 buffer is stored as a 64-bit float WAV, so it comes back as `float64`.)" ] }, { "cell_type": "code", "execution_count": null, "id": "c010", "metadata": {}, "outputs": [], "source": [ "with tempfile.TemporaryDirectory() as tmp:\n", " path = os.path.join(tmp, \"tone_11k.wav\")\n", " aus.io.save(path, hi)\n", " back = aus.io.read(path)\n", "\n", "print(back.sample_rate, back.dtype, back.samples_per_channel())\n", "assert back.sample_rate == 48_000\n", "assert back.samples_per_channel() == hi.samples_per_channel()\n", "# 64-bit float storage keeps every sample, well within this tolerance.\n", "assert np.allclose(back.to_numpy(), hi.to_numpy(), atol=3e-8)" ] }, { "cell_type": "markdown", "id": "c011", "metadata": {}, "source": [ "## How it works\n", "\n", "The folding formula is one line of code. Check it over a sweep of frequencies, and check the identity\n", "behind it: the samples of an 11 kHz sine at 16 kHz are exactly those of a 5 kHz sine with\n", "inverted sign, because\n", "$\\sin(2\\pi \\cdot 11000\\, n/16000) = \\sin(2\\pi(11000 - 16000)\\, n/16000) = -\\sin(2\\pi \\cdot 5000\\, n / 16000)$." ] }, { "cell_type": "code", "execution_count": null, "id": "c012", "metadata": {}, "outputs": [], "source": [ "def fold(f, fs):\n", " # Alias of a tone at f Hz sampled at fs Hz: |f - round(f / fs) * fs|.\n", " return np.abs(f - np.round(f / fs) * fs)\n", "\n", "# Every 250 Hz from 0 to 50 kHz at 16 kHz folds into [0, 8000] Hz.\n", "sweep = 250.0 * np.arange(201)\n", "aliases = fold(sweep, 16_000.0)\n", "assert aliases.max() <= 8_000.0 and aliases.min() >= 0.0\n", "\n", "# Measure the alias of a few of them with the library's rfft (0.25 s -> 4 Hz bins; every\n", "# alias below is a multiple of 4 Hz, so it lands exactly on a bin).\n", "for f in [3_000.0, 11_000.0, 25_000.0, 47_200.0]:\n", " t = np.arange(4000) / 16_000.0\n", " x = aus.AudioSamples.new_mono(np.cos(2 * np.pi * f * t), sample_rate=16_000)\n", " assert np.argmax(x.rfft(4000)[0]) * 4.0 == fold(f, 16_000.0)\n", "\n", "# Identical samples, sign inverted. Tolerance: sin of arguments up to ~2e4 rad in float64\n", "# carries ~1e-12 of rounding.\n", "n = np.arange(1000)\n", "assert np.allclose(np.sin(2 * np.pi * 11_000 * n / 16_000), -np.sin(2 * np.pi * 5_000 * n / 16_000), atol=1e-9)" ] }, { "cell_type": "markdown", "id": "c013", "metadata": {}, "source": [ "The library's `rfft` is the magnitude of the ordinary DFT. NumPy is an independent reference with\n", "the same (unnormalised, negative-exponent) convention, once we take `np.abs`:" ] }, { "cell_type": "code", "execution_count": null, "id": "c014", "metadata": {}, "outputs": [], "source": [ "sq = aus.square_wave(700.0, 1.0, sample_rate=16_000, dtype=F64)\n", "ref = np.abs(np.fft.rfft(sq.to_numpy(), n=16_000))\n", "# 16 000-term FFT sums of values of size 1: rounding of order 1e-12.\n", "assert np.allclose(sq.rfft(16_000)[0], ref, atol=1e-9)" ] }, { "cell_type": "markdown", "id": "c015", "metadata": {}, "source": [ "The sampling theorem says a band-limited signal can be recovered *between* its samples.\n", "Reconstruct a 1 kHz tone sampled at 8 kHz halfway between two samples with a (truncated) sinc\n", "sum:" ] }, { "cell_type": "code", "execution_count": null, "id": "c016", "metadata": {}, "outputs": [], "source": [ "fs, f = 8_000.0, 1_000.0\n", "n = np.arange(8000)\n", "x = np.sin(2 * np.pi * f * n / fs)\n", "\n", "u0 = 4000.5 # t = 4000.5 T, in the middle of the 1 s block\n", "estimate = np.sum(x * np.sinc(u0 - n))\n", "truth = np.sin(2 * np.pi * f * u0 / fs)\n", "print(f\"sinc reconstruction {estimate:.6f}, true value {truth:.6f}\")\n", "# The sum is truncated to 8000 terms; the neglected tails decay like 1/(pi u), so an error of\n", "# order 1e-4 is expected.\n", "assert abs(estimate - truth) < 1e-3" ] }, { "cell_type": "markdown", "id": "c017", "metadata": {}, "source": [ "## Ask the library to explain\n", "\n", "`aus.explain.sampling` and `aus.explain.aliasing` return an `ExplainDoc` with the formulas, the\n", "values for your parameters, a table of tones that share the same samples, and a warning when a tone is\n", "above the Nyquist frequency. In Jupyter the document renders as Markdown." ] }, { "cell_type": "code", "execution_count": null, "id": "c018", "metadata": {}, "outputs": [], "source": [ "s = aus.explain.sampling(16_000.0)\n", "assert s.quantity(\"Nyquist frequency\") == 8_000.0\n", "assert s.quantity(\"Sampling period\") == 0.0625 # in ms\n", "# 8 kHz is below the 20 kHz limit of hearing: an informational note.\n", "assert s.has_warning(\"info\")\n", "s" ] }, { "cell_type": "code", "execution_count": null, "id": "c019", "metadata": {}, "outputs": [], "source": [ "a = aus.explain.aliasing(25_000.0, 16_000.0)\n", "assert a.quantity(\"Alias frequency\") == 7_000.0 == fold(25_000.0, 16_000.0)\n", "assert a.has_warning(\"caution\")\n", "assert a.has_warning_containing(\"will alias to 7000 Hz\")\n", "for w in a.warnings:\n", " print(f\"[{w['level']}] {w['message']}\")\n", "a" ] }, { "cell_type": "markdown", "id": "c020", "metadata": {}, "source": [ "## Exercises\n", "\n", "1. A telephone line samples at 8 kHz. A 7.5 kHz whistle reaches the converter unfiltered. At what\n", " frequency (Hz) does it appear? Store it in `answer`." ] }, { "cell_type": "code", "execution_count": null, "id": "c021", "metadata": {}, "outputs": [], "source": [ "answer = None # TODO" ] }, { "cell_type": "code", "execution_count": null, "id": "c022", "metadata": { "tags": [ "solution" ] }, "outputs": [], "source": [ "# Solution\n", "answer = fold(7_500.0, 8_000.0) # |7500 - 1 * 8000|\n", "assert answer == 500.0\n", "assert aus.explain.aliasing(7_500.0, 8_000.0).quantity(\"Alias frequency\") == answer" ] }, { "cell_type": "markdown", "id": "c023", "metadata": {}, "source": [ "2. You halve the rate of a 44.1 kHz recording by keeping every second sample. It contains a\n", " 15 kHz tone. Predict its alias frequency, then measure it with `rfft` (use 0.2 s of signal, so the\n", " decimated 4410 samples give 5 Hz bins)." ] }, { "cell_type": "code", "execution_count": null, "id": "c024", "metadata": {}, "outputs": [], "source": [ "answer = None # TODO" ] }, { "cell_type": "code", "execution_count": null, "id": "c025", "metadata": { "tags": [ "solution" ] }, "outputs": [], "source": [ "# Solution\n", "answer = fold(15_000.0, 22_050.0) # decimated rate 22 050 Hz: |15000 - 22050|\n", "assert answer == 7_050.0\n", "x = aus.sine_wave(15_000.0, 0.2, sample_rate=44_100, dtype=F64)\n", "dec = aus.AudioSamples.new_mono(x.to_numpy()[::2], sample_rate=22_050)\n", "assert dec.samples_per_channel() == 4410\n", "assert np.argmax(dec.rfft(4410)[0]) * 5.0 == answer" ] }, { "cell_type": "markdown", "id": "c026", "metadata": {}, "source": [ "3. In the naive 700 Hz square wave above there is energy at 1300 Hz, which is not a harmonic of\n", " 700 Hz. Which harmonic number $h$ folded there? Check that the band-limited wave has nothing\n", " there." ] }, { "cell_type": "code", "execution_count": null, "id": "c027", "metadata": {}, "outputs": [], "source": [ "answer = None # TODO" ] }, { "cell_type": "code", "execution_count": null, "id": "c028", "metadata": { "tags": [ "solution" ] }, "outputs": [], "source": [ "# Solution\n", "answer = next(h for h in range(1, 200, 2) if fold(700.0 * h, 16_000.0) == 1_300.0)\n", "assert answer == 21 # 14 700 Hz, folded about 16 kHz\n", "assert s_naive[1300] / s_naive[700] > 1e-3 # clearly present\n", "assert s_clean[1300] / s_clean[700] < 1e-9 # absent" ] }, { "cell_type": "markdown", "id": "c029", "metadata": {}, "source": [ "## Common pitfalls\n", "\n", "* Keeping every $M$-th sample (`x[::M]`) is not resampling: it aliases. Every\n", " `ResamplingQuality` filters first, but the default, `fast`, uses a short filter whose pass band\n", " ends at 0.8 times the output's Nyquist frequency; pass `ResamplingQuality.medium` or `.high` when the\n", " top of the band matters (notebook 07).\n", "* `square_wave`, `sawtooth_wave` and `triangle_wave` are naive and alias; use the\n", " `*_bandlimited` versions for test signals.\n", "* The generators return `float32` unless you pass `dtype=np.float64` (a `np.dtype` or a string\n", " such as `\"float64\"` also works).\n", "* A tone exactly at $f_N$ is ambiguous: a sine sampled there at zero phase is all zeros.\n", "* An alias may come back with inverted phase (the 11 kHz example returns as $-\\sin$ at 5 kHz).\n", "* `AudioSamples.rfft` returns **magnitudes**, unlike `np.fft.rfft`; use `AudioSamples.fft` for\n", " the complex bins. `n_fft` must be at least the signal length (notebook 03).\n", "\n", "## See also\n", "\n", "* Rust guide chapter: [01. Sampling and aliasing](https://docs.rs/audio_samples/latest/audio_samples/guide/c01_sampling_aliasing/index.html) (available from the next release; until then build the docs locally with `cargo doc --features educational,full_no_plotting --open`)\n", " and the lab `examples/tutorial_01_sampling_aliasing.rs`.\n", "* Python API: `AudioSamples.resample`, `ResamplingQuality`, `AudioSamples.rfft`,\n", " `aus.sine_wave`, `aus.square_wave_bandlimited`, `aus.explain.sampling`,\n", " `aus.explain.aliasing`, `aus.explain.resampling` ([API reference](../api/audio_samples.rst)).\n", "* Next: [02. Quantisation and dither](02_quantisation_dither.ipynb)." ] }, { "cell_type": "markdown", "id": "references", "metadata": {}, "source": [ "## References\n", "\n", "* Shannon, C. E. (1949). Communication in the presence of noise. *Proceedings of the IRE*, 37(1), 10-21.\n", "* Oppenheim, A. V. and Schafer, R. W. (2010). *Discrete-Time Signal Processing*, 3rd ed. Pearson. Chapter 4 (sampling, aliasing, changing the sampling rate)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }