Articles

# Harmonic distortion in digital sinusoidal generators

In Problem 4.36 of DSP-Proakis [1], the task is to provide insights into harmonic distortion which may be present in practical sinusoidal generators. Consider the signal
$x(n) = \cos(2\pi f_0 n)$, where $f_0 = k_0/N$.

My take:
The discrete time signal of fundamental period $N$ can consist of frequency components separated by $2\pi/N$ radians or $f =1/N$ cycles (Refer Section4.2 in [1]).

The Fourier series coefficient at frequency $f_0$ is,
$c_{k0} = \frac{1}{N}\sum_{n=0}^{N-1}x(n)e^{\frac{-j2\pi k_0 n}{N}}$.

The total power of the signal over a period $P_x$ is same as the sum of the power of all the Fourier series coefficients (harmonic components) i.e.
$P_x = \frac{1}{N}\sum_{n=0}^{N-1}|x(n)|^2 = \sum_{k=0}^{N-1}|c_k|^2$.

As the signal is real valued, the power at other frequency components apart from the desired frequency component is $P_x - 2|c_{k0}|^2$.

Concluding, the Total Harmonic Distortion (THD) is
$THD = \frac{P_x - 2|c_{k0}|^2}{P_x} = 1 - \frac{2|c_{k0}|^2}{P_x}$.

In the second part of the problem, the task is to generate the sinusoidal for a single period by Taylor approximation
$\cos(x) = \sum_{n=0}^{\infty}\frac{(-1)^n}{2n!}x^{2n}$.

f = 1/32;
t = repmat([0:(1/f)-1],1,1);
x = 2*pi*f*t;
n = [0:7]’;
s = factorial(2*n);
p = (-1).^n;
r = (p./s*ones(size(t))).*(ones(size(n))*x).^(2*n*ones(size(t)));
cosT = sum(r); % cosine computed from Taylor series
cosA = cos(x); % actual cosine values

The third part of the problem is to find the THD of the sinusoidals obtained from the Taylor series summation and the actual cosine function.

% compute the fourier series coefficients
k = [0:(1/f)-2]’;
refF = exp(-j*2*pi*k*t*f);
hdA = mean((ones(1/f -1,1)*cosA).*refF,2);

hdT = mean((ones(1/f -1,1)*cosT).*refF,2);

% THD from Taylor series based cosine function
THD_T = 1 – 2*abs(hdT(2)).^2/sum(cosT.^2/length(cosT))
% THD from actual cosine function
THD_A = 1 – 2*abs(hdA(2)).^2/sum(cosA.^2/length(cosA))

From a quick run of the code for different values of f, observed that the computed THD for lower frequencies is higher than that for higher frequencies. For a lower frequency signal, there are more harmonic components present in $[0\ f_s/2)$, hence the reason.

Also, as only a single period of the sinusoidal signal is considered, the signal can be treated as an aperiodic signal and hence having a continuous (and periodic) spectrum. Summarizing, apart from the power at the harmonic frequencies, the signal will be having frequency components at other portions of the spectra in $[0\ f_s/2)$.