{ "cells": [ { "cell_type": "markdown", "id": "c000", "metadata": {}, "source": [ "# 05. Convolution and FIR filters\n", "\n", "A finite impulse response (FIR) filter replaces each sample by a weighted sum of the most recent\n", "input samples. This operation, convolution, is used to smooth noisy envelopes, remove hum,\n", "band-limit a signal before downsampling, simulate a room from its impulse response, and implement\n", "the pre-emphasis step of speech front ends. This notebook defines convolution precisely, describes\n", "the two output lengths (\"full\" and \"valid\"), and connects a filter's taps to its\n", "frequency response and delay, ending with a low-pass filter designed from scratch.\n", "\n", "**Learning outcomes.** After working through this notebook you can\n", "\n", "* compute a convolution by hand and predict the length of its full and valid parts;\n", "* read a filter's frequency response from its taps, and measure it by filtering sines;\n", "* explain linear phase and group delay, and predict the delay of a symmetric FIR filter;\n", "* design a windowed-sinc low-pass filter and check it against SciPy." ] }, { "cell_type": "code", "execution_count": null, "id": "c001", "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import scipy.signal as ss\n", "\n", "import audio_samples as aus\n", "\n", "rng = np.random.default_rng(seed=2026)\n", "F64 = np.dtype(\"float64\")\n", "WT = aus.WindowType\n", "FS = 16_000\n", "\n", "def mono(v, fs=FS):\n", " return aus.AudioSamples.new_mono(np.asarray(v, dtype=float), sample_rate=fs)" ] }, { "cell_type": "markdown", "id": "c002", "metadata": {}, "source": [ "## Concept\n", "\n", "**Convolution.** For an input $x[n]$ of $N$ samples and taps $h[k]$, $k = 0 \\dots M-1$ (the tap index; $j = \\sqrt{-1}$\n", "throughout):\n", "\n", "$$y[n] = \\sum_{k=0}^{M-1} h[k] \\, x[n - k]$$\n", "\n", "where $n$ is the output sample index, $M$ the number of taps and $x[\\cdot] = 0$ outside the\n", "signal. The **full** convolution has $N + M - 1$ samples ($n = 0 \\dots N + M - 2$). The **valid**\n", "part, where every term of the sum uses a real input sample, has $N - M + 1$ samples\n", "($n = M-1 \\dots N-1$).\n", "\n", "**Impulse response.** Filtering the unit impulse $\\delta[n]$ (1 at $n = 0$, 0 elsewhere) returns\n", "$y[n] = h[n]$: the taps *are* the impulse response.\n", "\n", "**Frequency response.** A complex exponential at angular frequency $\\omega = 2\\pi f / f_s$\n", "(radians per sample, $f$ in Hz, $f_s$ the sample rate in Hz) comes out multiplied by\n", "\n", "$$H(e^{j\\omega}) = \\sum_{k=0}^{M-1} h[k] \\, e^{-j\\omega k}$$\n", "\n", "so a sine of amplitude $A$ is output with amplitude $A\\,|H|$, shifted by the phase $\\arg H$. For the\n", "$M$-tap moving average $h[k] = 1/M$ this sums to the **Dirichlet kernel**\n", "\n", "$$|H(f)| = \\left| \\frac{\\sin(\\pi f M / f_s)}{M \\sin(\\pi f / f_s)} \\right|$$\n", "\n", "with nulls at every multiple of $f_s / M$ Hz (except 0).\n", "\n", "**Linear phase and group delay.** The group delay\n", "\n", "$$\\tau_g(\\omega) = -\\frac{d \\arg H(e^{j\\omega})}{d\\omega} = \\mathrm{Re}\\left\\{ \\frac{\\sum_k k\\,h[k]\\,e^{-j\\omega k}}{H(e^{j\\omega})} \\right\\}$$\n", "\n", "is the delay in samples of a narrow-band signal at $\\omega$. If the taps are symmetric,\n", "$h[k] = h[M-1-k]$, the phase is exactly $-\\omega (M-1)/2$ (plus jumps of $\\pi$ where $H$ changes\n", "sign), so **every frequency is delayed by the same $(M-1)/2$ samples** and waveform shapes are\n", "preserved. Asymmetric taps delay different frequencies by different amounts.\n", "\n", "**The four linear-phase types.** Linear phase needs symmetric taps, $h[k] = h[M-1-k]$, or\n", "antisymmetric ones, $h[k] = -h[M-1-k]$ (which add a constant $90°$ phase shift; same group delay).\n", "Together with odd or even $M$ that gives four types, each with zeros it cannot avoid:\n", "\n", "| Type | Taps | $M$ | Forced zeros | So it cannot be |\n", "|---|---|---|---|---|\n", "| I | symmetric | odd | none | (any response) |\n", "| II | symmetric | even | at Nyquist ($z = -1$) | high-pass |\n", "| III | antisymmetric | odd | at DC and Nyquist ($z = \\pm 1$) | low-pass or high-pass |\n", "| IV | antisymmetric | even | at DC ($z = 1$) | low-pass |\n", "\n", "**Windowed-sinc design.** The ideal low-pass with cutoff $f_c$ Hz has the infinitely long impulse\n", "response $h_{\\mathrm{ideal}}[n] = 2 (f_c/f_s)\\, \\mathrm{sinc}\\big(2 (f_c / f_s)\\, n\\big)$, with\n", "$\\mathrm{sinc}(u) = \\sin(\\pi u)/(\\pi u)$. Truncate it to $M$ taps centred on $(M-1)/2$, multiply\n", "by a window $w[n]$ (Hamming here) to reduce the ripples, and scale so that $\\sum_k h[k] = 1$ (unit\n", "gain at DC):\n", "\n", "$$h[n] = c \\; 2\\frac{f_c}{f_s}\\, \\mathrm{sinc}\\!\\left(2 \\frac{f_c}{f_s}\\left(n - \\frac{M-1}{2}\\right)\\right) w[n]$$\n", "\n", "where $c$ is the normalising constant. The response passes through about 0.5 ($-6$ dB) at $f_c$,\n", "and the transition band narrows as $M$ grows." ] }, { "cell_type": "markdown", "id": "c003", "metadata": {}, "source": [ "## With the library\n", "\n", "`AudioSamples.convolve(other)` returns the **full** convolution (both signals mono and of the\n", "same sample type). `AudioSamples.apply_filter(taps)` returns the **valid** part (what\n", "`numpy.convolve(x, h, 'valid')` gives), which is the slice `full[M-1:N]` of the full result." ] }, { "cell_type": "code", "execution_count": null, "id": "c004", "metadata": {}, "outputs": [], "source": [ "x = np.sin(0.05 * np.arange(1000))\n", "h = np.full(31, 1 / 31) # 31-tap moving average\n", "N, M = len(x), len(h)\n", "\n", "full = mono(x).convolve(mono(h)).to_numpy()\n", "valid = mono(x).apply_filter(h).to_numpy()\n", "assert np.array_equal(valid, full[M - 1: N]) or np.allclose(valid, full[M - 1: N], atol=1e-12)\n", "assert len(full) == 1030 # N + M - 1\n", "assert len(valid) == 970 # N - M + 1\n", "# NumPy and SciPy agree (rounding of 31-term sums: ~1e-15).\n", "assert np.allclose(full, np.convolve(x, h), atol=1e-12)\n", "assert np.allclose(valid, np.convolve(x, h, mode=\"valid\"), atol=1e-12)\n", "assert np.allclose(valid, ss.lfilter(h, 1.0, x)[M - 1:], atol=1e-12)\n", "assert np.allclose(ss.lfilter(h, 1.0, x), full[:N], atol=1e-12) # lfilter = first N samples\n", "\n", "# Filtering an impulse returns the taps.\n", "delta = np.zeros(64)\n", "delta[0] = 1.0\n", "ir = mono(delta).convolve(mono(h)).to_numpy()\n", "assert np.allclose(ir[:31], h, atol=1e-12) and np.allclose(ir[31:], 0.0, atol=1e-12)\n", "\n", "# The explainer classifies the taps and reports their delay.\n", "doc = aus.explain.fir(h, 16_000.0)\n", "assert doc.quantity(\"Group delay\") == 15.0 # (31 - 1) / 2\n", "assert abs(doc.quantity(\"DC gain\") - 1.0) < 1e-12" ] }, { "cell_type": "markdown", "id": "c005", "metadata": {}, "source": [ "The moving-average response, measured by filtering sines. One second of valid output ($f_s$\n", "samples) holds a whole number of cycles of each test tone, so projecting the output on $\\sin$ and\n", "$\\cos$ recovers its amplitude exactly." ] }, { "cell_type": "code", "execution_count": null, "id": "c006", "metadata": {}, "outputs": [], "source": [ "def filter_valid(x, h, fs=FS):\n", " # The valid part of the convolution computed by the library.\n", " return mono(x, fs).apply_filter(np.asarray(h, dtype=float)).to_numpy()\n", "\n", "def measured_gain(h, f, fs):\n", " n = np.arange(int(fs) + len(h) - 1) # so the valid output is exactly fs samples\n", " y = filter_valid(np.sin(2 * np.pi * f * n / fs), h, int(fs))\n", " phi = 2 * np.pi * f * np.arange(len(y)) / fs\n", " return 2 / fs * np.hypot(np.sum(y * np.sin(phi)), np.sum(y * np.cos(phi)))\n", "\n", "ma = np.full(8, 1 / 8)\n", "fs8 = 8_000.0\n", "for f, expected in [(250.0, 0.901764), (500.0, 0.640729), (750.0, 0.304489), (1500.0, 0.224994)]:\n", " u = np.pi * f / fs8\n", " dirichlet = abs(np.sin(8 * u) / (8 * np.sin(u)))\n", " g = measured_gain(ma, f, fs8)\n", " print(f\"{f:6.0f} Hz: measured {g:.6f}, Dirichlet {dirichlet:.6f}\")\n", " assert abs(g - dirichlet) < 1e-9 # exact up to rounding\n", " assert abs(g - expected) < 1e-6\n", "# Nulls at multiples of fs / M = 1000 Hz.\n", "for f in [1000.0, 2000.0, 3000.0]:\n", " assert measured_gain(ma, f, fs8) < 1e-9" ] }, { "cell_type": "code", "execution_count": null, "id": "c007", "metadata": {}, "outputs": [], "source": [ "w_, H_ = ss.freqz(ma, worN=2048, fs=fs8)\n", "f_test = np.array([250.0, 500.0, 750.0, 1000.0, 1500.0, 2000.0, 3000.0])\n", "fig, ax = plt.subplots(figsize=(8, 3))\n", "ax.plot(w_, np.abs(H_), label=\"|H(f)| from the taps (freqz)\")\n", "ax.plot(f_test, [measured_gain(ma, f, fs8) for f in f_test], \"o\", label=\"measured with sines\")\n", "ax.set(xlabel=\"Frequency (Hz)\", ylabel=\"Gain\", title=\"8-tap moving average at 8 kHz\")\n", "ax.legend()\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "c008", "metadata": {}, "source": [ "## How it works\n", "\n", "The convolution sum, a group-delay calculation, and the delay seen in the time domain, all for a\n", "63-tap windowed-sinc low-pass ($f_c = 2$ kHz, $f_s = 16$ kHz) designed here, since the library has\n", "no FIR designer. SciPy's `firwin` is the independent reference: it builds exactly this design\n", "(symmetric Hamming window, unit DC gain)." ] }, { "cell_type": "code", "execution_count": null, "id": "c009", "metadata": {}, "outputs": [], "source": [ "def windowed_sinc(m, fc, fs):\n", " n = np.arange(m) - (m - 1) / 2\n", " wc = 2 * fc / fs\n", " h = wc * np.sinc(wc * n) * WT.make_hamming(m)\n", " return h / h.sum()\n", "\n", "def convolve_full(x, h):\n", " # The convolution sum, written out.\n", " y = np.zeros(len(x) + len(h) - 1)\n", " for k, hk in enumerate(h):\n", " y[k: k + len(x)] += hk * x\n", " return y\n", "\n", "def group_delay(h, omega):\n", " k = np.arange(len(h))\n", " e = np.exp(-1j * omega * k)\n", " return (np.sum(k * h * e) / np.sum(h * e)).real\n", "\n", "lp = windowed_sinc(63, 2000.0, 16_000.0)\n", "assert np.allclose(lp, lp[::-1], rtol=0, atol=1e-15) # symmetric (to rounding)\n", "assert np.allclose(lp, ss.firwin(63, 2000.0, window=\"hamming\", fs=16_000), atol=1e-15)\n", "\n", "# Direct sum versus the library: the same numbers up to the last bits of rounding.\n", "xx = np.sin(0.05 * np.arange(1000)) + 0.3 * np.cos(0.71 * np.arange(1000))\n", "assert np.allclose(convolve_full(xx, lp), mono(xx).convolve(mono(lp)).to_numpy(), atol=1e-12)\n", "\n", "# Linear phase: 31 samples of delay at every passband frequency ...\n", "for f in [100.0, 500.0, 1000.0, 1500.0]:\n", " assert abs(group_delay(lp, 2 * np.pi * f / 16_000) - 31.0) < 1e-9\n", "# ... SciPy agrees ...\n", "_, gd = ss.group_delay((lp, [1.0]), w=[100.0, 1000.0], fs=16_000)\n", "assert np.allclose(gd, 31.0, atol=1e-6)\n", "# ... but not for asymmetric taps: 0.7 samples at DC, 0.25 at Nyquist.\n", "skew = np.array([0.5, 0.3, 0.2])\n", "assert abs(group_delay(skew, 0.0) - 0.7) < 1e-12\n", "assert abs(group_delay(skew, np.pi) - 0.25) < 1e-12" ] }, { "cell_type": "code", "execution_count": null, "id": "c010", "metadata": {}, "outputs": [], "source": [ "# Measured with a delayed impulse: impulse at n = 100 -> peak at 100 + 31 in the full output ...\n", "d = np.zeros(400)\n", "d[100] = 1.0\n", "assert np.argmax(mono(d).convolve(mono(lp)).to_numpy()) == 131\n", "# ... and at 131 - 62 = 69 in the valid part (its index i is time i + M - 1).\n", "assert np.argmax(filter_valid(d, lp)) == 69\n", "\n", "# And with a smooth pulse: its centroid moves by exactly (M - 1)/2 = 31.\n", "pulse = np.exp(-((np.arange(400) - 150) / 12) ** 2 / 2)\n", "centroid = lambda v: np.sum(np.arange(len(v)) * v) / np.sum(v)\n", "assert abs(centroid(convolve_full(pulse, lp)) - centroid(pulse) - 31.0) < 1e-9\n", "\n", "# The magnitude response, evaluated from the taps (the DTFT), and SciPy's freqz.\n", "def gain(h, f, fs=16_000.0):\n", " return abs(np.sum(h * np.exp(-2j * np.pi * f / fs * np.arange(len(h)))))\n", "\n", "db = lambda g: 20 * np.log10(g)\n", "for f in [500.0, 1000.0, 1500.0]:\n", " assert abs(db(gain(lp, f))) < 0.05 # pass band flat to 0.05 dB (max 0.03 dB)\n", "assert abs(gain(lp, 2000.0) - 0.5005) < 1e-4 # -6.01 dB at the cutoff\n", "assert abs(db(gain(lp, 2000.0)) - (-6.01)) < 0.005\n", "for f in [3000.0, 4000.0, 6000.0]:\n", " assert db(gain(lp, f)) < -59.0 # stop band below -59 dB from 3 kHz\n", "_, Hz = ss.freqz(lp, worN=[2000.0, 4000.0], fs=16_000)\n", "assert np.allclose(np.abs(Hz), [gain(lp, 2000.0), gain(lp, 4000.0)], atol=1e-12)" ] }, { "cell_type": "code", "execution_count": null, "id": "c011", "metadata": {}, "outputs": [], "source": [ "f_ax, H_lp = ss.freqz(lp, worN=4096, fs=16_000)\n", "fig, axes = plt.subplots(1, 2, figsize=(8, 3))\n", "axes[0].stem(np.arange(63), lp)\n", "axes[0].set(xlabel=\"Tap index k\", ylabel=\"h[k]\", title=\"63-tap windowed sinc\")\n", "axes[1].plot(f_ax, 20 * np.log10(np.abs(H_lp) + 1e-12))\n", "axes[1].axvline(2000, ls=\":\", c=\"k\")\n", "axes[1].set(xlabel=\"Frequency (Hz)\", ylabel=\"Gain (dB)\", ylim=(-100, 5), title=\"Response (fc = 2 kHz)\")\n", "fig.tight_layout()\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "c012", "metadata": {}, "source": [ "The same holds for long filters: a 201-tap design convolved by the library agrees with the direct\n", "sum to better than $10^{-12}$." ] }, { "cell_type": "code", "execution_count": null, "id": "c013", "metadata": {}, "outputs": [], "source": [ "lp201 = windowed_sinc(201, 2000.0, 16_000.0)\n", "noise = rng.standard_normal(4000)\n", "assert np.allclose(mono(noise).convolve(mono(lp201)).to_numpy(), convolve_full(noise, lp201), atol=1e-12)" ] }, { "cell_type": "markdown", "id": "c014", "metadata": {}, "source": [ "## Ask the library to explain\n", "\n", "`aus.explain.fir(taps, sample_rate)` classifies the taps (linear-phase types I-IV), reports the\n", "group delay, DC and Nyquist gains and a small response table, and notes when `apply_filter`\n", "switches to FFT convolution (from 160 taps):" ] }, { "cell_type": "code", "execution_count": null, "id": "c015", "metadata": {}, "outputs": [], "source": [ "ma5 = aus.explain.fir([0.2] * 5, 16_000.0)\n", "assert ma5.quantity(\"Taps\") == 5\n", "assert ma5.quantity(\"Group delay\") == 2.0 # samples\n", "assert abs(ma5.quantity(\"Group delay (time)\") - 0.125) < 1e-12 # ms\n", "assert ma5.has_warning_containing(\"type I\")\n", "\n", "# Even length and symmetric: type II, forced zero at Nyquist.\n", "t2 = aus.explain.fir([0.25] * 4, 16_000.0)\n", "assert t2.has_warning_containing(\"type II\") and abs(t2.quantity(\"Nyquist gain\")) < 1e-12\n", "\n", "# Antisymmetric taps: type III (odd length) and type IV (even length), with their forced zeros.\n", "H_abs = lambda taps, w: abs(np.sum(np.asarray(taps) * np.exp(-1j * w * np.arange(len(taps)))))\n", "t3, t4 = [0.5, 0.0, -0.5], [0.5, -0.5]\n", "assert aus.explain.fir(t3, 16_000.0).has_warning_containing(\"type III\")\n", "assert aus.explain.fir(t4, 16_000.0).has_warning_containing(\"type IV\")\n", "assert H_abs(t3, 0.0) < 1e-12 and H_abs(t3, np.pi) < 1e-12 # zeros at DC and Nyquist\n", "assert H_abs(t4, 0.0) < 1e-12 and abs(H_abs(t4, np.pi) - 1.0) < 1e-12 # zero at DC only\n", "assert H_abs([0.25] * 4, np.pi) < 1e-12 # type II: zero at Nyquist\n", "\n", "# Asymmetric taps: no constant group delay, only its value at DC.\n", "sk = aus.explain.fir(skew, 16_000.0)\n", "assert sk.quantity(\"Group delay\") is None\n", "assert abs(sk.quantity(\"Group delay at DC\") - group_delay(skew, 0.0)) < 1e-12\n", "\n", "long = aus.explain.fir(np.full(200, 1 / 200), 16_000.0)\n", "assert long.has_warning_containing(\"FFT convolution\")\n", "assert aus.explain.fir(np.full(160, 1 / 160), 16_000.0).has_warning_containing(\"FFT convolution\")\n", "assert not aus.explain.fir(np.full(159, 1 / 159), 16_000.0).has_warning_containing(\"FFT convolution\")\n", "ma5" ] }, { "cell_type": "markdown", "id": "c016", "metadata": {}, "source": [ "## Exercises\n", "\n", "1. Where are the nulls (Hz, below Nyquist) of a 5-tap moving average at $f_s = 10$ kHz? Check\n", " them by filtering sines." ] }, { "cell_type": "code", "execution_count": null, "id": "c017", "metadata": {}, "outputs": [], "source": [ "answer = None # TODO" ] }, { "cell_type": "code", "execution_count": null, "id": "c018", "metadata": { "tags": [ "solution" ] }, "outputs": [], "source": [ "# Solution\n", "answer = [k * 10_000 / 5 for k in (1, 2)] # multiples of fs / M below 5 kHz\n", "assert answer == [2000.0, 4000.0]\n", "ma_5 = np.full(5, 0.2)\n", "for f in answer:\n", " y = filter_valid(np.sin(2 * np.pi * f * np.arange(10_004) / 10_000), ma_5, 10_000) # 10 000 outputs\n", " assert np.max(np.abs(y)) < 1e-12\n", "assert gain(ma_5, 1000.0, 10_000.0) > 0.5 # but not in between" ] }, { "cell_type": "markdown", "id": "c019", "metadata": {}, "source": [ "2. You low-pass 1 s of 16 kHz audio with the 63-tap filter above and keep the valid part. How\n", " many samples come out, and which input sample $x[i + d]$ is output sample $i$ aligned with?\n", " (`answer = (length, d)`.) Check with a 100 Hz sine." ] }, { "cell_type": "code", "execution_count": null, "id": "c020", "metadata": {}, "outputs": [], "source": [ "answer = None # TODO" ] }, { "cell_type": "code", "execution_count": null, "id": "c021", "metadata": { "tags": [ "solution" ] }, "outputs": [], "source": [ "# Solution\n", "answer = (16_000 - 62, 31) # output i is the causal output at time i + 62, which lags by 31\n", "xs = np.sin(2 * np.pi * 100 * np.arange(16_000) / 16_000)\n", "y = filter_valid(xs, lp)\n", "assert len(y) == answer[0]\n", "# At 100 Hz the gain is 1.0012 (pass-band ripple), so the aligned samples agree to ~1.2e-3.\n", "assert abs(gain(lp, 100.0) - 1.0012) < 1e-4\n", "assert np.max(np.abs(y - xs[answer[1]: answer[1] + len(y)])) < 2e-3" ] }, { "cell_type": "markdown", "id": "c022", "metadata": {}, "source": [ "3. *Spectral inversion*: $h_{hp}[n] = \\delta[n - (M-1)/2] - h_{lp}[n]$ turns the low-pass into a\n", " high-pass. Predict its gain at DC, at the 2 kHz cutoff and at 6 kHz, then measure." ] }, { "cell_type": "code", "execution_count": null, "id": "c023", "metadata": {}, "outputs": [], "source": [ "answer = None # TODO" ] }, { "cell_type": "code", "execution_count": null, "id": "c024", "metadata": { "tags": [ "solution" ] }, "outputs": [], "source": [ "# Solution\n", "answer = (0.0, 0.5, 1.0) # 1 - 1; |1 - 0.5| (same linear phase); 1 - (almost 0)\n", "hp = -lp.copy()\n", "hp[31] += 1.0\n", "assert gain(hp, 0.0) < 1e-12\n", "assert abs(gain(hp, 2000.0) - answer[1]) < 0.01\n", "assert abs(gain(hp, 6000.0) - answer[2]) < 1e-3\n", "hp_doc = aus.explain.fir(hp, 16_000.0)\n", "assert hp_doc.has_warning_containing(\"type I\") and hp_doc.quantity(\"Group delay\") == 31.0" ] }, { "cell_type": "markdown", "id": "c025", "metadata": {}, "source": [ "## Common pitfalls\n", "\n", "* `AudioSamples.convolve` returns the **full** convolution ($N + M - 1$ samples);\n", " `AudioSamples.apply_filter` returns the **valid** part ($M - 1$ samples shorter, output $i$ belongs to input\n", " time $i + M - 1$). Neither is delay-compensated: a linear-phase filter still lags by\n", " $(M-1)/2$.\n", "* `convolve` needs both signals mono and of the same sample type (generators default to\n", " `float32`; build taps with `new_mono` from a float64 array, or pass `dtype`).\n", "* Even-length symmetric filters (type II) always have a zero at Nyquist and cannot be high-pass;\n", " spectral inversion needs an odd length.\n", "* A windowed sinc is $-6$ dB (not $-3$ dB) at its design cutoff.\n", "* SciPy's `lfilter(h, 1, x)` returns the full-length causal output (the first $N$ samples of\n", " `convolve`); the valid part is `lfilter(h, 1, x)[M-1:]`. Compare like with like.\n", "* `low_pass_filter` / `high_pass_filter` / `band_pass_filter` are first-order IIR (Butterworth)\n", " filters, not FIR (notebook 06).\n", "\n", "## See also\n", "\n", "* Rust guide chapter: [05. Convolution and FIR filters](https://docs.rs/audio_samples/latest/audio_samples/guide/c05_convolution_fir/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_05_convolution_fir.rs`.\n", "* Python API: `AudioSamples.convolve`, `AudioSamples.apply_filter`, `AudioSamples.deconvolve`, `aus.impulse`,\n", " `aus.explain.fir` ([API reference](../api/audio_samples.rst)); SciPy: `scipy.signal.firwin`,\n", " `freqz`, `group_delay`.\n", "* Previous: [04. STFT and spectrograms](04_stft_spectrograms.ipynb).\n", " Next: [06. IIR filters](06_iir_filters.ipynb)." ] }, { "cell_type": "markdown", "id": "references", "metadata": {}, "source": [ "## References\n", "\n", "* Oppenheim, A. V. and Schafer, R. W. (2010). *Discrete-Time Signal Processing*, 3rd ed. Pearson. Chapters 5 and 7 (linear-phase systems and the four generalised linear-phase FIR types; FIR design by windowing)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }