# Thread: Fourier series of a box function.

1. ## Fourier series of a box function.

Hey all,
I've been working on a question, and I was whether someone could go through my work and see where I went wrong.

The problem is:
Find the fourier series of the box function on the domain $\displaystyle [-\pi,\pi]$:
$\displaystyle f(x)=\left\{\begin{array}{cc}1,& |x|\leq \frac{\pi}{2} \\0, & \frac{\pi}{2}\leq |x| \leq \pi \end{array}\right.$

I need to find the coefficients $\displaystyle A_m$ & $\displaystyle B_m$ for the fourier series on the domain $\displaystyle [-L,L]$ $\displaystyle \phi (x)=\frac{1}{2} A_0 + \displaystyle \sum _{m=1} ^{\infty}( A_m cos(\frac{m\pi x}{L})+B_m sin(\frac{m\pi x}{L}))$.
I can find the coefficients by using the following equations:
$\displaystyle A_m=\frac{1}{L}\int_{-L} ^L \phi (x) cos(\frac{m \pi x}{L})dx, m=0,1,2,...$ and
$\displaystyle B_m=\frac{1}{L}\int_{-L} ^L \phi (x) sin(\frac{m \pi x}{L})dx, m=1,2,...$

I decided, because the function is piecewise continuous, to complete the following integrals
$\displaystyle A_m=\frac{1}{\pi}\int_{-\frac{\pi}{2}} ^{\frac{\pi}{2}} \phi (x) cos(\frac{m \pi x}{\pi})dx$ and
$\displaystyle B_m=\frac{1}{\pi}\int_{-\frac{\pi}{2}} ^{\frac{\pi}{2}} \phi (x) sin(\frac{m \pi x}{\pi})dx$

Not from $\displaystyle -\pi$ to $\displaystyle \frac{-\pi}{2}$ and not from $\displaystyle \frac{\pi}{2}$ to $\displaystyle \pi$ as $\displaystyle \phi (x) = 0$ in these domains.

I find that $\displaystyle B_m=0$, and $\displaystyle A_m = \frac{2sin(m\pi )}{m \pi}$. I can find $\displaystyle A_0 =\frac{1}{\pi} \int_{-\frac{\pi}{2}} ^{\frac{\pi}{2}} dx= 1$.

Thus, my fourier series is the following:
$\displaystyle \phi (x) = \frac{1}{2} + \displaystyle \sum _{m=1} ^{\infty}( \frac{2sin(m\pi )}{m \pi} cos(m x))$.

The answer supplied is the following series.
$\displaystyle \phi (x)=\frac{1}{2}+\frac{2}{\pi} \displaystyle \sum _{m=1} ^{\infty}( \frac{(-1)^m}{2M+1} cos((2m+1) x))$

I feel my solution can not be transformed into that solution. Is there something wrong with my working?

2. Originally Posted by Silverflow
Hey all,
I've been working on a question, and I was whether someone could go through my work and see where I went wrong.

The problem is:
Find the fourier series of the box function on the domain $\displaystyle [-\pi,\pi]$:
$\displaystyle f(x)=\left\{\begin{array}{cc}1,& |x|\leq \frac{\pi}{2} \\0, & \frac{\pi}{2}\leq |x| \leq \pi \end{array}\right.$

I need to find the coefficients $\displaystyle A_m$ & $\displaystyle B_m$ for the fourier series on the domain $\displaystyle [-L,L]$ $\displaystyle \phi (x)=\frac{1}{2} A_0 + \displaystyle \sum _{m=1} ^{\infty}( A_m cos(\frac{m\pi x}{L})+B_m sin(\frac{m\pi x}{L}))$.
I can find the coefficients by using the following equations:
$\displaystyle A_m=\frac{1}{L}\int_{-L} ^L \phi (x) cos(\frac{m \pi x}{L})dx, m=0,1,2,...$ and
$\displaystyle B_m=\frac{1}{L}\int_{-L} ^L \phi (x) sin(\frac{m \pi x}{L})dx, m=1,2,...$

I decided, because the function is piecewise continuous, to complete the following integrals
$\displaystyle A_m=\frac{1}{\pi}\int_{-\frac{\pi}{2}} ^{\frac{\pi}{2}} \phi (x) cos(\frac{m \pi x}{\pi})dx$ and
$\displaystyle B_m=\frac{1}{\pi}\int_{-\frac{\pi}{2}} ^{\frac{\pi}{2}} \phi (x) sin(\frac{m \pi x}{\pi})dx$

Not from $\displaystyle -\pi$ to $\displaystyle \frac{-\pi}{2}$ and not from $\displaystyle \frac{\pi}{2}$ to $\displaystyle \pi$ as $\displaystyle \phi (x) = 0$ in these domains.

I find that $\displaystyle B_m=0$, and $\displaystyle A_m = \frac{2sin(m\pi )}{m \pi}$. I can find $\displaystyle A_0 =\frac{1}{\pi} \int_{-\frac{\pi}{2}} ^{\frac{\pi}{2}} dx= 1$.

Thus, my fourier series is the following:
$\displaystyle \phi (x) = \frac{1}{2} + \displaystyle \sum _{m=1} ^{\infty}( \frac{2sin(m\pi )}{m \pi} cos(m x))$.

The answer supplied is the following series.
$\displaystyle \phi (x)=\frac{1}{2}+\frac{2}{\pi} \displaystyle \sum _{m=1} ^{\infty}( \frac{(-1)^m}{2M+1} cos((2m+1) x))$

I feel my solution can not be transformed into that solution. Is there something wrong with my working?

Being $\displaystyle \Phi(x)$ an even function it is immediate that $\displaystyle B_m=0\,\,\forall m$ . Now, for $\displaystyle A_m$ you get:

$\displaystyle A_m=\frac{1}{\pi}\int\limits^{\pi/2}_{-\pi/2}\cos mxdx=\frac{1}{m\pi}\sin mx\left|^{\pi/2}_{-\pi/2}\right.=\frac{2}{m\pi}\sin\frac{m\pi}{2}$ , but we know that $\displaystyle \sin\frac{m\pi}{2}=\left\{\begin{array}{rl}0&if\,m =0,2\!\!\pmod 4\\-1&if\,m=3\!\!\pmod 4\\1&if\,m=1\!\!\pmod 4\end{array}\right.$ ,

so the only non-zero values are obtained from the odd indexes (which is what you have in your answer!). Try to continue from here

Tonio

3. You went wrong in calculating the integral for $\displaystyle A_m$. It should be

$\displaystyle A_m = \frac{1}{\pi}{\displaystyle\int_{-\pi/2} ^{\pi/2}}\!\! f (x) \cos\bigl(\frac{m \pi x}{\pi}\bigr)\,dx = \frac{1}{\pi}{\displaystyle\int_{-\pi/2} ^{\pi/2}}\!\!\! \cos(mx)\,dx = \Bigl[\frac1m\sin(mx)\Bigr]_{-\pi/2} ^{\pi/2} = \frac1m\bigl(\sin\frac{m\pi}2 - \sin\frac{-m\pi}2\bigr).$

But $\displaystyle \sin(-\theta) = -\sin\theta$. So $\displaystyle A_m = \frac2m\sin\frac{m\pi}2$. Next, $\displaystyle \sin\frac{m\pi}2$ is 0 if m is even, and it is alternately +1 and –1 if m is odd. That should get you to the required form of the answer.

Edit. Beaten to it by tonio!

4. Thanks for that, both of you. So, M becomes 2M+1 because sine is only +/- 1 at odd indexes? Was it really necessary to change M to 2M + 1? Is there a real significant change to having 1 or -1 divided by an odd integer than a even integer in this case?

5. Originally Posted by Silverflow
Thanks for that, both of you. So, M becomes 2M+1 because sine is only +/- 1 at odd indexes? Was it really necessary to change M to 2M + 1?

Well, that way you have a closed, nice and simple formula for $\displaystyle A_n$...

Tonio

Is there a real significant change to having 1 or -1 divided by an odd integer than a even integer in this case?
.

6. Rightio, cheers.

7. Sorry, just one more question that I have. What if the function is now $\displaystyle f(x)=\left\{\begin{array}{cc}1,& |x|< \frac{\pi}{2} \\0, & \frac{\pi}{2} < |x| < \pi \end{array}\right$ on the domain $\displaystyle (-\pi,\pi)$? Does the Fourier series change as the function is no longer piecewise continuous?

8. Originally Posted by Silverflow
Sorry, just one more question that I have. What if the function is now $\displaystyle f(x)=\left\{\begin{array}{cc}1,& |x|< \frac{\pi}{2} \\0, & \frac{\pi}{2} < |x| < \pi \end{array}\right$ on the domain $\displaystyle (-\pi,\pi)$? Does the Fourier series change as the function is no longer piecewise continuous?

Says who? As you're going to continue the definition of f(x) periodically, the function (in all the reals) is

too piecewise continuous!

Tonio

9. Ok, that makes sense. Thank you soo much for your time.