Harmonic distortion of sine signal. plotting resulting spectrum
Here is a way that you can approach this mathematically.  It's not the only way.  Another way to approach this is with Tchebyshev polynomials and I will leave that to someone else.

This approach requires understanding two ingredients.


an identity that is a consequence of Euler's formula:


$$ \cos(\omega t) = \tfrac12(e^{j\omega t}+e^{-j\omega t}) $$
or
$$ \sin(\omega t) = \tfrac1{2j}(e^{j\omega t}-e^{-j\omega t}) $$


the binomial theorem:


$$\begin{align}
 (a+b)^N &amp;= \sum_{n=0}^N {N \choose n} \, a^{N-n} \, b^n \\
         &amp;= \sum_{n=0}^N {N \choose n} \, a^n \, b^{N-n} \\
\end{align}$$
or
$$\begin{align}
 (a+b)^N &amp;= \sum_{n=0}^N \frac{N!}{(N-n)! \, n!} \, a^{N-n} \, b^n \\
         &amp;= \sum_{n=0}^N \frac{N!}{(N-n)! \, n!} \, a^n \, b^{N-n} \\
\end{align}$$

Now you might see where this is going.  So using the cosine identity (so i don't have to mess around with powers of $j$ in the sine identity):

$$\begin{align}
 \cos^k(\omega t) &amp;= \frac{1}{2^k}(e^{j\omega t}+e^{-j\omega t})^k \\
\\
 &amp;= \frac{1}{2^k} \sum_{n=0}^k \frac{k!}{(k-n)! \, n!} \, (e^{j\omega t})^{k-n} \, (e^{-j\omega t})^n \\
\\
 &amp;= \frac{1}{2^k} \sum_{n=0}^k \frac{k!}{(k-n)! \, n!} \, e^{j(k-n)\omega t} \, e^{-jn\omega t} \\
\\
 &amp;= \frac{1}{2^k} \sum_{n=0}^k \frac{k!}{(k-n)! \, n!} \, e^{j(k-2n)\omega t} \\
\end{align}$$

It appears that we will have to deal with the two cases of even $k$ vs. odd $k$ differently.



For even $k \ge 2$:

$$\begin{align}
 \cos^k(\omega t) &amp;= \frac{1}{2^k}(e^{j\omega t}+e^{-j\omega t})^k \\
\\
 &amp;= \frac{1}{2^k} \sum_{n=0}^k \frac{k!}{(k-n)! \, n!} \, e^{j(k-2n)\omega t} \\
\\
 &amp;= \frac{1}{2^k} \left( \sum_{n=0}^{\tfrac{k}{2}-1} \frac{k!}{(k-n)! \, n!} \, e^{j(k-2n)\omega t} + \frac{k!}{\tfrac{k}{2}! \, \tfrac{k}{2}!} + \sum_{n=\tfrac{k}{2}+1}^k \frac{k!}{(k-n)! \, n!} \, e^{j(k-2n)\omega t} \right) \\
\\
 &amp;= \frac{1}{2^k} \left(\frac{k!}{\left(\tfrac{k}{2}!\right)^2} +  \sum_{n=0}^{\tfrac{k}{2}-1} \frac{k!}{(k-n)! \, n!} \, e^{j(k-2n)\omega t} + \sum_{n=0}^{\tfrac{k}{2}-1} \frac{k!}{n! \, (k-n)!} \, e^{j(k-2(k-n))\omega t} \right) \\
\\
 &amp;= \frac{1}{2^k} \frac{k!}{\left(\tfrac{k}{2}!\right)^2} + \frac{1}{2^k} \sum_{n=0}^{\tfrac{k}{2}-1} \frac{k!}{(k-n)! \, n!} \, \Big( e^{j(k-2n)\omega t} + e^{-j(k-2n)\omega t} \Big) \\
\\
 &amp;= \frac{1}{2^k} \frac{k!}{\left(\tfrac{k}{2}!\right)^2} + \frac{1}{2^k} \sum_{n=0}^{\tfrac{k}{2}-1} \frac{k!}{(k-n)! \, n!} \, 2 \cos\big((k-2n)\omega t\big) \\
\\
 &amp;= \frac{1}{2^k} \frac{k!}{\left(\tfrac{k}{2}!\right)^2} + \frac{2 k!}{2^k} \sum_{n=1}^{\tfrac{k}{2}} \frac{1}{\left(\tfrac{k}{2}+n\right)! \, \left(\tfrac{k}{2}-n\right)!} \, \cos(2n\omega t) \\
\end{align}$$

Note that only DC and even-numbered harmonics come outa the even powers of $\cos^k(\omega t)$.





For odd $k \ge 1$:

$$\begin{align}
 \cos^k(\omega t) &amp;= \frac{1}{2^k}(e^{j\omega t}+e^{-j\omega t})^k \\
\\
 &amp;= \frac{1}{2^k} \sum_{n=0}^k \frac{k!}{(k-n)! \, n!} \, e^{j(k-2n)\omega t} \\
\\
 &amp;= \frac{1}{2^k} \left( \sum_{n=0}^{\tfrac{k-1}{2}} \frac{k!}{(k-n)! \, n!} \, e^{j(k-2n)\omega t} + \sum_{n=\tfrac{k+1}{2}}^k \frac{k!}{(k-n)! \, n!} \, e^{j(k-2n)\omega t} \right) \\
\\
 &amp;= \frac{1}{2^k} \left( \sum_{n=0}^{\tfrac{k-1}{2}} \frac{k!}{(k-n)! \, n!} \, e^{j(k-2n)\omega t} + \sum_{n=0}^{\tfrac{k-1}{2}} \frac{k!}{n! \, (k-n)!} \, e^{j(k-2(k-n))\omega t} \right) \\
\\
 &amp;= \frac{1}{2^k} \sum_{n=0}^{\tfrac{k-1}{2}} \frac{k!}{(k-n)! \, n!} \, \Big( e^{j(k-2n)\omega t} + e^{-j(k-2n)\omega t} \Big) \\
\\
 &amp;= \frac{1}{2^k} \sum_{n=0}^{\tfrac{k-1}{2}} \frac{k!}{(k-n)! \, n!} \, 2 \cos\big((k-2n)\omega t\big) \\
\\
 &amp;= \frac{2 k!}{2^k} \sum_{n=0}^{\tfrac{k-1}{2}} \frac{1}{\left(\tfrac{k+1}{2}+n\right)! \, \left(\tfrac{k-1}{2}-n\right)!} \, \cos\big((2n+1)\omega t\big) \\
\end{align}$$

Note that only odd-numbered harmonics come outa the odd powers of $\cos^k(\omega t)$.





So now what if we pass this sinusoid:

$$ x(t) = A \, \cos(\omega t) $$

through this polynomial mapping function:

$$\begin{align}
 y(t) &amp;= a_0 + a_1 x(t) + a_2 x^2(t) + a_3 x^3(t) + ... + a_{K-1} x^{K-1}(t) + a_K x^K(t) \\
      &amp;= \sum_{k=0}^{K} a_k \big( x(t) \big)^k \\
\end{align} $$

?

I believe we have to split the even-order terms from the odd-order terms in the summation

$$\begin{align}
 y(t) &amp;= \sum_{k=0}^{K} a_k \big( x(t) \big)^k \\
\\
  &amp;= a_0 + \sum_{k=1}^{\left\lfloor \tfrac{K}{2} \right\rfloor} a_{2k} \big( x(t) \big)^{2k} + \sum_{k=0}^{\left\lfloor \tfrac{K-1}{2} \right\rfloor} a_{2k+1} \big( x(t) \big)^{2k+1} \\
\\
  &amp;= a_0 + \sum_{k=1}^{\left\lfloor \tfrac{K}{2} \right\rfloor} a_{2k} \big( A \cos(\omega t) \big)^{2k} + \sum_{k=0}^{\left\lfloor \tfrac{K-1}{2} \right\rfloor} a_{2k+1} \big( A \cos(\omega t) \big)^{2k+1} \\
\\
  &amp;= a_0 + \sum_{k=1}^{\left\lfloor \tfrac{K}{2} \right\rfloor} a_{2k} A^{2k} \cos^{2k}(\omega t) + \sum_{k=0}^{\left\lfloor \tfrac{K-1}{2} \right\rfloor} a_{2k+1} A^{2k+1} \cos^{2k+1}(\omega t) \\
\\
  &amp;= a_0 + \sum_{k=1}^{\left\lfloor \tfrac{K}{2} \right\rfloor} a_{2k} A^{2k} \left( \frac{1}{2^{2k}} \frac{(2k)!}{(k!)^2} + \frac{2 (2k)!}{2^{2k}} \sum_{n=1}^{k} \frac{1}{\left(k+n\right)! \, \left(k-n\right)!} \, \cos(2n\omega t) \right) + \sum_{k=0}^{\left\lfloor \tfrac{K-1}{2} \right\rfloor} a_{2k+1} A^{2k+1} \left( \frac{2 (2k+1)!}{2^{2k+1}} \sum_{n=0}^{k} \frac{1}{(k+1+n)! \, (k-n)!} \, \cos\big((2n+1)\omega t\big) \right) \\
\\
  &amp;= a_0 + \sum_{k=1}^{\left\lfloor \tfrac{K}{2} \right\rfloor} a_{2k} \frac{A^{2k}}{2^{2k}} \frac{(2k)!}{(k!)^2} + \sum_{k=1}^{\left\lfloor \tfrac{K}{2} \right\rfloor} \sum_{n=1}^{k} a_{2k} \frac{2 A^{2k} (2k)!}{2^{2k}\left(k+n\right)! \left(k-n\right)!} \, \cos(2n\omega t) \qquad + \sum_{k=0}^{\left\lfloor \tfrac{K-1}{2} \right\rfloor} \sum_{n=0}^{k} a_{2k+1} \frac{2 A^{2k+1} (2k+1)!}{2^{2k+1}(k+1+n)!(k-n)!} \, \cos\big((2n+1)\omega t\big) \\
\\
  &amp;= a_0 + \sum_{k=1}^{\left\lfloor \tfrac{K}{2} \right\rfloor} a_{2k} \frac{A^{2k}}{2^{2k}} \frac{(2k)!}{(k!)^2} + \sum_{n=1}^{\left\lfloor \tfrac{K}{2} \right\rfloor} \sum_{k=n}^{\left\lfloor \tfrac{K}{2} \right\rfloor} a_{2k} \frac{2 A^{2k} (2k)!}{2^{2k}\left(k+n\right)! \left(k-n\right)!} \, \cos(2n\omega t) \qquad + \sum_{n=0}^{\left\lfloor \tfrac{K-1}{2} \right\rfloor} \sum_{k=n}^{\left\lfloor \tfrac{K-1}{2} \right\rfloor} a_{2k+1} \frac{2 A^{2k+1} (2k+1)!}{2^{2k+1}(k+1+n)!(k-n)!} \, \cos\big((2n+1)\omega t\big) \\
\end{align} $$

$\lfloor u \rfloor$ is the floor() function, which is the largest integer no larger than the argument $u$.

$$ \lfloor u \rfloor \le u  &lt; \lfloor u \rfloor + 1 $$
or
$$  u-1 &lt; \lfloor u \rfloor \le u $$

Also note that if $K$ is even
$$ \left\lfloor \tfrac{K-1}{2} \right\rfloor &lt; \left\lfloor \tfrac{K}{2} \right\rfloor = \tfrac{K}{2} \quad \text{and} \quad \left\lfloor \tfrac{K-1}{2} \right\rfloor &lt; \tfrac{K-1}{2} $$

If $K$ is odd
$$ \left\lfloor \tfrac{K}{2} \right\rfloor = \left\lfloor \tfrac{K-1}{2} \right\rfloor = \tfrac{K-1}{2} \quad \text{and} \quad \left\lfloor \tfrac{K}{2} \right\rfloor &lt; \tfrac{K}{2} $$



$$\begin{align}
 y(t) &amp;= \sum_{k=0}^{K} a_k \big( A \cos(\omega t) \big)^k \\
\\
     &amp;= \sum_{n=0}^{K} b_n \cos(n \omega t) \\
\end{align}$$

where, apparently the DC component of the Fourier cosine series is:

$$ b_0 =  a_0 + \sum_{k=1}^{\left\lfloor \tfrac{K}{2} \right\rfloor} a_{2k} \frac{(2k)!}{(k!)^2} \left(\frac{A}{2}\right)^{2k}  $$

The coefficient for the even harmonic terms:

$$ b_{2n} = 2 \sum_{k=n}^{\left\lfloor \tfrac{K}{2} \right\rfloor} a_{2k} \frac{(2k)!}{\left(k+n\right)! \left(k-n\right)!} \left(\frac{A}{2}\right)^{2k}  $$

And the coefficient for the odd harmonic terms:

$$ b_{2n+1} = 2 \sum_{k=n}^{\left\lfloor \tfrac{K-1}{2} \right\rfloor} a_{2k+1} \frac{(2k+1)!}{(k+1+n)!(k-n)!} \left(\frac{A}{2}\right)^{2k+1}  $$