Pulse-density Modulation - Algorithm

Algorithm

A digital model of pulse-density modulation can be obtained from a digital model of the delta-sigma modulator. Consider a signal in the discrete time domain as the input to a first-order delta-sigma modulator, with the output. In the discrete frequency domain, the delta-sigma modulator's operation is represented by

Rearranging terms, we obtain

Here, is the frequency-domain quantization error of the delta-sigma modulator. The factor represents a high-pass filter, so it is clear that contributes less to the output at low frequencies, and more at high frequencies. This demonstrates the noise shaping effect of the delta-sigma modulator: the quantization noise is "pushed" out of the low frequencies up into the high-frequency range.

Using the inverse Z-transform, we may convert this into a difference equation relating the input of the delta-sigma modulator to its output in the discrete time domain,

There are two additional constraints to consider: first, at each step the output sample is chosen so as to minimize the "running" quantization error . Second, is represented as a single bit, meaning it can take on only two values. We choose for convenience, allowing us to write

This, finally, gives a formula for the output sample in terms of the input sample . The quantization error of each sample is fed back into the input for the following sample.

The following pseudo-code implements this algorithm to convert a pulse-code modulation signal into a PDM signal:

// Encode samples into pulse-density modulation // using a first-order sigma-delta modulator function pdm(real x) var int y var real qe qe := 0 // initial running error is zero for n from 0 to s if x >= qe y := 1 else y := -1 qe := y - x + qe return y, qe // return output and running error

Read more about this topic:  Pulse-density Modulation