An analog wave is an infinite line. To process it, we must chop it into a finite series of numbers. This is the science of Sampling.
1The Sampling Rate
To convert an analog wave into digital data, we measure the amplitude at regular intervals. This is the Sample Rate. According to the Nyquist-Shannon Theorem, to perfectly reconstruct a signal, you must sample at a rate at least double the highest frequency in the signal. Since humans hear up to 20,000 Hz, the standard CD sample rate is 44,100 Hz—providing a safe buffer to capture everything we can hear without distortion. If you ignore this and sample too slowly, the AI will learn from broken, incomplete data.
// The Nyquist Theorem in Practice
const maxHumanFreq = 20000; // Hz
// Minimum required sample rate
const minSampleRate = maxHumanFreq * 2;
console.log(minSampleRate); // 40000 Hz
// Industry standard adds a small buffer
const cdQualityRate = 44100; // Hz2The Bit Depth
While the sample rate defines the time resolution, Bit Depth defines the amplitude resolution. Every time we take a sample, we must round the amplitude to the nearest available digital value. This rounding is called Quantization. A 16-bit signal has 65,536 possible levels, while a 24-bit signal has over 16 million. Higher bit depth reduces Quantization Noise and allows for a greater Dynamic Range, capturing the difference between a whisper and a thunderclap. For neural networks, we usually convert this raw bit depth into floating-point numbers right away.
// Understanding Bit Depth resolution
const bitDepth = 16;
// 2 to the power of 16
const possibleValues = Math.pow(2, bitDepth);
console.log(`Resolution: ${possibleValues} levels`);
// Output: Resolution: 65536 levels
// We must 'round' the analog voltage to one
// of these 65,536 discrete steps.3Digital Artifacts
If we sample too slowly, we experience Aliasing. High-frequency waves 'disguise' themselves as low-frequency waves because our samples are too far apart to see the true oscillation. This creates metallic, distorted 'phantom' sounds that ruin your ML model's accuracy. To prevent this, audio hardware uses an Anti-aliasing Filter before the conversion process—a steep low-pass filter that aggressively chops off any frequencies that are too high for the chosen sample rate to handle safely.
// Conceptual Anti-Aliasing Filter
function applyAntiAliasing(signal, sampleRate) {
const nyquistLimit = sampleRate / 2;
let safeSignal = [];
for (let freq of signal) {
if (freq < nyquistLimit) {
safeSignal.push(freq);
}
}
return safeSignal;
}