Making Quiet Harmonics Visible
A sustained vowel can look surprisingly busy. Hold a low drone, move your tongue, and some of the higher harmonics grow louder while others recede. A spectrogram turns those changes into a picture; a sketch can start with just one column of magnitudes.
Suppose an analysis has already supplied five magnitudes: 2, 4, 6, 10, 18. Their absolute values might be awkward to draw directly. Min-max normalization maps the smallest to 0 and the largest to 1, placing everything else proportionally between them. For this column, the result is 0.000, 0.125, 0.250, 0.500, 1.000.
Zig makes the numeric types explicit, which is handy when the next stop might be a pixel buffer:
const std = @import("std");
pub fn main() void {
const magnitudes = [_]f64{ 2, 4, 6, 10, 18 };
var low = magnitudes[0];
var high = magnitudes[0];
for (magnitudes[1..]) |value| {
low = @min(low, value);
high = @max(high, value);
}
for (magnitudes) |value| {
const brightness = if (high == low) 0 else (value - low) / (high - low);
std.debug.print("{d:.3}\n", .{brightness});
}
}
Ruby lets the same little experiment read almost like a note beside the drawing:
magnitudes = [2.0, 4.0, 6.0, 10.0, 18.0]
low, high = magnitudes.minmax
magnitudes.each do |value|
brightness = high == low ? 0.0 : (value - low) / (high - low)
puts format('%.3f', brightness)
end
Both programs treat a flat column as zero brightness: when every value is equal, there is no range to divide by. That’s a drawing choice, not a claim that the sound is silent.
There’s a catch to stretching each column independently. A faint breath and a powerful vowel can each contain a brightest point rendered as white, so comparisons across time lose their absolute meaning. For a sketch of changing harmonic shape, that contrast can be useful. For comparing loudness, keep a shared scale across columns instead. The code begins after spectral analysis; it doesn’t turn a microphone recording into magnitudes.