Can You Confirm My Fourier Series Calculation for a Square Wave?

BOAS
Messages
546
Reaction score
19
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. Homework Statement


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.

Homework Equations

The Attempt at a Solution


[/B]
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

which leads to the following;

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:
Physics news on Phys.org
all sins looks good. seems to add up to 1 at origin.
 
cellurl said:
all sins looks good. seems to add up to 1 at origin.

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.
 
BOAS said:
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. Homework Statement


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.

Homework Equations

The Attempt at a Solution


[/B]
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

which leads to the following;

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 + \frac{2}{\pi}(\sin(x) - \frac{1}{3}\sin(3x) + \frac{1}{5}\sin(5x) - ... + )

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

Does this look ok?

Thanks

Aha! I have found the mistake.

The a_{n} coefficients are related to \cos(nx) not \sin(nx)
 
BOAS said:
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. Homework Statement


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.

Homework Equations

The Attempt at a Solution


[/B]
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

which leads to the following;

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 + \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

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?)
 
Ray Vickson said:
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?)

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}
 
BOAS said:
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}

Another one is
a_n = \frac{2}{\pi} \frac{\sin(n \pi/2)}{n}.
 
Ray Vickson said:
Another one is
a_n = \frac{2}{\pi} \frac{\sin(n \pi/2)}{n}.

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?
 
BOAS said:
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?

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)}
 
  • Like
Likes BOAS

Similar threads

Back
Top