So I'm trying to approximate the Square wave using Sine and Cosine waves as something to learn while we have a stay at home order.
I defined my square wave as
$$\tag{1}\text{square}(t)=\text{sgn}(\sin(t)), t\in[-\pi,\pi]$$
To take the Fourier transformation of this, I converted it to the following integral:
$$\tag{2}c_k=\frac{1}{2\pi}\int_{-\pi}^{0}{-e^{-i k t}dt}+\frac{1}{2\pi}\int_0^{\pi}{e^{-i k t}dt}$$
Where $c_k$ is the $k$th Fourier coefficient in the approximation.
$$\tag{3}\begin{align}\frac{1}{2\pi}\left(\int_0^{\pi}{e^{-i k t}dt}-\int_{-\pi}^{0}{e^{-i k t}dt}\right) &=\frac{1}{2\pi}\left(\frac{i e^{-i k t}}{k}\bigg\rvert_{0}^{\pi} - \frac{i e^{-i k t}}{k}\bigg\rvert_{-\pi}^{0} \right)\\ &=\frac{1}{2\pi}\left[\left(\frac{ie^{-i k \pi}}{k}-\frac{i}{k}\right)-\left(\frac{i}{k}-\frac{ie^{i k \pi}}{k} \right) \right] \\ &= \frac{1}{2\pi}\left(\frac{ie^{-i k \pi}-i}{k}-\frac{i+ie^{i k \pi}}{k}\right) \\ &= \frac{1}{2k\pi}\left(ie^{-ik\pi}+ie^{ik\pi}-2i\right) \\ &= \frac{i}{2k\pi}\left(e^{-ik\pi}+e^{ik\pi}-2\right) \\ &= \frac{i\left(e^{-ik\pi}+e^{ik\pi}-2\right)}{2k\pi} \end{align}$$
The problem is, I can't calculate the DC offset using this formula since at $k=0$ we are dividing by $0$. I understand that I can just plug $0$ into $k$ inside the integral and do it that way, but I'd like to have a derived function to calculate the $k$th coefficient that works for all $k$. I also know that $c_0$ in here is $0$, but it bothers me that I can't plug $k=0$ into the formula and get $0$ as output. Is there a way (hopefully in Mathematica as well) to multiply this by something to get rid of the denominator so the formula will work at $k=0$?