# Output spectrum of the direct digital synthesis (DDS)

I have a question about the output spectrum of DDS, which consists of a phase accumulator and look-up table.

Since the look-up table stores accurate information about sinusoidal waveform, I think quantization error and corresponding spectrum information (such as total harmonic distortion) might differ from simply equally distributed cases like ADC.

Of course normally DDS output is changed to analog value by DAC, I'd like to know spectrum analysis right after look-up table.

So my questions are :

1. How do the look-up table bits affect the spectrum? By intuition, it's expected that the larger the bits, the less THD. Is there any mathematical expression?

2. How can the amplitude error from quantization be converted to a spectrum? For example, I need "10.3" to define a specific point of the sinusoid after the phase accumulator, but I have only an integer-weighted LUT (in this case, I have to express 10.3 by either 10 or 11).

For example:

If I have a LUT with an integer value and 4 samples, I have sinewave samples like 1, 3, 8, 10.

But if I have 0.5 resolution and 8 samples, I can express it like 1, 1.5, 2.5, 4.5, 6.5, 8.5, 9.5, 10.

So my question is:

How are size and resolution related to spurious contents (e.g., THD)?

• Maybe give one example implementation and one signal then someone could help you with that and you generalize accordingly to your needs. There are so many ways to do that. Don't forget you should have a filter after your DAC to mitigate the zero-order hold effect. For instance if you had only one bit and a very high frequency DAC you could still have a sine wave with a very low TDH. Even if you had one bit DAC and the DAC frequency was twice as large as the sine frequency, with a sharp filter you could get a very good TDH.
– Bob
Feb 12 at 16:59
• @Bob Thank you for your comment. I'm going to rephrase my question more precisely with example. Feb 13 at 4:20
• @Hilmar Well i just added an example for better illustration, but basically it's not that different from my previous question. Feb 13 at 5:28
• The answer is the same: it depends a lot on the details of how exactly you implement the lookup table and the interpolation (if any). It's easy enough to model in Matlab or Python for your specific algorithm. For any reasonable implementation, the amplitude quantization and quantization of the phase accumulator won't matter, it's primarily the size of the lookup table that will determine the THD Feb 13 at 5:43
• Under my answer to your previous question, you said you wanted to ask with a concrete example, but this isn't really concrete about the things I pointed out you need to define. Feb 13 at 11:02

First you need to model your DDS.

Let $$l(t)$$ be the impulse response and $$L(\omega)$$ the frequency response of your DAC, output that you could tune with a filter; $$q(t) = \sum_k x_k \delta(t - k T_s)$$ the dac input. Then your output will be $$\hat y(t) = \sum x_k l(t - k T_s)$$, and the output spectrum

$$\mathcal{F}(\hat y) = \hat Y(\omega) = \sum_k x_k L(\omega)\exp(-j\, k \omega_f)$$

Now you can think express your error, e.g. THD could be expressed as something like this

$$\sum_{n=2}^\infty |\hat Y(n \omega_F)|^2 = \sum_{n=2}^\infty \left| \sum_k x_k\, L(n\, \omega_F)\exp(-j\, n\, k\,\omega_F)\right|^2$$

But this is too complicated, and I will continue with a simpler example, the squared error.

$$\frac 1 T \int_0^T |\hat y(t) - y(t)|^2 dt$$

This can be optimized using the least squares curve fit. For one period one could compute $$u_k = \int_0^T y(t) l(t - k T_s) dt$$, and also the correlation matrix $$C_{i,k} = \int_0^T l(t - k T_s) l(t - i T_s) dt$$, the input $$x$$ can be determined by solving the system of equations $$C \mathbf x = \mathbf u$$.

If you want to deal with $$y(t)$$ of period $$T$$, all you have to do is to replace $$l(t)$$ by $$\sum_{p=-\infty}^{\infty} l(t - p T)$$

## Quantization

The linear equation above arises from the solution of

$$\min_\mathbf x ||C \mathbf x - u||^2$$

That is a quadratic programming problem.

You can model quantization by introducing a restriction $$x_i \in \mathbb N$$, and the problem

$$\min_\mathbf x ||C \mathbf x - u||^2 \\ s.t. \quad x_i \in \mathbb N$$

Is a Mixed-integer quadratic programming problem. This type of problem is NP, you can attempt a solution with cvxpy in python, or in matlab using intlinprog, or surrogateopt.

If you want a simpler solution you have to look closer to your specific problem. Maybe this can be simplified, for instance if $$C$$ matrix is diagonal the optimal solution is obtained by solvin one scalar linear equation and then rounding the result for each $$x_k$$.

This is why we insist with you to "improve" your question.

There are two sources of spurious error in a Numerically Controlled Oscillator (NCO): phase truncation based on truncating the phase accumulator output (which is then the number of bits into the look-up table) and quantization noise at the output (which is based on the number of bits stored for each output sample in the look-up table, or the bit width of the output).

For the phase truncation components, the highest harmonic is given by 6.02 dB per bit where “bit” is the number of bits into the Look up table input, and this result will be the amount in dB that the highest spur is below the power of the primary sinusoidal output (and thus the spurious free dynamic range or SFDR). This can be derived as follows: The phase truncation error will result in a ramp function of phase error vs time (or often a subsampled ramp). The phase modulation due to small angle approximation (where $$\sin(\theta) \approx \theta$$) will have one dominant sideband for each sinusoidal component from the Fourier Series Expansion of the ramp. Thus the first harmonic of this series will be the strongest spurious component in the result due to phase truncation. Carrying this through results in a $$6.02$$ dB/bit SFDR.

(I am traveling now but will update this answer with the detailed derivation, which I have also confirmed through simulation).

How do the look-up table bits affect the spectrum? By intuition, it's expected that the larger the bits, the less THD.

Complicated. Of course, your table's bit depth affects the output – but this is really a combined problem on the table size, the bitdepth, the ratio of desired frequency and sample rate, and the method chosen to calculate indices and interpolation. There's not a single answer – and things like dithering make this even more specific to the individual DDS.

Is there any mathematical expression?

Sure, once you write down very precisely what your DDS does mathematically, you can derive that (it's usually not hard for a DDS to do that for when your period in samples is actually a divisor of the table length (because then it's just the classical theory of quantization), very doable when it's an integer multiple, but starts depending on the interpolation method…)

How can the amplitude error from quantization be converted to a spectrum?

Different question. We model things as quantization noise, which we often model as sufficiently uncorrelated. That won't work for a DDS, because things are pretty inherently periodic. So, you'll want to look at how you plan to implement things, and then you can look at what the effects are.

Note that there's a lot of possible tradeoffs here! If you have a specific application problem in mind, do not hesitate to ask about it in a new question – there's definitely a lot of experience on such problems on this platform.

• Thank you for your comment. I'm going to re-ask with a specific example. Feb 13 at 4:21