# Fourier Series - Square Wave

1. Oct 1, 2015

### BOAS

Hello,

I think that I have done this correctly, but this is the first problem I have done on my own and would appreciate confirmation.

1. The problem statement, all variables and given/known data

Find the Fourier series corresponding to the following functions that are periodic over the interval $(−π, π)$ with: (a) $f(x) = 1$ for $−\frac{π}{2} < x < \frac{π}{2}$ and $f(x) = 0$ otherwise.

2. Relevant equations

3. The attempt at a solution

The first coefficient $a_{0} = \frac{1}{\pi} \int^{0.5\pi}_{-0.5\pi} f(x) dx = 1$

$a_{n} = \frac{1}{\pi} \int^{0.5\pi}_{-0.5\pi} \cos(nx) dx$

$a_{n} = - \frac{1}{n \pi} ((-1^{n}) - 1)$

$b_{n} = \frac{1}{\pi} \int^{0.5 \pi}_{-0.5 \pi} \sin(nx) dx = 0$

so my Fourier series is;

$f(x) = 1/2 + \frac{2}{\pi}(\cos(x) - \frac{1}{3}\cos(3x) + \frac{1}{5}\cos(5x) - ... + )$

or $f(x) = \frac{1}{2} + \Sigma^{\infty}_{n = 1} (- \frac{1}{n \pi}( (-1)^{n} - 1)) \cos(nx)$

Does this look ok?

Thanks

Last edited: Oct 1, 2015
2. Oct 1, 2015

### cellurl

all sins looks good. seems to add up to 1 at origin.

3. Oct 1, 2015

### BOAS

I think I have made a mistake somewhere, based on some plots I made in mathematica.

It does not appear to be creating a square wave.

I will go through it again.

4. Oct 1, 2015

### BOAS

Aha! I have found the mistake.

The $a_{n}$ coefficients are related to $\cos(nx)$ not $\sin(nx)$

5. Oct 1, 2015

### Ray Vickson

No, it is not OK. Your formula for the coefficients give results that are either 0 or positive, because $-[(-1)^n - 1] = 1 - (-1)^n$ is 0 for even n and 2 for odd n. In fact, the $a_n$ for successive odd n should alternate in sign. (However, when you subsequently wrote out the first few terms of the series, you did have alternating signs. How did that happen?)

6. Oct 1, 2015

### BOAS

I computed several coefficients for a, which lead me to observe the alternating sign pattern. My mistaken formula was not used there, I evaluated the expression for each.

I don't know if this is the prettiest formula, but it does the trick.

$a_{n} = \frac{2}{\pi + 2(n-1) \pi} (-1)^{n-1}$

7. Oct 1, 2015

### Ray Vickson

Another one is
$$a_n = \frac{2}{\pi} \frac{\sin(n \pi/2)}{n}.$$

8. Oct 1, 2015

### BOAS

This result pops out very easily when performing the integral that defines a_n.

I was trying to find an algebraic expression to model that, mainly because it's what I saw on an example in class. Am I just making things harder on myself, or is there any benefit to showing it like this?

9. Oct 1, 2015

### Ray Vickson

Well, the numerator of the second fraction is 0 for even n, is +1 for n = 1, 5, 9, ... and is -1 for n = 3, 7, 11, ... .All you need to do is find a nifty way of describing that in a formula that does not involve trig functions, etc. It might be easier to write the relevant n in the form n = 2m+1, m = 0, 1, 2, ... . Now we need +1 for even m and -1 for odd m, so $(-1)^m$ will do it. That is,
$$a_{2m+1} = \frac{2 (-1)^m}{\pi (2m+1)}$$