# 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 $[-\pi,\pi]$:
$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 $A_m$ & $B_m$ for the fourier series on the domain $[-L,L]$ $\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:
$A_m=\frac{1}{L}\int_{-L} ^L \phi (x) cos(\frac{m \pi x}{L})dx, m=0,1,2,...$ and
$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
$A_m=\frac{1}{\pi}\int_{-\frac{\pi}{2}} ^{\frac{\pi}{2}} \phi (x) cos(\frac{m \pi x}{\pi})dx$ and
$B_m=\frac{1}{\pi}\int_{-\frac{\pi}{2}} ^{\frac{\pi}{2}} \phi (x) sin(\frac{m \pi x}{\pi})dx$

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

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

Thus, my fourier series is the following:
$\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.
$\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?

Thanks for your time.

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 $[-\pi,\pi]$:
$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 $A_m$ & $B_m$ for the fourier series on the domain $[-L,L]$ $\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:
$A_m=\frac{1}{L}\int_{-L} ^L \phi (x) cos(\frac{m \pi x}{L})dx, m=0,1,2,...$ and
$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
$A_m=\frac{1}{\pi}\int_{-\frac{\pi}{2}} ^{\frac{\pi}{2}} \phi (x) cos(\frac{m \pi x}{\pi})dx$ and
$B_m=\frac{1}{\pi}\int_{-\frac{\pi}{2}} ^{\frac{\pi}{2}} \phi (x) sin(\frac{m \pi x}{\pi})dx$

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

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

Thus, my fourier series is the following:
$\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.
$\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?

Thanks for your time.

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

$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 $\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 $A_m$. It should be

$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 $\sin(-\theta) = -\sin\theta$. So $A_m = \frac2m\sin\frac{m\pi}2$. Next, $\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 $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 $f(x)=\left\{\begin{array}{cc}1,& |x|< \frac{\pi}{2}
\\0, & \frac{\pi}{2} < |x| < \pi \end{array}\right$
on the domain $(-\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 $f(x)=\left\{\begin{array}{cc}1,& |x|< \frac{\pi}{2}
\\0, & \frac{\pi}{2} < |x| < \pi \end{array}\right$
on the domain $(-\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.