<?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[📐 Sensor math that matters]]></title><description><![CDATA[<p dir="auto">Most firmware projects hit a wall that only maths solves — a sensor reading too noisy to use, a frequency that must be detected, a filter that needs tuning, a calculation that loses precision on a microcontroller with no FPU. This post is the practical core: no academic DSP, just the techniques that come up with real sensors.</p>
<h3>Sample fast enough, or lie to yourself</h3>
<p dir="auto">Nyquist: to represent bandwidth B you need fs &gt; 2B; anything above fs/2 folds back as a phantom: <code>f_alias = |f - k*fs|</code>.</p>
<ul>
<li>Thermal logger at fs = 10 Hz with 60 Hz mains hum coupled into the wiring → k=6 → |60-60| = 0 Hz. Your "temperature drift" is mains hum pretending to be DC.</li>
<li>100 Hz sampler with 130 Hz motor PWM residue → |130-100| = 30 Hz phantom. You chase a resonance that doesn't exist.</li>
<li>The engineering rule (not the textbook 2x): sample at 5–10x the highest frequency you must resolve, so your filter has room to roll off. Averaging <em>after</em> aliasing can't help — the fold already happened at the sampling instant. Anti-alias in analog (RC before the ADC) or by oversampling-then-filtering at high fs.</li>
</ul>
<h3>Smooth with the right tool</h3>
<ul>
<li><strong>Moving average (N):</strong> white noise drops by √N, lag ≈ N·T/2. General thermal and ADC cleanup (N = 16–64).</li>
<li><strong>Exponential (EMA):</strong> <code>y += alpha*(x-y)</code>, O(1) RAM. Display smoothing and tight loops.</li>
<li><strong>Median (odd N):</strong> kills spikes (WiFi bursts, brush clicks), preserves edges. Put it <em>before</em> averaging in spiky environments.</li>
<li><strong>Oversample + decimate:</strong> 4x oversampling buys roughly 1 extra bit (16x → +2 bits: sample 160 Hz, average 16, output 10 Hz). Needs real noise across 1 LSB to dither.</li>
<li><strong>Hysteresis/deadband:</strong> act only past ±band. Stops relay and fan chatter around thresholds.<br />
→ <a href="https://embiq.grapesiot.com/bonus/48-iot-data-acquisition-processing/chapter-02" rel="nofollow ugc">Sampling and signal conditioning for industrial sensors</a></li>
</ul>
<h3>Convert counts to units — with proof</h3>
<p dir="auto">Two-point calibration: take two raw/reference pairs, fit <code>T = a·counts + b</code>, then validate with a third point and record references, conditions, date, and stale-data behaviour (hold-last-good, never actuate on unvalidated samples). Sample on a stable timebase (<code>millis()</code> cadence with +=, not <code>delay()</code> drift under WiFi load).</p>
<p dir="auto">Takeaways: match the rate to the physics, filter in analog before digital, median-before-average for spikes, calibrate with numbers and an expiry date.</p>
<hr />
<p dir="auto"><em>Finish with <a href="https://embiq.grapesiot.com/foundation/05-sensors-actuators/chapter-05" rel="nofollow ugc">Sampling, noise and calibration</a> — the full treatment this primer is distilled from. Post your sensor, your rate, the filter you tried, and the numbers. Tag with <code>signal-processing</code>.</em></p>
]]></description><link>https://forum.grapesiot.com/topic/78/sensor-math-that-matters</link><generator>RSS for Node</generator><lastBuildDate>Thu, 19 Nov 2026 13:02:50 GMT</lastBuildDate><atom:link href="https://forum.grapesiot.com/topic/78.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 03 Oct 2026 11:29:42 GMT</pubDate><ttl>60</ttl></channel></rss>