Wed Sep 5 14:06:19 CEST 2012

Closed form expression for A1 modulator output + Fourier spectrum

An indication of the "noise" component in a S/D signal from a
constant, q/p rational-valued signal, using a non-leaky 1st order
integrator / accumulator (an "A1 modulator"), can be computed as the
lowest harmonic of the Fourier expansion of the p-periodic binary
output signal b[k].

  \sum_{k=1}^p b[k] w^k  with w=e^{i 2 \pi / p}

In a single period b[1] to b[p] we have q nonzero values.  This
follows from the average q/p and b[i] \in {0,1}.  The indices of these
non-zero sequence elements are given by

  I = { ceil( k p / q ) | 1 <= k <= q }

The state of an A1 modulator can be represented as the rotation angle
of a regular polygon with p sides, where the input (the constant
number q/p) represents the constant rotation to be performed at each
time step.  The output of the modulator is 1 at each time step that a
new full revolution has been completed.

To find the indices at which these revolutions complete, first
approximate them fractionally, solving for n in

            q/p * n_f = k   or   n_f = k * p/q,

reasoning that a full revolution is completed for each integer k.

However, n cannot be fractional so if n_f is not an integer, the full
revolution will be completed at the nearest later time index obtained
by rounding n_f to the nearest larger integer n = ceil(n_f). This
corresponds to the definition of I.

( Note that because q <= p making p/q >= 1, this equation never yields
  the same index more than once. )

In an example, q/p = 3/11 we have   n = k*11/3

k              1        2       3
n_f            1*11/3,  2*11/3, 3*11/3
                 3.67,    7,33,     11
n = ceil(n_f) =     4,       8,     11

The output bit sequence is: 

1  2  3  4  5  6  7  8  9 10 11
0  0  0  1  0  0  0  1  0  0  1

and the amplitude of the lowest harmonic in the Fourier analysis is

   w^4 + w^7 + w^11 != 0   w = e^{2 \pi / 11}

which is almost zero (easy to see when drawing the 3 vectors on paper)
but not quite.  It would be zero if fractional indices were allowed,
making the 3 vectors the sides of a regular triangle.

   w^{1 * 11/3} + w^{2 * 11/3} + w^{3 * 11/3} = 0

Conclusion: The existence of a closed form expression for the binary
sequence (I) avoids having to perform a simulation to generate the bit

-- Closed form expression for indices of non-zero sequence elements.
nz' q p = map n [1..q] where
  n k = ceiling $ k * p / q

-- Type conversion
nz q p = nz' (i q) (i p) where i = fromIntegral