The square wave is 1 from 0 to π, and 0 from π to 2π. Setting quantum physics aside for the moment, a vibrating object, or even a voltage, does not instantaneously drop from 1 to 0, then jump back up from 0 to 1. The real-world square wave drops to 0 as quickly as possible, then shoots back up to 1 for the start of the next cycle. However, if you're using transisters that change state in a trillionth of a second, the resulting wave form is pretty dog gone close to a perfect square wave.
the "duty cycle" of our square wave is 50%. It is up half the time, and down half the time. Some people define a square wave as any wave form that is high for part of the cycle and low for the remainder of the cycle. The "on" ratio is called the duty cycle, and is usually described as a percentage of the whole.
If you run your microwave at half power, it is probably implemented as a duty cycle. The fan runs all the time, but you can hear the microwave transmitter turning on and off, with a duty cycle of 50%. (This is because the microwave cavity cannot easily run at half power; it's easier to turn it on and off.) Try other power settings and you'll see what I mean.
What are the fourier coefficients for the square wave, and does the resulting fourier series converge to the square wave?
Rescale the wave so that it is centered on the x axis. In other words, g(x) = 1 for x in [0,π], and -1 for x in [π,2π]. We need to integrate sin(nx), or cos(nx), times 1 or -1, from 0 to π or from π to 2π. After some calculus, the cosine terms drop out, and so do the sine terms when n is even. For n odd, the integral of g(x)×sin(nx) is 4/n. Divide by π to get the fourier coefficients: bn = 4 over nπ, where n is odd. Let f(x) be the fourier series, which should equal g(x).
f(x) = 4/π × ( sin(x) + sin(3x)/3 + sin(5x)/5 + sin(7x)/7 + … )
Evaluate this at x = 0 or π, the two jump discontinuities. The result is 0, which is halfway between the two levels. This is how fourier series work. They attain the average when evaluated at a jump discontinuity.
Next let x = π/2, and obtain 4/π times the alternating series (1 - 1/3 + 1/5 - 1/7 + 1/9 …). This is the taylor expansion of atan(), evaluated at 1. In other words, we have the arctangent of 1, which is π/4, times 4/π, giving 1. Thus f(π/4) = 1, as it should. Similarly, f(3π/4) = -1, as it should.
When a series is conditionally convergent, the order of the terms is significant. We could set f(π/4) equal to anything we like, simply by rearranging the terms of the fourier series. The series is only equal to g(x) when we take the terms in the order of increasing harmonics.
Does conditional convergence cause any trouble in the real world? No - because at some point the higher harmonics drop out. Flipping your hand back and forth through the air does not produce whispers of pressure waves in the gigahurtz range. Even if it did, they would be swamped by the thermal vibrations of the air. And the highest harmonics are rendered impossible by the quantum nature of matter and energy, and perhaps time itself. For an engineer, the fourier series is finite, and convergence is a non-issue. But this is a math site, not an engineering site, so I'm going to investigate convergence, at least a little bit.
1 + x2 + x4 + x6 + x8 …
Integrate the above to get the following taylor series, which I will call h.
h(x) = x + x3/3 + x5/5 + x7/7 + x9/9 + …
This is starting to look like our fourier series. But what is this function, and where does it converge? We can answer the second question first. We know that the expansion of 1/(1-x2) converges as long as x has a norm less than 1. In the complex plane, the circle of convergence is the interior of the unit circle.
Within the unit circle, 1/(1-x2), or its taylor series, can be integrated. For each point x inside the unit circle, the integral from 0 to x is well defined, hence the taylor series converges to that integral. Therefore h(x) converges to an analytic function inside the unit circle.
What is this function anyways? We evaluated the integral of 1/(1-x2) in another section, and obtained the following.
h(x) = ½ log( (1+x) / (1-x) )
Of course we're not just plugging x into the taylor series, x has to become sin(x), and x3 has to look like sin(3x), and x5 becomes sin(5x), and so on. How can we pull this off?
Consider Eix, where i is the square root of -1. When x is real, ix is pure imaginary, and E to this power runs counterclockwise around the unit circle. The imaginary component of this expression is sin(x). Write it this way.
sin(x) = im(Eix)
What if Eix is raised to the third power? This is the same as E3ix, and the imaginary component is sin(3x). This gives us a way to plug sin(nx) into our taylor series.
Let v be the analytic function Eix, where x runs from 0 to 2π. Plug v into h(), then take the imaginary component of the result, which is the same as adding the imaginary components of the terms of h(v). The imaginary components look like sin(nx)/n, which are our fourier functions. The fourier series is proportional to im(h(v(x))).
Ok, but h() doesn't necessarily converge on the unit circle, and v is always on the unit circle, so what gives?
for starters, we don't have convergence when v = ±1. This gives the function 1/(1-v2) a zero denominator, and that's the function we integrated to obtain h(v). The good news is, we don't care about v = ±1, because we already evaluated f() at 0 and π, and the result was 0. These were the two jump discontinuities. So assume v is not 1 or -1.
Pull v inside the unit circle for a moment, where h is known to converge. When v is real, between -1 and 1, 1+v and 1-v are real, with angles of 0. Their quotient has an angle of 0, and log() extracts this angle and projects it onto the imaginary component. Thus im(h(v)) = 0 when v is real.
Now move v up from the real line. Consider the triangle formed by v and the diameter [-1,1]. As v moves towards the edge of the unit circle, it approaches the apex of an inscribed angle, which is always 90 degrees. The base angles are complementary. Let the left most angle, corresponding to 1+v, approach θ as v moves towards the circumference. Let w be the reflection of v through the origin, thus w = -v. The angle corresponding to 1+w, or 1+-v, or 1-v, approaches the opposite of the complement of θ, or θ-90. Subtract these two angles, as directed by (1+v)/(1-v), and the quotient has an angle that approaches 90 degrees. Apply the factor of ½, and im(h(v)) approaches 45 degrees, or π/4. When v moves below the real line, and towards the lower half of the unit circle, the signs are reversed, and im(h(v)) approaches -45 degrees, or -π/4.
But remember, v is on the unit circle. Does h(v) converge? The taylor series consists of powers of v, which all lie on the unit circle, times the reciprocals, which approach 0. Use abel summation to demonstrate convergence.
The imaginary components of h() converge to + or - π/4, and when this is scaled by 4/π, the result is the fourier series for our square wave, which converges to 1 or -1. Setting the jump discontinuities aside, f(x) = g(x).
After 20 years I'm still amazed. An infinite series of sine waves converges to a function that is perfectly flat from 0 to π, then jumps to another level, also perfectly flat, from π to 2π. It's beautiful.
If you look again at abel summation, the speed of convergence depends on the reciprocals of the integers and the radius 1. It does not depend on x or v. Therefore f(x) converges uniformly to g(x).
The beeps produced by your in-built PC toggle speaker take the form of a square wave. The speaker turns on and off, 1,000 times a second, producing the familiar control-G bell. But the tone sounds harsh to our ears. It sounds like a computer, rather than a sound of nature. This is because square waves don't occur in nature. Objects don't jump back and forth in sudden jerks; they swing back and forth under the control of a restoring force. The first few harmonics may be present at modest energy levels - that's how we distinguish spoken vowels - but nature doesn't crank out the high harmonics of a square wave. So the PC speaker sounds a bit odd to us - like, er um, like a computer.
The first coefficient, a0, equals q/π, which is the duty cycle of the pulse.
Since sin(nx) is an odd function, and our pulse is an even function, the sine waves all drop to 0. We only need consider the cosine terms.
Multiply the pulse by cos(nx) and integrate to get 2×sin(nq)/n. Thus an = 2×sin(nq) over nπ.
As a sanity check, let's reproduce the square wave we analyzed earlier. The fourier coefficients should be the same. Replace q with ½π, giving the desired 50% duty cycle. Now sin(nq)/n builds an alternating sum of odd reciprocals, which is starting to look familiar. Next, double the amplitude, because this pulse jumps from 0 to 1, and our original square wave ran from -1 to 1. This turns 2/π into 4/π, which also looks familiar. Finally, phase shift the wave by replacing x with x-½π. This turns cosines into sines, and cancels the minus signs in our alternating series, so that all coefficients become positive. Sure enough, the earlier formula reappears.
If g(x) is a general pulse of width 2q, and f(x) is the fourier series derived above, does f(x) converge to g(x)?
Replace sin(nq)×cos(nx) with ½sin(nq+nx) + ½sin(nq-nx), courtesy of the angle addition formula.
Split f into two phase shifted fourier series, where f1 is based on ½sin(nq+nx), and f2 is based on ½sin(nq-nx).
Look at f1 without its phase shift, i.e. without the nq offset. Derive the fourier coefficients for the resulting sine waves: bn = 1 over nπ,for all n > 1. This is different from the square wave presented earlier. As you recall, only the odd terms were present. Thus we built a taylor series based on 1/(1-x2). This time all terms are present, so build a taylor series based on 1/(1-x). This function converges on the unit circle, and so does its integral, which is -log(1-x). Define h(x) as follows.
h(x) = x + x2/2 + x3/3 + x4/4 + x5/5 + x6/6 + … = -log(1-x)
As before, h will not be evaluated at just any x. Instead, consider h(v), where v(x) is Eix. the imaginary component of h(v(x)) is the sum of sin(nx)/n, i.e. the sum of our fourier functions. It is also the opposite of the angle of 1-v.
Convergence is assured inside the unit circle. Use abel summation, as we did before, to show h(v) converges on the unit circle (for v ≠ 1), and that this convergence is uniform. (We'll deal with v = 1 later.)
When v is real, between -1 and 1, the angle is 0. Move v up from the real line and the angle of 1-v becomes negative. Take the opposite to get a positive angle. Let's try to quantify this in terms of x.
Let v = Eix, where x ranges from -π to +π. Start with x positive, hence v is on the upper half of the unit circle. Now x measures both an arc and a central angle. Draw a diameter from v, through the origin, to w, which is -v. Some geometry shows the angle of 1+w, or 1-v, is -½(180-x). The opposite of this angle is 90-½x. The graph slopes down from π/2 to 0, as x runs from 0 to π.
When x is negative, v moves around the bottom half of the unit circle, and its reflection, w, is on top. The angle of 1+w is ½(180+x). The opposite of this is -90-½x. The graph slopes up from -π/2 to 0, as x runs from 0 to -π.
Don't forget the scaling factor on the fourier coefficients. Multiply the graph by 1/π, and the graph has a range from -½ to ½.
Replace x with x+q to find f1. This shifts the graph to the left, so that its apex is above -q, and it slopes down to the right from there.
Within f2, x is negated, so the graph slopes down and to the left. Replace x with x-q, which slides the graph to the right, and places the apex above q.
Now add f1 and f2 together. The wave form is flat from -q to q, with a height of 1-q/π. Outside of this region, the sum is also flat, with a height of -q/π. The difference in levels is 1, as we expect.
Remember that a0, the first term in f(x), is q/π. Add this in, and the levels are 0 and 1. Thus f(x) converges uniformly to g(x).
Take a moment to look at the jump discontinuities. When x is -q, f1(q) = 0. The series f2 converges in its usual way, to ½-q/π. Add these together, plus the term a0, and f(-q) = ½, which is halfway between the two levels. Using similar algebra, f(q) = ½.
Let g() be piecewise constant, with k steps from 0 to 2π. Note that each step in g() implies a pulse of a certain width and height. The next step, up or down, defines another pulse, and so on.
Find the fourier coefficients of g using integration, as usual. Each of these integrals is the concatenation, or the sum, of the integrals over each rectangular step. Thus the fourier series for g can be separated into k subseries, one for each step. Each of these converges uniformly to the corresponding pulse. Add the k series back together to build f(x), and f converges uniformly to g.
Consider the jump discontinuity between successive steps. Let the first step have level s, while the second step has level t. At the right edge of s, the subseries that defines this pulse attains a value of ½s, the average of s and 0. similarly, the subseries that defines the next pulse attains a value of ½t at the boundary, the average of t and 0. The other pulses contribute 0 at this point. Therefore f attains a value of ½s+½t between the two steps. This is the average of the two levels.