Understanding the Discrepancy in Fourier Coefficients of a Piecewise Function

56 Views Asked by At

Given the following peicewise function: $$f(t) = \begin{cases} 2 \quad &\text{ if } \quad t \in [0, \pi) \\ -4 \quad &\text{ if } \quad t \in [\pi, 2 \pi) \end{cases},$$ I want to calculate the fourier coefficients $c_k$ such that $$f(x) = \sum_{k = - \infty}^\infty c_k e^{i k x}.$$

My approach is the following: $$c_k = \frac{1}{2 \pi} \int_0^{2\pi} f(t) e^{-ikt}dt = \frac{1}{2 \pi} ( 2 \cdot \int_0^{\pi}e^{-ikt}dt - 4 \cdot \int_{\pi}^{2\pi} e^{-ikt}dt) = \frac{1}{2 \pi} (2 \cdot \biggl [\frac{i}{k}e^{-ikt} \biggl ]_0^{\pi} - 4 \cdot \biggl [\frac{i}{k}e^{-ikt} \biggl ]_{\pi}^{2\pi}) \\ = \frac{1}{2 \pi} \biggl ( 2 \frac{i}{k} ((-1)^k -1) - 4 \frac{i}{k} ( 1 - (-1)^k) \biggl ) = \begin{cases} 0 \quad \quad &\text{ if } \quad 2 \mid k \\ \frac{i}{k} \frac{-6}{\pi} \quad &\text{ if } \quad 2 \nmid k \end{cases}$$

When I plotted this (for $k = \{ -101, -100, ..., 101 \}$) (see the attached image link), I got a function that is more between $3$ and $-3$ instead of the expected $2$ and $-4$. Subtracting one gives the desired result.

What are the reasons I'm off by $1$ and/or what am I doing wrong?

incorrect