<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CliDeck Research Notes]]></title><description><![CDATA[CliDeck Research Notes]]></description><link>https://clideckresearch.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 24 Oct 2026 14:44:11 GMT</lastBuildDate><atom:link href="https://clideckresearch.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Exact RMS, Missed Troughs: A Sampling Trap in Python]]></title><description><![CDATA[A reproducible cosine-wave example shows how exact RMS can coexist with a missed trough, and derives a practical discretization bound.]]></description><link>https://clideckresearch.hashnode.dev/exact-rms-missed-troughs-a-sampling-trap-in-python</link><guid isPermaLink="true">https://clideckresearch.hashnode.dev/exact-rms-missed-troughs-a-sampling-trap-in-python</guid><category><![CDATA[Mathematics]]></category><category><![CDATA[Python]]></category><category><![CDATA[Signal Processing]]></category><category><![CDATA[audio]]></category><dc:creator><![CDATA[Valentyn Miloserdov]]></dc:creator><pubDate>Sun, 18 Oct 2026 19:39:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6ad51e9f0fdedfe13f6c3362/73181ed9-085a-40d3-a329-369bda653c85.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Taking min(samples) is a tempting shortcut when building a waveform display. A twelve-harmonic example shows exactly what that shortcut can miss: 25 samples reproduce the signal’s RMS perfectly, yet the continuous negative peak is more than six times the depth suggested by the lowest sample.</p>
<p><em>This article, its supporting code, and its mathematical checks were prepared with substantial assistance from ChatGPT. It has not undergone external peer review.</em></p>
<p>The question grew out of work on <a href="https://bassplus.clideck.com/">Bass Plus</a>, our macOS audio app, and the accompanying Mathematics of Sound project. The example below is an ideal mathematical signal. It is not a measurement of the app or a claim that this estimator is implemented in it.</p>
<h2>A small model with a useful distinction</h2>
<p>Imagine adding several cosine waves. Each has amplitude one, starts with zero phase, and completes an integer number of cycles during a shared period. For a nonempty set A of distinct positive integer frequencies, write</p>
<p>$$
f_A(x)=\sum_{a\in A}\cos(ax).
$$</p>
<p>Here x is phase, measured in radians. To turn it into a time variable, use x = 2πν₀t, where ν₀ is a base frequency in hertz. The values of f are normalized amplitudes, not decibels.</p>
<p>Two different measurements matter. RMS describes the square root of the average squared amplitude. The negative peak describes how far the lowest point falls below zero. Define its depth as</p>
<p>$$
K(A)=-\min_{0\le x\le2\pi} f_A(x).
$$</p>
<p>Fourier orthogonality gives a mean of zero and an RMS of √(N/2), where N is the number of frequencies. RMS therefore depends only on the number of unit-amplitude components in this model. The negative peak also depends on which frequencies are present.</p>
<p>For example, the sets {1, 2} and {1, 3} both have RMS 1. Their negative depths are 9/8 and 2 respectively. The first follows by writing cos x + cos 2x as 2(cos x + 1/4)² − 9/8. The second reaches −2 at x = π.</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6ad51e9f0fdedfe13f6c3362/9376834c-0c76-45b3-bfda-ef8651c6d19e.png" alt="Two pairs of cosine waves have the same RMS of one but negative depths of 1.125 and 2." /></p>
<p><strong>Figure 1. Equal RMS, different troughs.</strong> The curves have identical average squared amplitude. Their lowest values differ. The plotted curves are numerical renderings; both stated depths follow from the exact calculations above. Plotting code was prepared with AI assistance.</p>
<p>For an acoustic-pressure interpretation, a negative value means a pressure deviation below equilibrium; it does not mean negative energy. This example also concerns the negative peak specifically. Both signals reach the positive value 2, so their maximum absolute amplitudes are identical.</p>
<h2>Twenty-five samples that conceal a deeper trough</h2>
<p>Now take every frequency from 1 through N and put q = 2N + 1 equally spaced samples around one period. Include phase zero, and do not duplicate the endpoint at 2π:</p>
<p>$$
f_N(x)=\sum_{a=1}^{N}\cos(ax),\qquad x_j=\frac{2\pi j}{q},\quad 0\le j&lt;q.
$$</p>
<p>At phase zero all components equal one, so the sample is N. Every other sample is exactly −1/2. One way to see this is to sum the q complex roots of unity and pair each root with its conjugate. Equivalently, use the finite Dirichlet-kernel identity</p>
<p>$$
1+2f_N(x)=\frac{\sin(qx/2)}{\sin(x/2)}.
$$</p>
<p>At every nonzero grid point the numerator is zero. The removable singularity at phase zero has the value 2N + 1.</p>
<p>Choose N = 12. The recorded values are 12 once, followed by twenty-four values of −0.5. Their mean is zero, and their mean square is (144 + 24 × 0.25)/25 = 6. Their RMS is therefore √6, about 2.44949: exactly the RMS of the continuous signal.</p>
<p>But look halfway between the first and second nonzero sample positions, at x = 3π/25. The numerator of the identity is −1. The depth at this particular point is</p>
<p>$$
-f_N(3\pi/q)=\frac{1}{2}+\frac{1}{2\sin(3\pi/(2q))}.
$$</p>
<p>For q = 25, that is about 3.16836. A separate exact rational calculation bounds the true continuous depth between 3.2301038754 and 3.2301038755. The marked point is a convenient witness of a missed trough; it is not the exact minimizer.</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6ad51e9f0fdedfe13f6c3362/73181ed9-085a-40d3-a329-369bda653c85.png" alt="The continuous twelve-harmonic signal drops below its sampled minimum of minus one half; a marked off-grid witness has value approximately minus 3.16836." /></p>
<p><strong>Figure 2. The curve between the samples.</strong> The sample markers and the off-grid witness represent different evaluations of the same function. The witness already proves that the sample minimum is insufficient. The exact global-depth check uses a separate polynomial calculation. Plotting code was prepared with AI assistance.</p>
<p>This gap is not restricted to twelve components. Since sin u ≤ u for positive u, the witness depth is at least 1/2 + q/(3π). It grows with N, while the negative depth inferred from the original grid remains 1/2. These are unnormalized sums: their total RMS also grows as more components are added.</p>
<h2>The samples contain the information</h2>
<p>There is no contradiction with signal reconstruction. A trigonometric polynomial of known degree at most N is uniquely determined by these 2N + 1 samples. Discrete Fourier orthogonality recovers its coefficients.</p>
<p>In physical units, the sample rate is (2N + 1)ν₀, above twice the highest frequency Nν₀. The problem is the operation applied after sampling: taking the smallest recorded value does not minimize the reconstructed curve.</p>
<p>A display that joins the dots with straight lines can consequently give the wrong impression of the trough. Reconstructing the known polynomial, then finding its minimum with a controlled calculation, answers a different and more demanding question.</p>
<p>There is another useful experiment. Move the entire grid by a fraction δ of one sample spacing, using xⱼ = 2π(j + δ)/q. The sampled minimum changes. The sampled RMS remains exactly √6 for every shift in this example: squaring the polynomial produces no frequency as high as q, so averaging over the shifted grid still cancels all nonconstant terms.</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6ad51e9f0fdedfe13f6c3362/20c63af3-0fc7-4dfc-908f-c3d9b52d2959.png" alt="Moving the twenty-five-point sampling grid changes the observed negative peak, while the sampled RMS stays equal to the continuous RMS." /></p>
<p><strong>Figure 3. Move the measuring grid, keep the waveform.</strong> The offset runs through one sample spacing; offsets zero and one describe the same grid. RMS agreement is exact. The changing sampled-minimum curve is evaluated numerically. Plotting code was prepared with AI assistance.</p>
<p>The positive peak of the original signal is N at phase zero, and the original grid captures it. This construction demonstrates a missed negative trough; it does not demonstrate a missed maximum absolute peak or an audible defect in an audio product.</p>
<h2>Put an error interval around the estimate</h2>
<p>The general model also permits a simple bound. On an M-point uniform grid, let Kₘ be the negative of the sample minimum. Define S₁ as the sum of the frequencies and S₂ as the sum of their squares. Then</p>
<p>$$
K_M\le K(A)\le K_M+E_M,
$$</p>
<p>$$
E_M=\min\left(\frac{\pi S_1}{M},\frac{\pi^2S_2}{2M^2}\right).
$$</p>
<p>Why does this work? Every phase lies within π/M of a grid point. The derivative has magnitude at most S₁, which bounds the change in amplitude over that distance. At a true minimum the first derivative vanishes; Taylor’s theorem and the second-derivative bound S₂ give the second, quadratic estimate. Both bounds are valid, so we can use the smaller one.</p>
<p>The bound applies to any finite frequency set in this model, and also to a shifted uniform grid. It is conservative. For a fixed set, doubling M reduces the quadratic allowance by a factor of four; it does not guarantee that every observed error decreases by exactly that factor. On a very coarse grid, Kₘ can even be negative, so the definition matters.</p>
<p><img src="https://cdn.hashnode.com/uploads/covers/6ad51e9f0fdedfe13f6c3362/f64a6446-fe62-4ed0-8505-de7edd2d987f.png" alt="Intervals computed from increasing grid sizes enclose the known exact depth of nine eighths for the two-frequency signal." /></p>
<p><strong>Figure 4. An estimate with a stated allowance.</strong> For A = {1, 2}, the exact answer is 9/8. Each interval starts at the sampled estimate and adds the analytic discretization bound. Its displayed endpoints are floating-point approximations of mathematical bounds. Plotting code was prepared with AI assistance.</p>
<h2>Try the calculation</h2>
<p>This small example uses only the Python standard library:</p>
<pre><code class="language-python">from math import cos, pi

