Explaining a Series Expansion for the Divisor Function The "sum-of-divisors" function, defined as $\sigma(n)=\sum_{d\,\mid\,n}d$, can be expressed as $$\sigma(n)=\sum_{i=1}^n\sum_{j=1}^i\cos\Big(2\pi n \frac{j}{i}\Big)$$This expansion makes logical sense. However, while looking through the wolfram page regarding the divisor function, I found the following expansion (equation 26):
$$
\begin{align}
\sigma(n) = \frac{1}{6}n\pi^2\left[\left(1+\frac{(-1)^n}{2^2}\right) + \frac{2\cos\left(\frac{2}{3}n\pi\right)}{3^2} \right. \\[8pt]
{} + \frac{2\cos\left(\frac{1}{2} n\pi\right)}{4^2} & \left. {} + \frac{2\left[\cos\left(\frac{2}{5}n\pi\right) + \cos\left(\frac{4}{5}n\pi\right)\right]}{5^2} + \cdots\right]
\end{align}
$$
Is there an obvious link I am missing between the first and second expression? If not, how is this second expression derived?

This can be done by means of Ramanujan Sum. We follow the definitions and notations in the link. 
The identity is a special case ($s=2$) of the following general identity:
$$
\frac{\sigma_{s-1}(n)}{n^{s-1}\zeta(s)}  = \sum_{q=1}^{\infty} \frac{c_q(n)}{q^s} \  \ \ (\ast)
$$
Proof of $(\ast)$: 
$$
c_q(n)=\sum_{d|q} \mu\left(\frac qd\right) \eta_d(n) = \mu \ast \eta
$$
where $\eta_d(n) =  d \mathbf{1}_{d|n} (n)$ and $\ast$ is the Dirichlet convolution. 
Since the Dirichlet series corresponding to $\mu$ is $\frac1{\zeta(s)}$ and the Dirichlet series corresponding to $\eta$ is $\frac{\sigma_{s-1}(n)}{n^{s-1} } $, we have established $(\ast)$ for $s$ with sufficiently large real part. For more  values of $s$ that $(\ast)$ is valid, we consider the RHS as a product of two absolutely convergent Dirichlet series.
By the absolute convergence of the two Dirichlet series:
$$
\frac{\sigma_{s-1}(n)}{n^{s-1}} \ \  \mathrm{and} \ \ \frac1{\zeta(s)}
$$
for $\mathrm{Re}(s)>1$, 
the Dirichlet series
$$
\sum_{q=1}^{\infty} \frac{c_q(n)}{q^s}
$$
is also absolutely convergent for $\mathrm{Re}(s)>1$. 
Therefore, we showed that $(\ast)$ is valid for $\mathrm{Re}(s)>1$. In particular, plugging in $s=2$ is justified. 
In fact, $(\ast)$ is known to be valid for $\mathrm{Re}(s)\geq 1$. In particular, $(\ast)$ for $s=1$:
$$
\sum_{q=1}^{\infty} \frac{c_q(n)}q = 0
$$
is equivalent to the Prime Number Theorem. 
Moreover, validity of $(\ast)$ for $\mathrm{Re}(s)>\frac12$ is implied by the Riemann Hypothesis.
