I use this formula for the Fourier Transform, preferring the angular frequency $\omega$ over the ordinary frequency $f$:
$$ f(x) = \frac{1}{2\pi} \int_{-\infty}^{\infty} F(\omega) e^{i\omega x} d\omega \\ F(\omega) = \int_{-\infty}^{\infty} f(x) * e^{-i\omega x} dx $$
Given a non-periodic box function, let's call it $g(x)$:
$$ g(x) = \begin{cases} A & \text{if } -\frac{1}{2} \lt x \lt \frac{1}{2} \\ 0 & \text{otherwise} \\ \end{cases} $$
(Where $A \in R_{+}$ is a constant)
I've calculated the $G(\omega)$ for $g(x)$:
$$ G(\omega) = \int_{-\frac{1}{2}}^{\frac{1}{2}} A * e^{-i\omega x} dx = A * \frac{e^{-i\omega x}}{-i\omega}\Bigr|_{-\frac{1}{2}}^{\frac{1}{2}} = A * \frac{e^{\frac{i\omega}{2}} - e^{\frac{-i\omega}{2}}}{i\omega} \\ $$
That simplifies to:
$$ G(\omega) = A * \frac{2}{\omega} * sin(\frac{\omega}{2}) = A * \frac{sin(\frac{\omega}{2})}{\frac{\omega}{2}} $$
Until now, everything is clear (unless I've made a mistake).
Now, I want to use the Fourier Transform to approximate my initial function $g(x)$ as a $\sum$ of sinusoids.
Using the inverse Fourier Transform $g(x)$ can be written as:
$$ g(x)=\frac{1}{2\pi} \int_{-\infty}^{\infty} G(\omega) * \underbrace{e^{i\omega x}}_{\text{sinusoid}} d\omega $$
So my relationship becomes:
$$ g(x)=\frac{1}{2\pi} \int_{-\infty}^{\infty} \frac{2*A}{\omega} * sin(\frac{\omega}{2}) * e^{i\omega x} d\omega $$
How do I identity and extract the most relevant 10 terms (sinusoids) from the Inverse Fourier Transform so I can express $g(x) \approx \sum_{n=1}^{10} \text{?sinusoid?}$.
If I plug in some values for $\omega$ and plot the results, there is nothing like the initial box function. So, I suspect I might be doing something incorrect (from a mathematical standpoint).
This makes me ask a secondary question: Is my assumption correct that the Inverse Fourier Transform can still be approximated as sum of sinusoids? If yes, how can I read of the imaginary part, as my initial function was on R.
Since the function
$$g_A(x)=\left\{\begin{array}{cc} A & -\frac{1}{2}<x<\frac{1}{2} \\ 0 & \text{Otherwise} \\ \end{array}\right.\tag{1}$$
is an even function of $x$ it can be approximated by the cosine Fourier series
$$g_A(x) \approx a_0+\underset{K\to\infty}{\text{lim}}\left(\sum\limits _{n=1}^K a_n \cos \left(\frac{2 \pi n x}{P}\right)\right)\tag{2}$$
on the interval $-\frac{P}{2}<x<\frac{P}{2}$ where
$$a_0=\frac{1}{P} \int\limits_{-\frac{P}{2}}^{\frac{P}{2}} g(x) \, dx=\frac{A}{P}\tag{3}$$
and for $n\ne0$
$$a_n=\frac{2}{P} \int\limits_{-\frac{P}{2}}^{\frac{P}{2}} g(x)\, \cos\left(\frac{2 \pi n x}{P}\right) \, dx=\frac{2 A}{\pi}\, \frac{\sin\left(\frac{\pi n}{P}\right)}{n}\tag{4}$$
so in a sense one has
$$g_A(x) \approx \underset{P\to\infty}{\text{lim}}\left(\frac{A}{P}+\frac{2 A}{\pi}\, \underset{K\to\infty}{\text{lim}}\left(\sum\limits_{n=1}^K \frac{\sin\left(\frac{\pi n}{P}\right)}{n}\, \cos\left(\frac{2 \pi n x}{P}\right)\right)\right)\tag{5}.$$
The exponential Fourier series for $g_A(x)$ on the interval $-\frac{P}{2}<x<\frac{P}{2}$ is
$$g_A(x) \approx \underset{K\to\infty}{\text{lim}}\left(\sum\limits_{n=-K}^K c_n\, e^{\frac{2 i \pi n x}{P}}\right)\tag{6}$$
where
$$c_n=\frac{1}{P} \int\limits_{-\frac{P}{2}}^{\frac{P}{2}} g_A(x)\, e^{-\frac{i 2 \pi n x}{P}} \, dx=\frac{A}{\pi}\,\frac{\sin\left(\frac{\pi n}{P}\right)}{n}\tag{7}$$
and
$$c_0=a_0=\frac{1}{P} \int\limits_{-\frac{P}{2}}^{\frac{P}{2}} g(x) \, dx=\frac{A}{P}=\underset{n\to 0}{\text{lim}}\left(\frac{A}{\pi}\, \frac{\sin\left(\frac{\pi n}{P}\right)}{n}\right)\tag{8}$$
so in a sense one has
$$g_A(x) \approx \underset{P\to\infty}{\text{lim}}\left(\frac{A}{\pi}\, \underset{K\to\infty}{\text{lim}}\left(\sum\limits_{n=-K}^K \frac{\sin\left(\frac{\pi n}{P}\right)}{n}\, e^{\frac{2 i \pi n x}{P}}\right)\right)\tag{9}.$$
Formula (9) above can also be evaluated as
$$g_A(x) \approx \underset{P\to\infty}{\text{lim}}\left(\frac{A}{P}+\frac{A}{\pi}\underset{K\to\infty}{\text{lim}}\left(\sum\limits_{n=1}^K \left(\frac{\sin\left(-\frac{\pi n}{P}\right)}{-n}\, e^{-\frac{2 i \pi n x}{P}}+\frac{\sin\left(\frac{\pi n}{P}\right)}{n}\, e^{\frac{2 i \pi n x}{P}}\right)\right)\right)\tag{10}$$
and since
$$\frac{A}{\pi} \left(\frac{\sin\left(-\frac{\pi n}{P}\right)}{-n}\, e^{-\frac{2 i \pi n x}{P}}+\frac{\sin\left(\frac{\pi n}{P}\right)}{n}\, e^{\frac{2 i \pi n x}{P}}\right)=\frac{2 A}{\pi}\, \frac{\sin\left(\frac{\pi n}{P}\right)}{n}\, \cos\left(\frac{2 \pi n x}{P}\right)\tag{11}$$
the exponential Fourier series defined in formula (9) above is equivalent to the cosine Fourier series defined in formula (5) above.
The function $g_A(x)$ can also be approximated as
$$g_A(x) \approx \frac{A}{\pi}\, \underset{f\to\infty}{\text{lim}} \left(\text{Si}\left(2 f \pi \left(x+\frac{1}{2}\right)\right)-\text{Si}\left(2 f \pi \left(x-\frac{1}{2}\right)\right)\right)\tag{12}$$
where $\text{Si}(z)$ is the sine integral function.