I've realised that any periodic $f(t)$ with period $2L$ can be rewritten as
$$ f(t)=a_0+\sum_{n=1}^\infty[a_n\cos(\frac{\pi{n}}Lt)+b_n\sin(\frac{\pi{n}}Lt)] $$
where the coefficients are calculated using the following integrals:
$$ \begin{align*} a_0&=\frac1{2L}\int_a^{a+2L}f(t)\,dt\\ a_n&=\frac1L\int_a^{a+2L}f(t)\cos(\frac{\pi{n}}Lt)\,dt\\ b_n&=\frac1L\int_a^{a+2L}f(t)\sin(\frac{\pi{n}}Lt)\,dt \end{align*} $$
I want to come up with new expressions for the coefficients that would work on discrete input sequences such as $v=(1,1,1,1,-1,-1,-1,-1)$.
The Aim
Here is a demos graph with an example of what I'm aiming for.
I'm aiming to be able to take as inputs the list of values $v$ and the variable $\delta{t}$ which specifies the time/x-distance between the y-values in $v$, and I want to output the coefficients $a_0$, $a_n$ and $b_n$.
I just tried converting straight from integrals to summations (based on the fact that $\int_a^bf(x)dx=\lim_{\delta{x}\to0}\sum_{x=a}^bf(x)\delta{x}$)
I thought these would work:
$$ \begin{align*} a_0&=\frac1{2L}\sum_{t=a}^{a+2L}v_t\delta{t}\\ a_n&=\frac1L\sum_{t=a}^{a+2L}v_t\cos(\frac{\pi{n}}Lt)\delta{t}\\ b_n&=\frac1L\sum_{t=a}^{a+2L}v_t\sin(\frac{\pi{n}}Lt)\delta{t} \end{align*} $$
Where obviously $v_t$ is the $t^\mathrm{th}$ element of the sequence $v$, $\delta{t}$ is the x-distance/time between each element of the sequence and $2L$ is the period of the sequence.
I tried to use these in demos but it didn't work at all, gave me very messy, chaotic, non-periodic (I think) graphs.
What's the correct way of performing a Fourier transform on a sequence?
My specific application will be taking in a list of samples of audio as the sequence, knowing that the time between each sample is $\frac1{44100}$ seconds, and hopefully finding the Fourier series approximation of that data set.