1
$\begingroup$

I am computing the fourier series of the following function between $[-0.5, 0.5]$ $$\displaystyle f(t) = \frac{1}{2} - |t|$$ According to the definition of Fourier Series the coefficients are given by $$\displaystyle \hat f_n = \frac{-(-1)^n}{2\pi ^2 n^2} + \frac{1}{2\pi ^2 n^2}$$ That's easy to calculate. So far so good.

With the coefficients I know I can do the approximation of the function $f(t)$. But then how to plot, the frequency spectrum??

For example, I defined the function $f(t)$ in matlab and plot it from $-0.5$ to $0.5$ and got the triangle function. Now, I have the coefficients that depend on $n$ but what's the range of $n$? Plotting the coefficients will give me the frequency spectrum?

Please help me clarify this I'm really confused, seems I can't get the relation.

$\endgroup$
4
$\begingroup$

The coefficients of the Fourier series that you have computed are, in effect, the spectrum of the periodic signal consisting of the sum of signals $f(t)$ delayed in time or advanced in time by integer multiples of $1$ second. Mathematically, the Fourier transform of a periodic function has impulses in it with the impulse amplitudes being the Fourier series coefficients. The impulses occur at intervals of the period, in this instance $1$ second, and a "plot" of the spectrum typically shows a bunch of vertical arrows (a common representation of impulses) with the amplitude marked just above the arrowhead. In your case, assuming that you have computed the complex form of the Fourier series, you would get a series of such arrows extending from $n=0$ out to $\pm \infty$. Note that your formula $$ \hat f_n = \frac{-(-1)^n}{2\pi ^2 n^2} + \frac{1}{2\pi ^2 n^2} $$ is saying that $\hat{f}_n = 0$ when $n$ is even. Also, putting $n=0$ in the formula makes $\hat{f}_0$ undefined which is incorrect since $\hat{f}_0$ is the "DC value" which is $\frac{1}{4}$ by inspection.. So please do check your work. In particular, note that while integrating by parts as you are likely to be doing, the antiderivative $$\int e^{-j2\pi nt}\,\mathrm dt = \frac{e^{-j2\pi nt}}{-j2\pi n}$$ cannot be used when $n=0$: $\int 1 \,\mathrm dt = t$.

Note: if you computed the sine/cosine form of the Fourier series, then you should have found that the coefficients of the $\sin(2\pi nt)$ terms are all $0$ and your spectrum will extend from $n=0$ to $n=\infty$ only.

$\endgroup$
  • $\begingroup$ Thank you very much, that helped a lot. So, the values of $n$ have to be always integers right? As for the coefficients' formula, I checked it twice and I don't see any error but I do see that $\hat f_0$ becomes undefined... I checked also the fourier transform of a triangle signal and it is $sinc(w)^2$ which will explain the undefined value at 0, apart from that I can't see other errors. $\endgroup$ – BRabbit27 Apr 21 '13 at 22:04
  • $\begingroup$ Check your work again for $n=0$ because $\hat{f}_0$ is the "DC value" which is obviously not $0$. In general, whatever you or MATLAB or Mathematica or... is doing when calculating $\hat{f}_n$ cannot be extrapolated to $\hat{f}_0$ because the antiderivative $$\int \cos(n\omega t)\,\mathrm dt = \frac{\sin(n\omega t)}{n\omega}$$ cannot be used when $n=0$. $\endgroup$ – Dilip Sarwate Apr 21 '13 at 22:58
  • $\begingroup$ Ok. I'll check it and I got for $a_0 = 1/4$ and $a_n = \frac{1-cos(\pi n)}{2\pi ^2 n^2}$. Is this better? By the way, I computed this with the separate formulas for $a_0$, $a_n$. But when I used the general formula $c_n$ I got the previous result, why am I not getting the $1/4$ when using the latter? $\endgroup$ – BRabbit27 Apr 22 '13 at 6:46
  • $\begingroup$ @BRabbit27 See edited answer. $\endgroup$ – Dilip Sarwate Apr 22 '13 at 11:56
