The dfsdm object represents a digital filter for sigma-delta modulators (DFSDM). It is instantiated automatically, but is only available on the imp004m, which provides a single DFSDM input driven by two signal pins: a clock on pin S (CLK) and data on pin R (DATA).
When using DFSDM, both of these pins are configured as inputs. DATA is fed with the bit stream output by an external sigma-delta modulator at the same frequency as the CLK pin is driven. The external sigma-delta modulator may or may not output this clock signal. If the sigma-delta modulator does not output a clock signal, the imp004m can provide one itself by routing a PWM pin to both the sigma-delta modulator and back into CLK. Alternatively, an external clock can be used to drive both the sigma-delta modulator and CLK.
Sigma-delta modulators are an alternative to traditional analog to digital converters.
An ADC converts analog signals to digital by sampling the absolute value of the analog signal at a fixed frequency. A multi-level quantizer is used to convert each sample into a digital representation at a preset bit depth. This method suffers from quantization errors in the digital output, experienced as noise. ADC functionality is provided by the imp API’s sampler object.
By contrast, a sigma-delta modulator measures the difference (delta) between two samples of the analog signal over a specified time period and encodes it as a stream of digital pulses (0 representing a negative delta and 1 representing a positive delta). The delta is added back (sigma) to the analog signal through a 1-bit DAC, and the resulting signal issued as a bit stream. This results in much-reduced quantization noise.
The bit stream from a sigma-delta modulator is then passed through a digital filter within the imp004m in order to create a digitized sample at the required bit-depth. This approach to analog to digital conversion makes the dfsdm very versatile when compared to a traditional ADC, as varying bit depths and effective sample rates can be achieved simply by adjusting the digital filter parameters.
Another advantage of using dfsdm rather than sampler is that analog components can be removed from the circuit design, thereby reducing the risk of interference from radio transceivers such as WiFi and Bluetooth.
The imp004m’s dfsdm behaves very much like the sampler object, both in terms of how it is configured and how it operates. The dfsdm object is set up using the dfsdm.configure() method, which takes as parameters the desired digital filter settings, and an array of blobs as buffers. Each time a buffer is filled with data, a buffer-processing callback function is executed and passed the filled buffer. This callback is registered using dfsdm.configure(). Optionally, the buffers can be pre-processed with a selection of audio processing filters.
While the sampler provides 16-bit samples, dfsdm is capable of producing samples of up to 24 bits in depth. Without any pre-processors specified, dfsdm will provide buffers of 24-bit unsigned samples in the least significant bits of Squirrel 32-bit signed integers. An additional pre-processor is provided to convert these 24-bit samples into 16-bit samples, two of which are packed into each 32-bit word.
The digital filter has three configurable parameters: the filter order, the decimation rate and the integration rate.
The filter order can be interpreted as the number of levels of feedback provided, where a single level of feedback comprises a 1-bit DAC that feeds the sampled delta back to the original analog signal. Different filter orders result in different frequency response characteristics of the resulting output. The quantization noise arising from the conversion is arranged to be present in a different part of the spectrum than the signal of interest. It is through this technique, sometimes known as ‘noise shaping’, that the approach employed by DFSDM can achieve a much better signal to noise ratio than a traditional ADC, especially as bit depth is increased.
The decimation rate is the number of times the signal is oversampled. The