A, M = (1, 2), 32
samples = [sum(cos(2*pi*a*j/M) for a in A) for j in range(M)]
k_grid = -min(samples)
s1, s2 = sum(A), sum(a*a for a in A)
error = min(pi*s1/M, pi*pi*s2/(2*M*M))

print(f"Approximate interval: [{k_grid:.9f}, {k_grid + error:.9f}]")
print("Exact depth for this example: 9/8 = 1.125")
</code></pre>
<p>The approximate interval is [1.118969855, 1.143065568]. It contains 1.125, as the analytic argument predicts.</p>
<p>There are two sources of error to distinguish here: missing a minimum between grid points, and rounding while evaluating numbers. The formula controls the first. Ordinary floating-point cosine evaluations do not automatically certify the second. A machine-certified interval needs justified evaluation-error bounds and outward rounding, or an exact alternative such as the rational polynomial check supplied with this article.</p>
<h2>What to carry into an audio interface</h2>
<p>A useful analysis display can show the sampled minimum, identify any reconstructed curve, and state an error allowance when one is available. A slider that moves the sample grid makes the distinction visible without changing the underlying waveform. The axes should retain the same amplitude scale throughout the interaction.</p>
<p>This is an educational example using equal-amplitude integer harmonics. It does not establish how arbitrary music, different phases, a playback device, or a processing chain behaves. It also does not resolve the open cosine-sum question that motivated the wider project. Its practical contribution is narrower: a correct average can coexist with a poor extremum estimate, and a small amount of analysis can make that uncertainty explicit.</p>
<p>For an implementation, make the distinction explicit in the data model: a sample statistic, a reconstructed extremum, and a justified error interval are three different outputs. The small exact examples here can serve as useful reference cases when checking such a display.</p>
<h3>Attribution and reproducibility</h3>
<p>The Fourier-series and Parseval background is standard; see the <em>NIST Digital Library of Mathematical Functions</em>, §1.8. The Chebyshev identity Tₙ(cos x) = cos(nx), used in the accompanying exact polynomial check, is given in §18.5, equation 18.5.1. These classical tools and the elementary bounds above are not claimed as new discoveries.</p>
<p>The <a href="https://bassplus.clideck.com/mathematics-of-sound/downloads/bassplus_sampling_reproducibility.zip">reproducibility files</a> contain the plotting code, the standard-library demonstration, and an exact rational verifier. The verifier forms the polynomial sum of T₁ through T₁₂, isolates every critical point using Sturm’s theorem, and bounds their values. This checks the twelve-component example; it is not external peer review or proof-assistant formalization.</p>
<p><em>Project affiliation: CliDeck Research Notes, Mathematics of Sound. This is educational material authored for the project that motivated the investigation.</em></p>
]]></content:encoded></item></channel></rss>