3
$\begingroup$

As correctly pointed out by Dilip Sarwate, the Fourier coefficients apply to the periodic continuation of your triangular function. However, they are also samples of the continuous Fourier transform of the original (non-periodic) triangular function. So the Fourier coefficients can also be used as a discrete approximation of the spectrum of the non-periodic function.

Let's now have a look at the formula for the coefficients. As you know, there are two representations for the Fourier coefficients. I learned them in this form:

$$f(t) = \frac{a_0}{2} + \sum_{n=1}^{\infty}\left (a_n\cos n\omega t + b_n\sin n\omega t \right )$$ $$a_0=\frac{2}{T}\int_{-T/2}^{T/2}f(t)dt,\; a_n=\frac{2}{T}\int_{-T/2}^{T/2}f(t)\cos n\omega tdt,\; b_n=\frac{2}{T}\int_{-T/2}^{T/2}f(t)\sin n\omega tdt,\; n\ge 1$$

with $\omega=\frac{2\pi}{T}$, where $T$ is the period of the function $f(t)$. The other representation uses complex coefficients:

$$f(t) = \sum_{n=-\infty}^{\infty}c_n e^{jn\omega t}$$ $$c_n=\frac{1}{T}\int_{-T/2}^{T/2}f(t)e^{-jn\omega t}dt$$

Let's first calculate the coefficients $a_n$ and $b_n$. We can immediately note that $b_n=0,\; n=1,2,\dots$ because the function under consideration is even. With $T=1$ we get

$$a_0=2\int_{-1/2}^{1/2}f(t)dt=\frac{1}{2}$$

Note that according to the definition I use, the DC component is $a_0/2=1/4$. For $a_n,\; n\ge 1,$ we have

$$a_n = 2\int_{-1/2}^{1/2}f(t)\cos 2\pi n tdt = 4\int_{0}^{1/2}f(t)\cos 2\pi n tdt =\\ =4\int_{0}^{1/2}\left (\frac{1}{2}-t\right )\cos 2\pi n tdt = 2\int_{0}^{1/2}\cos 2\pi n t dt - 4\int_{0}^{1/2}t\cos 2\pi n tdt$$

Due to symmetry, the first term is zero. The second term can be obtained by integrating by parts:

$$a_n = -4\int_{0}^{1/2}t\cos 2\pi n tdt = \frac{1-\cos n\pi}{(n\pi)^2} = \frac{1-(-1)^n}{(n\pi)^2}$$

For the complex coefficients we get

$$c_n=\int_{-1/2}^{1/2}f(t)e^{-j2\pi n t}dt = \frac{1}{2}\int_{-1/2}^{1/2}e^{-j2\pi n t}dt - \int_{0}^{1/2}te^{-j2\pi n t} + \int_{-1/2}^{0}te^{-j2\pi n t}$$

Again, the first term equals 0 due to symmetry. Combining the other two terms yields

$$-\int_{0}^{1/2}t\left ( e^{j2\pi n t} + e^{-j2\pi n t} \right )dt = -2\int_{0}^{1/2}t\cos 2\pi n t dt$$

which, apart from a factor 2, is the same integral as above for $a_n$. So we get

$$c_n = \frac{1-\cos n\pi}{2(n\pi)^2} = \frac{1-(-1)^n}{2(n\pi)^2}\tag{1}$$

The value $c_0$ can be obtained from $$c_0 = \int_{-1/2}^{1/2}f(t)dt$$ but it can also be obtained from (1) by calculating the limit $n\rightarrow 0$:

$$c_0 = \lim_{n\rightarrow 0}\frac{1-\cos n\pi}{2(n\pi)^2} = \frac{(n\pi)^2}{4(n\pi)^2}=\frac{1}{4}$$

where I used the Taylor series expansion of $\cos(x)$ at $x=0$.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.