2.2.2. Exercise: Resolution and Mapping

2.2.2.1. Objective

Filter a control input to control an audible signal and explore signal precision.

Digitized signals are represented by a finite number of bits and thus are discretized in value as well as time. However, there is a often a tradeoff between time and resolution, since multiple samples of a measurement can be combined over time.

This exercise continues with audible signal generation since our ears are very sensitive to subtle changes of pitch.

2.2.2.2. Steps and observations

  1. Start from your result from the previous exercise: a circuit reading a potentiometer input and mapping the voltage to a change in the frequency of two audible speaker outputs.

  2. Adjust the mapping function until a one-unit change in the input is enough to create an audible step. Adjust the update rate to approximately 2 Hz so each input change creates a tone at about 120 BPM for ease of observation.

  3. Observe the effect of ADC noise on the pitch sequence. Slowly move the potentiometer and observe the step changes in pitch for small input changes.

  4. Add a smoothing filter to the potentiometer input. This can be as simple as a basic first-order filter:

    static float smoothed_value = 0.0;                  // filtered value of the input
    int new_value      =  analogRead( analogPin );      // read the current input
    float difference   =  new_value - smoothed_value;   // compute the 'error'
    smoothed_value     += 0.1 * difference;             // apply a constant gain to move the smoothed value toward the reading
    
  5. Observe the resulting pitch sequence. Increase the input sampling rate to decrease the convergence time for step inputs.

2.2.2.3. Comments

As a challenge, try adding a differentiator to the potentiometer input to map the change rate of the input to the pitch.