Quantization: what an ADC does to a smooth signal
Draw a pitch line on the graph. The blue line is the smooth “analog” signal that you drew. An analog-to-digital converter (ADC) can store only a fixed number of values, so the ADC moves each point to the nearest permitted level. This gives the pink staircase. With n bits, there are 2n levels. Play the two versions to hear the difference.
Bits → levels
Each added bit doubles the number of levels: 1 bit = 2, 2 bits = 4, 8 bits = 256, 12 bits = 4096. When the number of levels doubles, the step size decreases by half, so the maximum error also decreases by half.
Quantization error
The difference between the original value and the rounded value is the quantization error. Its maximum is ½ step. In audio, you hear this error as noise or distortion. Each bit adds about 6 dB of signal-to-noise ratio.
Sampling vs. quantizing
An ADC does two tasks. It samples (measures at regular times) and it quantizes (rounds each measurement to a level). Try a low sample rate with a low bit depth. The line then becomes a grid of blocks.
ESP32 connection
The ESP32 ADC is 12-bit. It divides its input range (about 0–3.1 V at the default setting) into 4096 levels, with less than 1 mV for each step. Electrical noise makes the lowest bits unstable, so real readings are less accurate than this. The ESP32 DAC is 8-bit (256 levels). To hear these resolutions, set the bit depth above to 8 or 12. The MPU-6050 uses 16-bit converters.