Spectral Derivatives
Pavel Komarov · 2025
Read Spectral Derivatives by Pavel Komarov (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2506-06210.txt.
Introduction
Pavel Komarov wrote a document in two thousand twenty-five that sets out the math behind a Python package for spectral derivatives. Taking derivatives in the Fourier frequency domain is strikingly easy, a happy accident of mathematics. Using that fact on a computer, without creating artifacts, takes extra care and knowledge.
Komarov builds the needed background from the ground up. He touches on core signal processing and calculus ideas as they become necessary, then develops the spectral method step by step. The document serves as the theory guide for the package of the same name. Readers get both the formulas and the cautions that make them work in practice. It is a reference text, not a research report.
Catalog record
| CREATOR | Pavel Komarov |
|---|---|
| YEAR | 2025 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 76 KB |
| VERSION | 1.0 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2506-06210
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
Spectral Derivatives Pavel Komarov Abstract One of the happiest accidents in all math is the ease of transforming a function to and taking derivatives in the Fourier (i.e. the frequency ) domain. But in order to exploit this extraordinary fact without serious artefacting, and in order to be able to use a computer, we need quite a bit of extra knowledge and care. This document sets out the math behind the spectral-derivatives Python package, all the way down to the bones, as much as I can manage. I try to get in to the real whys behind what we’re doing here, touching on fundamental signal processing and calculus concepts as necessary, and building upwards to more general cases. 1 Bases A basis is a set of functions, call them \{\xi_{k}\} , that can be linearly combined to produce other functions. Often these are chosen to be orthogonal, meaning that if we take the “inner product” of one funtion from the set with itself, we get back a constant (often normalized to be 1), and if we take the inner product of one of these functions with a different member of the set, we get back 0. In this sense the members of an orthogonal basis set are like perpendicular directions on a graph. The inner product between two functions f and g is a generalization of the inner product between vectors, where instead of summing over a finite number of discrete entries, we integrate over infinitely many infinitesimally-separated points in the domain. We define it as: \langle f,g\rangle=\int\limits_{a}^{b}\overline{f(x)}g(x)dx where the overbar \overline{\circ} denotes a complex conjugate. The inner product is symmetrical, so \langle f,g\rangle=\langle g,f\rangle=\int\limits_{a}^{b}f(x)\overline{g(x)}dx Note that if we set a and b at \pm\infty , this integral could diverge. If it doesn’t diverge with infinite bounds, we say the argument is “Lebesgue integrable” [ 1 ] . Some of what we’ll do only makes sense for this class of functions, so be aware. 1.1 The Fourier Basis The most famous basis is the Fourier basis a , which is the set of complex exponentials: e^{j\omega x}=\cos(\omega x)+j\sin(\omega x) (1) where I use j to represent the imaginary unit ( \sqrt{-1} ), because I’m from Electrical Engineering, and because Python uses j . Why this identity is true isn’t obvious at first but can be seen by Taylor Expanding [ 3 ] the exponential function and trigonometric functions: e^{a}=1+a+\frac{a^{2}}{2!}+\frac{a^{3}}{3!}+...=\sum_{n=0}^{\infty}\frac{a^{n}}{n!} So e^{j\omega x}=1+j\omega x+\frac{(j\omega x)^{2}}{2!}+\frac{(j\omega x)^{3}}{3!}+...=1+j\omega x-\frac{(\omega x)^{2}}{2!}-j\frac{(\omega x)^{3}}{3!}+\frac{(\omega x)^{4}}{4!}-... \sin(\omega x)=\omega x-\frac{(\omega x)^{3}}{3!}+\frac{(\omega x)^{5}}{5!}-\frac{(\omega x)^{7}}{7!}+... \cos(\omega x)=1-\frac{(\omega x)^{2}}{2!}+\frac{(\omega x)^{4}}{4!}-\frac{(\omega x)^{6}}{6!}+... Notice all the even-power terms appear with alternating sign as in the cosine expansion, and the odd-power terms appear with alternating sign as in the sine expansion, but with an extra j multiplied in. The presence of complex numbers to make this work can be confusing at first, but don’t be scared! All we’re really doing is using a compressed representation of a sine plus a cosine, where the real and imaginary parts (orthogonal in the complex plane, and therefore independent and non-interfering) allow us to describe the contributions of sine and cosine simultaneously. In fact, Joseph Fourier originally used only real trigonometric functions [ 5 ] , and it wasn’t until later someone decided it would be easier to work with complex exponentials. Later ( subsection 2.1 ) we’ll see that for real signals all the complex numbers cancel, leaving only a real sine and real cosine, which when added together make a single, phase-shifted sinusoid! So think of e^{j\omega x} as oscillations of frequency \omega along direction x . If we inner product sinusoidal wiggles of mismatched frequency, differing by \Delta\omega , they misalign and integrate to 0 over a period of length T=\frac{2\pi}{\Delta\omega} . But if we inner product matched wiggles, they align, multiply to 1 because of the inner product’s complex conjugate, and integrate to a constant, the length of whichever domain we choose to consider, so this basis is orthogonal. 2 Transforms We can reconstruct a function from a linear combination of basis functions: f(x)=\sum_{k=0}^{M-1}c_{k}\xi_{k}(x),\quad x\in[a,b] (2) where M is the number of basis functions we’re using in our reconstruction and k iterates through them. This is essentially a recipe , which tells us how much of each basis function \xi_{k} is present in the signal f on a domain between a and b . We can find the quantities \{c_{k}\} by taking the inner product of the above with each of the basis functions to produce a system of M equations, then solving. In the special case where \{\xi_{k}\} are orthogonal, only one of the inner-producted terms from the sum will be nonzero, so the system’s equations untangle to yield the simple relationship: c_{k}=\frac{\langle\xi_{k},f\rangle}{\langle\xi_{k},\xi_{k}\rangle}=\frac{\int\limits_{a}^{b}f(x)\overline{\xi_{k}(x)}dx}{||\xi_{k}||_{2}^{2}} (3) The set of numbers \{c_{k}\} is now an alternative representation of the original function. In some sense it’s equally descriptive, so long as we know which basis we’re using to reconstruct. The function has been transformed , completely analogous to changing coordinate systems in linear algebra, where we can express vector \vec{f} in terms of a new orthogonal basis (\vec{\xi}_{0},\vec{\xi}_{1}) instead of axis-aligned unit vectors (\vec{e}_{0},\vec{e}_{1}) via \vec{f}=\frac{\langle\vec{\xi}_{0},\vec{f}\rangle}{||\vec{\xi}_{0}||_{2}^{2}}\vec{\xi}_{0}+\frac{\langle\vec{\xi}_{1},\vec{f}\rangle}{||\vec{\xi}_{1}||_{2}^{2}}\vec{\xi}_{1} : \vec{e}_{0} \vec{e}_{1} \vec{f} \vec{\xi}_{0} \vec{\xi}_{1} \mathrm{proj}_{\vec{\xi}_{0}}\vec{f} \mathrm{proj}_{\vec{\xi}_{1}}\vec{f} The \{c_{k}\} are often said to live in another “domain”, although we have to be careful with this terminology, because it technically refers to a “connected” set, not just a collection of M things. To be precise, some authors instead use “series” to describe \{c_{k}\} . However, it is possible for members of the basis set to be related through a continuous parameter which in some sense makes the set dense, even in cases where we only take discrete members of this more general set to be our basis set for a particular scenario. This is the case for the Fourier basis, where we choose \omega\in\mathbb{R} , and hence \omega really can become a new domain. 2.1 The Fourier Transform Using Fourier’s original real-sinusoid-based formulation, we can write the reconstruction expression as * * * It’s worth considering how weird it is this works to express arbitrary functions, even non-smooth ones (so long as they meet the Dirichlet conditions [ 4 ] , i.e. aren’t pathological cases), a fact so counter-intuitive that Joseph Lagrange publicly declared Fourier was wrong at a meeting of the Paris Academy in 1807 [ 6 ] and rejected Fourier’s paper, which then went unpublished until after Lagrange died! [ 4 ] It’s valuable to ask why this works [ 7 ] and sift through some analysis . [ 8 ] : f(x)=a_{0}+\sum_{k=1}^{\infty}(a_{k}\cos(k\omega_{0}x)+b_{k}\sin(k\omega_{0}x)) where • f is periodic with fundamental frequency \omega_{0} , so the k^{th} frequency becomes k\cdot\omega_{0} . • a_{k} and b_{k} are coefficients describing how much cosine and sine to add in, respectively. • k goes up to \infty because in general we need an infinite number of ever-higher-frequency sinusoids to reconstruct the function with perfect fidelity. Let’s now use \cos(x)=\frac{e^{jx}+e^{-jx}}{2} and \sin(x)=\frac{e^{jx}-e^{-jx}}{2j} , which can be verified by manipulating Euler’s formula, Equation 1 . \displaystyle f(x) \displaystyle=a_{0}+\sum_{k=1}^{\infty}(a_{k}\frac{e^{jk\omega_{0}x}+e^{-jk\omega_{0}x}}{2}+b_{k}\frac{e^{jk\omega_{0}x}-e^{-jk\omega_{0}x}}{2j}) \displaystyle=a_{0}+\sum_{k=-\infty}^{-1}(\frac{a_{-k}}{2}-\frac{b_{-k}}{2j})e^{jk\omega_{0}x}+\sum_{k=1}^{\infty}(\frac{a_{k}}{2}+\frac{b_{k}}{2j})e^{jk\omega_{0}x}=\sum_{k=-\infty}^{\infty}c_{k}e^{jk\omega_{0}x} So if we choose c_{0}=a_{0} and c_{k}=\overline{c_{-k}}=\frac{a_{k}}{2}+\frac{b_{k}}{2j} , then the complex exponential formulation is exactly equivalent to the trigonometric formulation [ 9 ] . That is, we can evaluate Equation 3 using the complex exponentials as basis