signal-processing-dsp-basics
Foundations of digital signal processing — sampling, aliasing, the Nyquist criterion, quantization, convolution, the discrete Fourier transform, FFT, FIR and IIR filter design, windowing, spectral leakage, and practical issues in fixed-point versus floating-point implementation. Use when designing filters, analyzing spectra, choosing sample rates, reasoning about aliasing, or implementing DSP algorithms on a microcontroller, DSP chip, or host CPU.
git clone --depth 1 https://github.com/Tibsfox/gsd-skill-creator /tmp/signal-processing-dsp-basics && cp -r /tmp/signal-processing-dsp-basics/examples/skills/electronics/signal-processing-dsp-basics ~/.claude/skills/signal-processing-dsp-basicsSKILL.md
# Signal Processing: DSP Basics
Digital signal processing is what happens after an ADC and before a DAC — or inside the world of purely discrete-time signals like audio files, sensor logs, and computed waveforms. The core ideas of DSP are deceptively simple (sample, add, multiply, feed back) but the traps are numerous (aliasing, leakage, numerical underflow, phase distortion, quantization noise). This skill covers the fundamentals every embedded or systems engineer needs to avoid making expensive analog problems digital.
**Agent affinity:** shima (DSP architecture and fixed-point implementation), horowitz (intuition and practical filter examples)
**Concept IDs:** elec-data-conversion-dsp, elec-signal-ac-analysis
## Sampling and the Nyquist Criterion
A continuous-time signal x(t) is sampled by taking its value at evenly spaced instants T_s apart, producing the discrete-time sequence x[n] = x(n * T_s). The sample rate f_s = 1 / T_s.
**The Nyquist-Shannon sampling theorem.** A band-limited signal whose frequency content is strictly below f_s / 2 can be perfectly reconstructed from its samples. Any frequency content above f_s / 2 gets aliased — folded back into the band from 0 to f_s / 2 — and becomes indistinguishable from legitimate signal content at the aliased frequency.
**The critical corollary.** The sample rate must be at least twice the highest frequency of interest. For audio at up to 20 kHz, the minimum is 40 kHz (compact disc uses 44.1 kHz, professional audio 48 or 96 kHz). For a temperature sensor whose highest frequency of interest is 1 Hz, 10 Hz is plenty.
**Anti-aliasing filters.** Before the ADC, an analog low-pass filter must attenuate everything above f_s / 2 below the noise floor of the ADC. No amount of post-processing can undo aliasing; once two frequencies fold onto each other, they are indistinguishable.
## Technique 1 — Quantization
An ADC represents each sample as one of 2^N levels, where N is the bit depth. The rounding error at each sample is a **quantization error**, uniformly distributed in the interval (-q/2, q/2) where q is the step size. Its RMS value is q / sqrt(12), and the resulting signal-to-quantization-noise ratio (SQNR) is approximately 6.02 * N + 1.76 dB.
**Practical numbers:**
| Bits | SQNR (dB) |
|---|---|
| 8 | 50 |
| 10 | 62 |
| 12 | 74 |
| 16 | 98 |
| 24 | 146 |
16-bit audio provides about 98 dB of dynamic range, which is near the limit of what consumer headphones can resolve. 24-bit audio is used in professional recording for headroom, not because the last eight bits are audible.
**Dithering.** Adding a small amount of random noise before quantization decorrelates the quantization error from the signal, trading distortion for noise. This is why 16-bit masters sound better than naive 16-bit truncation of a 24-bit original.
## Technique 2 — The Discrete Fourier Transform
The DFT of a length-N sequence x[n] is:
X[k] = sum over n=0..N-1 of x[n] * exp(-j * 2π * k * n / N)
It represents the sequence as a sum of N complex exponentials at frequencies k * f_s / N. The magnitude |X[k]| shows how much energy is at each frequency; the phase shows the relative timing.
**The FFT.** The fast Fourier transform is an O(N log N) algorithm for computing the DFT; the naive computation is O(N^2). For N = 1024 the FFT is 100x faster, and the ratio grows with N.
**Worked example.** A 1024-sample buffer sampled at 48 kHz has frequency resolution 48000 / 1024 ≈ 46.9 Hz per bin. Bin k = 100 corresponds to 4.69 kHz. To resolve adjacent musical notes near 440 Hz (about 26 Hz apart between half-steps), a longer window is needed — e.g., 4096 samples gives 11.7 Hz resolution.
**Real vs complex.** A real-valued signal has conjugate-symmetric FFT: X[N-k] = conj(X[k]). Only the first N/2 + 1 bins carry independent information. DSP libraries provide real-FFT variants that exploit this for 2x speedup.
## Technique 3 — Windowing and Spectral Leakage
The DFT implicitly assumes the sequence is periodic with period N. If the actual signal is not an integer number of cycles in the window, the discontinuity at the boundary spreads energy across all frequency bins — **spectral leakage**.
**Windowing** multiplies the sequence by a tapered function that smoothly decays to zero at both ends of the buffer, suppressing the boundary discontinuity. Common windows:
| Window | Main lobe width | Side lobe level | Use |
|---|---|---|---|
| Rectangular | narrow | -13 dB | Baseline; worst leakage |
| Hann | medium | -31 dB | General-purpose |
| Hamming | medium | -43 dB | Speech analysis |
| Blackman-Harris | wide | -92 dB | Strong tones near weak tones |
| Kaiser (tunable) | variable | variable | When trade-off must be exact |
**Trade-off.** Narrower main lobe means better frequency resolution but worse side-lobe rejection. Tapered windows sacrifice some resolution for enormously better leakage suppression.
## Technique 4 — Convolution and FIR Filters
A finite impulse response filter has output:
y[n] = sum over k=0..M-1 of h[k] * x[n - k]
where h[k] are the filter coefficients (the impulse response). This is a discrete convolution. FIR filters are always stable (no feedback, no poles) and can have exactly linear phase if the coefficients are symmetric — meaning all frequencies are delayed by the same amount, preserving waveform shape.
**Design methods:**
- **Window method.** Compute the ideal impulse response (sinc for a low-pass), truncate to M taps, multiply by a window.
- **Parks-McClellan (equiripple).** Optimize coefficients to minimize maximum error in the pass and stop bands.
- **Least-squares.** Minimize the sum of squared errors instead of the maximum error.
**Practical note.** FIR filter computation is dominated by multiply-accumulate (MAC) operations. DSP chips like TI's C6000 and ARM Cortex-M with DSP extensions can do one MAC per cycle, which is why they are called "DSP."
## Technique 5 — IIR Filters
Infinite impulse response filters use feedbacMajor art movements and their historical context for art education. Covers 12 movements from the Renaissance to contemporary art, their defining characteristics, key artists, signature works, and the intellectual/social forces that produced them. Use when analyzing artworks in historical context, understanding stylistic lineages, identifying influences across periods, or connecting studio practice to art-historical precedent.
Color theory principles for art education. Covers the three color properties (hue, saturation, value), color mixing systems (subtractive and additive), color relationships (complementary, analogous, triadic, split-complementary), color temperature, simultaneous contrast and the relativity of color perception, and practical palette construction. Use when analyzing color in artworks, planning color schemes, understanding optical phenomena in painting, or investigating Albers's Interaction of Color experiments.
The creative process in art from idea to exhibition. Covers five phases of creative work (inspiration, incubation, exploration, execution, reflection), sketchbook practice, artist statements, critique methodology (formal and conceptual), portfolio development, and the studio as a working environment. Use when guiding students through project development, facilitating critique sessions, developing artist statements, curating portfolios, or understanding how professional artists structure their creative practice.
Digital art tools, techniques, and workflows for art education. Covers raster and vector workflows, digital painting, photo manipulation, generative and procedural art, 3D modeling and rendering, pixel art, the relationship between traditional skills and digital execution, and ethical considerations of AI-generated imagery. Use when working with digital tools, evaluating digital art, or bridging traditional art concepts into digital practice.
Observational drawing and visual perception techniques for art education. Covers contour drawing, gesture drawing, negative space, proportion and measurement, value mapping, spatial depth cues, and the cognitive shift from symbolic to perceptual seeing. Use when teaching drawing fundamentals, analyzing observational accuracy, or developing visual literacy in any medium.
Three-dimensional art and sculptural thinking for art education. Covers additive and subtractive sculptural processes, armature construction, modeling in clay, carving principles, casting and moldmaking, assemblage and found-object sculpture, installation art as expanded sculpture, and the conceptual transition from pictorial to spatial thinking. Use when working with three-dimensional media, analyzing sculptural form, understanding spatial composition, or investigating the relationship between sculpture and site.
Celestial coordinate systems and sky positioning. Covers horizon (altitude-azimuth), equatorial (right ascension-declination), ecliptic, and galactic systems; epoch and precession; coordinate transformations; planisphere use; and practical sky-locating from any latitude and date. Use when locating objects, planning observations, converting catalog coordinates, or teaching the geometry of the sky.
Observational cosmology from Hubble's law to the CMB. Covers redshift, Hubble expansion, the cosmological parameters, the cosmic microwave background, large-scale structure, galaxy rotation curves and dark matter, Type Ia SNe and dark energy, and the current state of Lambda-CDM. Use when reasoning about the large-scale universe, interpreting cosmological surveys, or teaching the Big Bang evidence chain.