Physics Library
 An open source physics library
Encyclopedia | Forums | Docs | Random  

First Complete Fourier Series - Square Wave

(Topic)

First Complete Fourier Series: Square Wave

FS04, FS05, and FS06 derived the machinery for computing Fourier coefficients. We now use that machinery from beginning to end on a genuinely nonsinusoidal periodic waveform.

The square wave is an ideal first complete example because it contains several important Fourier ideas at once:

  • the waveform is periodic but not sinusoidal,
  • symmetry eliminates entire families of coefficients,
  • the surviving coefficients can be evaluated exactly,
  • only odd harmonics remain,
  • the harmonic amplitudes decrease as 1∕n,
  • finite partial sums visibly approach the waveform away from jumps,
  • and the behavior near discontinuities previews the Gibbs phenomenon.

We begin on the reference interval [−π,π], then generalize the result to [−L,L] and to a time-periodic signal of period T.

1 Define the square wave carefully

Let A > 0. Define the function over one fundamental interval by

       {
         − A,  − π < x <  0,
f(x) =
         A,    0 < x <  π.
(1)

Extend the function periodically so that

f(x + 2π ) = f (x).
(2)

This is the odd square wave of amplitude A and period 2π.

PIC

Figure 1. The odd square wave has value −A on the negative half of each period and +A on the positive half. The isolated jump points do not affect any Fourier coefficient because changing a function at finitely many points does not change its definite integrals.

What value should we assign at x = 0, x = ±π, and the periodically repeated jump points?

For coefficient calculations, it does not matter. A definite integral is unchanged if the value of an integrable function is altered at one isolated point. We may therefore leave the jump values unspecified for now.

Later convergence articles will distinguish carefully between the value assigned to the original function and the value approached by its Fourier series at a jump.

2 Start from the complete real Fourier series

On [−π,π], the real Fourier series has the form

        a0   ∑∞
f (x ) ∼ 2--+     [an cos(nx) + bnsin(nx )].
             n=1
(3)

The coefficients derived in FS04 and FS05 are

      1∫  π
a0 = --    f (x)dx,
     π   −π
(4)

        ∫ π
an =  1-    f(x)cos(nx )dx,
      π  −π
(5)

and

        ∫ π
bn =  1-    f(x)sin(nx )dx.
      π  −π
(6)

A brute-force calculation could evaluate all three. But before integrating, we should inspect the waveform.

3 Symmetry first: the square wave is odd

For 0 < x < π,

f(x) = A.
(7)

Then −x lies in (−π, 0), where

f(− x) = − A.
(8)

Therefore

f(− x) = − f(x).
(9)

So the square wave is odd.

PIC

Figure 2. The waveform has origin symmetry. Reflecting a point through the origin changes both x and the sign of the function value, so f(−x) = −f(x).

This immediately determines two entire coefficient families.

3.1 The constant coefficient vanishes

Because an odd function integrated over a symmetric interval gives zero,

       ∫  π
a  = 1-    f (x )dx = 0.
 0   π   −π
(10)

Thus the mean value is

a
-0-=  0.
 2
(11)

This also makes physical sense: the signal spends equal portions of each period at +A and −A.

3.2 Every cosine coefficient vanishes

The cosine function is even:

cos(− nx ) = cos(nx).
(12)

The product of odd f(x) and even cos(nx) is odd. Therefore

      1 ∫ π
an =  --    f(x) cos(nx )dx =  0
      π  −π
(13)

for every n ≥ 1.

So before doing any difficult integral, symmetry has reduced the complete series to

        ∞
       ∑
f(x) ∼     bn sin(nx ).
        n=1
(14)

This is one of the main practical lessons of Fourier analysis:

inspect symmetry   before integrating.
(15)

4 Derive the sine coefficients step by step

Start from

        ∫ π
b  =  1-    f(x)sin(nx )dx.
 n    π  −π
(16)

Because f(x) changes formula at x = 0, split the integral there:

bn = 1-
π[∫                    ∫                  ]
   0                    π
     f(x)sin(nx )dx +     f(x) sin(nx )dx
  −π                   0. (17)

Substitute the two constant values of the square wave:

bn = 1
--
π[∫ 0                   ∫ π             ]
     (− A )sin(nx) dx +     A sin(nx )dx
  −π                    0. (18)

Factor out A:

bn = A
--
π[                                 ]
   ∫ 0              ∫ π
 −     sin(nx) dx +     sin(nx )dx
    − π              0. (19)

There is a shorter route. Since f(x) is odd and sin(nx) is odd, their product is even:

f (− x) sin(− nx ) = f(x)sin(nx ).
(20)

Therefore

∫ π                    ∫ π

 −π f(x)sin(nx) dx = 2  0 f (x)sin(nx) dx.
(21)

On 0 < x < π, f(x) = A, so

     2A  ∫ π
bn = ---     sin(nx )dx.
      π   0
(22)

Now integrate:

∫                cos(nx )
  sin(nx )dx = − --------.
                    n
(23)

Hence

bn = 2A
---
π[  cos(nx )]
 − --------
      n0π (24)
= 2A
---
π(                  )
    cos(nπ)   cos 0
  − --------+ -----
       n        n. (25)

Use

               n
cos(n π) = (− 1)
(26)

and

cos0 = 1.
(27)

Then

bn =  2A-[1 − (− 1)n].
      nπ
(28)

PIC

Figure 3. The sine coefficient calculation collapses to one integral over the positive half-period. The factor 1 − (−1)n then separates odd and even harmonic numbers automatically.

5 Separate odd and even harmonic numbers

Equation (28) contains the entire harmonic-selection rule.

5.1 If the harmonic number is even

Let

n = 2k.
(29)

Then

    n        2k
(− 1) = (− 1)  =  1.
(30)

Therefore

bn = 2A-(1 − 1) = 0.
     nπ
(31)

Every even sine harmonic vanishes.

5.2 If the harmonic number is odd

Let

n = 2k + 1.
(32)

Then

    n        2k+1
(− 1 ) = (− 1)    = − 1.
(33)

Therefore

bn = 2A-
nπ[1 − (− 1)] (34)
= 4A
---
nπ. (35)

Thus

     (
     {  4A-,  n odd,
bn =    nπ
     ( 0,     n even.
(36)

The first few coefficients are therefore

b1 = 4A
---
 π, (37)
b2 = 0, (38)
b3 = 4A
---
3π, (39)
b4 = 0, (40)
b5 = 4A
5π-, (41)
b6 = 0. (42)

PIC

Figure 4. The square-wave sine spectrum contains only odd harmonics. Their magnitudes decrease as 1∕n, so the third harmonic has one third the first-harmonic amplitude, the fifth has one fifth, and so on.

6 Assemble the first complete Fourier series

Substitute the surviving coefficients into the sine-only series:

           [                                             ]
        4A-         1-         1-          1-
f(x) ∼  π   sinx +  3 sin(3x) + 5 sin (5x ) + 7 sin(7x) + ⋅⋅⋅ .
(43)

A compact index uses

n = 2k + 1,     k = 0,1, 2,...
(44)

so that

        4A ∑∞  sin[(2k + 1 )x ]
f(x ) ∼ ---    --------------.
        π  k=0     2k + 1
(45)

This is the first complete nonsinusoidal Fourier series in the FS sequence.

Notice what the series says physically. The square wave is built from ordinary sinusoidal modes:

  • the fundamental sine wave sin x,
  • the third harmonic sin 3x,
  • the fifth harmonic sin 5x,
  • the seventh harmonic sin 7x,
  • and all higher odd harmonics.

No even harmonic is required for this particular waveform.

7 Why the coefficient amplitudes decrease inversely with harmonic number

For odd n,

|b | = 4A-.
 n    nπ
(46)

So

       1-
|bn| ∝ n.
(47)

The ratio of the nth odd-harmonic amplitude to the fundamental is

|bn|   1
----=  --.
|b1|   n
(48)

For example,

|b3|-= 1-,    |b5|=  1.
|b1|   3      |b1|   5
(49)

The slow 1∕n decay is closely connected with the jump discontinuities of the square wave. Later articles will make the relation between smoothness and spectral decay more systematic.

8 Half-wave antisymmetry gives a second explanation

The square wave has more structure than ordinary odd symmetry. Shift the waveform by half a period:

f (x + π) = − f(x).
(50)

This property is called half-wave antisymmetry.

It explains why even harmonics vanish even before using the explicit square-wave integral.

Consider a generic Fourier integral over one full 2π period and split it into two half-periods. For a sine coefficient, use the interval [0, 2π]:

In = ∫ 02πf(x) sin(nx) dx (51)
= ∫ 0πf(x) sin(nx) dx + ∫ π2πf(x) sin(nx) dx. (52)

In the second integral let

u =  x − π.
(53)

Then

x =  u + π,
(54)

and

f (u + π) = − f(u).
(55)

Also,

sin[n(u + π)] = sin(nu + nπ) (56)
= (−1)n sin(nu). (57)

Therefore the second half contributes

        ∫ π
− (− 1)n    f(u) sin(nu )du.
         0
(58)

The two halves combine to give

                ∫
              n    π
In = [1 − (− 1) ]    f(x) sin(nx )dx.
                  0
(59)

For even n, the factor is zero.

So half-wave antisymmetry itself suppresses even harmonics. Odd symmetry separately tells us that this particular phase choice has sine terms rather than cosine terms.

9 Square waves do not always have only sine terms

The result in Equation (45) belongs to the oddly phased square wave of Equation (1).

Shift the waveform by π∕2:

         (      )
g (x ) = f  x + π- .
               2
(60)

This shifted square wave is even rather than odd. Substitute the shift into the sine series:

g(x) ∼4A-
 π∑ k=0∞---1---
2k +  1 sin [        (     π) ]
 (2k + 1)  x + 2. (61)

For odd integers,

    [                      ]
                 (2k-+-1)π-        k
sin  (2k + 1)x +     2      =  (− 1) cos[(2k + 1)x ].
(62)

Thus

       4A  [       1          1            ]
g(x) ∼ ---  cosx − --cos 3x + --cos5x − ⋅⋅⋅  .
        π          3          5
(63)

Therefore the statement

“a square wave  contains only sine terms ”
(64)

is not generally correct.

The correct statement is that the sine/cosine split depends on the choice of time or spatial origin. The harmonic frequencies remain the same, but a phase shift redistributes information between sine and cosine components.

10 Finite partial sums

An infinite Fourier series cannot be drawn directly. We approximate it by keeping finitely many terms.

Because only odd harmonics survive, it is convenient to define the partial sum containing the first M nonzero harmonics:

          4A M∑ −1sin[(2k + 1)x]
QM (x) =  ---    --------------.
          π  k=0     2k + 1
(65)

The first partial sum is

Q  (x ) = 4A-sinx.
  1       π
(66)

The first three nonzero harmonics give

             [                         ]
         4A          1         1
Q3 (x) = -π-  sin x + 3-sin 3x + 5-sin5x  .
(67)

The first ten nonzero harmonics give

             ∑9
Q   (x ) = 4A-    sin[(2k-+-1-)x-].
  10      π          2k + 1
             k=0
(68)

PIC

Figure 5. Partial sums built from one, three, and ten nonzero odd harmonics. As more harmonics are added, the waveform develops flatter plateaus and steeper transitions near the discontinuities.

Every finite QM(x) is continuous because it is a finite sum of continuous sine functions. Yet the target square wave has jumps. Therefore no finite number of harmonics can reproduce the discontinuity exactly.

The jump emerges only through the limiting behavior of increasingly many harmonics.

11 What happens exactly at the jump?

At x = 0, every sine term vanishes:

sin[(2k + 1)0] = 0.
(69)

Therefore every finite partial sum satisfies

QM  (0 ) = 0.
(70)

The left and right limits of the square wave are

f (0− ) = − A,
(71)

and

f (0+ ) = A.
(72)

Their midpoint is

f(0− )-+-f(0+-)  −-A-+-A-
      2       =     2     = 0.
(73)

So the partial sums already point toward the jump-midpoint rule that will be proved and formalized later in the convergence sequence.

The same thing happens at x = ±π because

sin[(2k + 1)π] = 0.
(74)

12 Preview of the Gibbs phenomenon

Increasing the number of terms makes the transition region narrower, but the oscillatory overshoot near a jump does not simply disappear.

PIC

Figure 6. A magnified view near the jump. Adding more odd harmonics squeezes the oscillation closer to the discontinuity, but a persistent overshoot remains. FS16 will analyze this Gibbs phenomenon in detail.

For the jump from −A to +A, the jump height is

Δf  = 2A.
(75)

In the large-partial-sum limit, the first overshoot approaches approximately 8.95% of the jump height above the upper plateau. Thus the peak approaches roughly

A + 0.0895(2A ) ≈ 1.179A.
(76)

We record this only as a preview. The derivation belongs to FS16.

13 A numerical coefficient table for unit amplitude

Set

A  = 1.
(77)

Then for odd n,

bn = -4-.
     n π
(78)

The first few nonzero values are

b1 = 4-
π ≈ 1.27324, (79)
b3 = -4-
3π ≈ 0.42441, (80)
b5 =  4
---
5π ≈ 0.25465, (81)
b7 = -4-
7π ≈ 0.18189, (82)
b9 = -4-
9π ≈ 0.14147. (83)

Notice that the fundamental coefficient is larger than the plateau magnitude A = 1. That does not mean the square wave itself reaches 1.27324 everywhere. The full waveform results from interference among all harmonics.

This is an important distinction:

coefficient amplitude  ⁄= instantaneous waveform  amplitude.
(84)

14 A useful special point on the positive plateau

At

x =  π,
     2
(85)

the square wave is on its positive plateau, so away from any discontinuity the Fourier series approaches A.

For the odd harmonics,

sin (  )
 π-
  2 = 1, (86)
sin ( 3π )
  ---
  2 = −1, (87)
sin (    )
  5π-
  2 = 1, (88)

and so on.

Thus the square-wave series leads to

         (                    )
     4A-      1-   1-  1-
A  =  π   1 − 3 +  5 − 7 + ⋅⋅⋅  .
(89)

Cancel A:

     4 (    1    1   1      )
1 =  -- 1 − --+  --− --+ ⋅⋅⋅  .
     π      3    5   7
(90)

Therefore

π        1   1   1
--=  1 − --+ --− --+ ⋅⋅ ⋅ .
4        3   5   7
(91)

This is the Leibniz series for π∕4. In this Fourier context it appears naturally by evaluating the square-wave expansion at a convenient point.

The rigorous justification for substituting into the infinite series will be supplied by the later convergence results.

15 Generalize the square wave to an arbitrary symmetric interval

Now define

       {
         − A,  − L < x <  0,
f(x) =
         A,    0 < x <  L,
(92)

with periodic extension of period 2L.

FS06 showed that the basis functions are

    (     )
cos  n-πx
       L
(93)

and

   (     )
sin   nπx-  .
      L
(94)

The waveform is still odd, so

a0 = 0,     an = 0.
(95)

The sine coefficient is

       ∫ L         (     )
b =  1-    f(x )sin   nπx-  dx.
 n   L  − L           L
(96)

Because the integrand is even,

         ∫
      2A-  L    ( nπx-)
bn =  L      sin   L    dx.
          0
(97)

Integrate:

∫     (n πx)         L     ( nπx )
  sin  ----  dx =  − ---cos  ----  .
        L            nπ       L
(98)

Therefore

bn = 2A
---
 L[   L     ( nπx )]
 −  ---cos  ----
    nπ       L0L (99)
= 2A-
nπ         n
[1 − (− 1 ) ] . (100)

The factor L cancels.

Thus

     (
     {  4A-,  n odd,
bn =    nπ
     ( 0,     n even.
(101)

The coefficient magnitudes are independent of L because stretching the waveform changes the harmonic wavelengths but not the vertical amplitude ratios.

The general-interval series is

            ∞            (            )
        4A-∑   ---1---     (2k-+-1)πx-
f (x) ∼  π     2k +  1 sin      L       .
            k=0
(102)

PIC

Figure 7. Scaling the period from 2π to 2L changes the harmonic arguments but not the dimensionless coefficient ratios. The odd square wave still contains only odd harmonics with amplitudes proportional to 1∕(2k + 1).

16 Time-domain form

For a signal of period T, use

      2π
ω0 =  --.
      T
(103)

Define the odd square wave over one centered period by

       {
         − A,  − T∕2 <  t < 0,
f(t) =   A,    0 < t < T∕2.
(104)

Then

           [                                         ]
        4A-            1-           1-
f (t) ∼ π   sin(ω0t) + 3 sin(3ω0t) + 5 sin(5ω0t) + ⋅⋅ ⋅ .
(105)

The frequencies present are

f0,  3f0,   5f0,  7f0,  ...
(106)

where

     1
f0 = --.
     T
(107)

16.1 Numerical example

Suppose a square-wave voltage has

A  = 5 V
(108)

and

f0 = 1 kHz.
(109)

Then

ω0 = 2π (1000) = 2000π rad ∕s.
(110)

The first three nonzero harmonic amplitudes are

b1 = 20
---
 π V ≈ 6.366 V, (111)
b3 = 20-
3π V ≈ 2.122 V, (112)
b5 = 20-
5π V ≈ 1.273 V. (113)

So a three-harmonic approximation is

f(t) ≈ 20
---
π sin(2000πt) + 20
---
3π sin(6000πt) (114)
+ 20-
5π sin(10000πt). (115)

Again, individual coefficient amplitudes can exceed A. Their superposition produces the square-like waveform.

17 Dimensional check

A Fourier coefficient multiplying sin(nω0t) must have the same units as f because the sine is dimensionless.

From

       ∫  T∕2
b  = 2-      f(t)sin(nω  t) dt,
 n   T   −T∕2           0
(116)

the units are

        1
[bn] = time-[f]time =  [f ].
(117)

For the square wave,

      4A
bn =  ---
      nπ
(118)

also has units of amplitude because n and π are dimensionless.

18 Sanity checks on the result

A good Fourier derivation should survive several independent checks.

18.1 Check 1: mean value

The waveform spends equal time at +A and −A, so its mean must vanish. We found

a0 = 0.
(119)

Pass.

18.2 Check 2: parity

An odd waveform should have no cosine terms. We found

a  = 0.
 n
(120)

Pass.

18.3 Check 3: half-wave antisymmetry

A waveform satisfying

f(x + π) = − f(x )
(121)

should contain no even harmonics. We found

b2k = 0.
(122)

Pass.

18.4 Check 4: units

Every nonzero coefficient is a dimensionless number times A. Therefore it has the correct units.

Pass.

18.5 Check 5: period scaling

Replacing [−π,π] by [−L,L] changes the basis argument to

nπx-
 L
(123)

while leaving the amplitude ratios unchanged.

Pass.

19 Common mistakes

19.1 Mistake 1: computing every coefficient before checking parity

For the odd square wave, a0 and all an are known to vanish before integration.

19.2 Mistake 2: forgetting the inverse harmonic factor from integration

Since

∫
                 cos(nx-)
  sin(nx )dx = −    n    ,
(124)

the coefficient must contain 1∕n.

19.3 Mistake 3: keeping even harmonics

The factor

1 − (− 1)n
(125)

is zero for even n.

19.4 Mistake 4: saying every square wave has only sine terms

A phase-shifted square wave can have cosine terms. Sine versus cosine depends on the origin; the harmonic frequencies are the more invariant feature.

19.5 Mistake 5: expecting a finite sum to contain an exact jump

Every finite trigonometric sum is continuous. A discontinuity appears only through the limit of increasingly many harmonics.

19.6 Mistake 6: assuming the oscillations near a jump simply vanish

The Gibbs region narrows as more terms are added, but the limiting overshoot remains a fixed fraction of the jump height.

20 Self-check questions

  1. Why does a0 vanish for the odd square wave?
  2. Why does every an vanish?
  3. Why is f(x) sin(nx) even?
  4. Starting from the coefficient integral, where does the factor 1∕n enter?
  5. Why does 1 − (−1)n eliminate even harmonics?
  6. What is the third-harmonic amplitude relative to the fundamental?
  7. Why can b1 be larger than A without contradiction?
  8. Why does every finite partial sum satisfy QM(0) = 0?
  9. What property besides ordinary odd symmetry helps explain the absence of even harmonics?
  10. How does the series change when the square wave is stretched from period 2π to period 2L?
  11. What changes under a phase shift of the square wave, and what does not?
  12. Why is the overshoot near a jump deferred to a later convergence article?

21 Practice problems

  1. For A = 2, compute b1, b3, b5, and b7.
  2. Write the first four nonzero terms of the Fourier series for the odd square wave with A = 3.
  3. Show directly from the two piecewise integrals that a0 = 0 without using odd symmetry.
  4. Show directly that an = 0 by splitting the cosine integral at x = 0.
  5. Evaluate Q1(π∕2), Q2(π∕2), and Q3(π∕2), where QM contains the first M nonzero odd harmonics.
  6. For a square wave on [−4, 4] with amplitude A = 1, write its first three nonzero Fourier terms.
  7. A square-wave voltage alternates between −12 V and +12 V at 400 Hz. Find the frequencies and amplitudes of the first three nonzero harmonics.
  8. Verify that shifting the odd square wave by π∕2 produces alternating odd cosine coefficients.
  9. Use half-wave antisymmetry to prove that even cosine coefficients also vanish for any waveform satisfying f(x + π) = −f(x), whether or not the waveform is odd.
  10. Explain why the value assigned to the square wave at x = 0 cannot change any Fourier coefficient.

22 Summary

For the odd square wave

       {
f(x) =   − A,  − π < x <  0,
         A,    0 < x <  π,
(126)

periodically extended with period 2π, odd symmetry gives

a0 = 0,     an = 0.
(127)

The sine coefficients are

      2A
bn =  ---[1 − (− 1)n],
      nπ
(128)

or

     (
     {  4A-
b  =    nπ ,  n odd,
 n   (
       0,     n even.
(129)

Therefore

           [                               ]
f(x ) ∼ 4A- sinx +  1sin 3x + 1-sin 5x + ⋅⋅⋅  .
        π           3         5
(130)

On the general interval [−L,L],

            ∞            (            )
        4A-∑   ---1---     (2k-+-1)πx-
f (x) ∼  π     2k +  1 sin      L       .
            k=0
(131)

The square wave therefore establishes the first full connection between a nonsinusoidal periodic function and its harmonic spectrum.

PIC

Figure 8. FS07 establishes the complete square-wave calculation. FS08 next compares the sawtooth and triangle waves, where changes in waveform smoothness lead to different harmonic structures and decay rates.

References

[1]   R. V. Churchill and J. W. Brown, Fourier Series and Boundary Value Problems, McGraw-Hill.

[2]   E. Kreyszig, Advanced Engineering Mathematics, Wiley.

[3]   R. Haberman, Applied Partial Differential Equations with Fourier Series and Boundary Value Problems, Pearson.

[4]   G. P. Tolstov, Fourier Series, Dover Publications.


"First Complete Fourier Series - Square Wave" is owned by bloftin.
(view preamble)
View style:
Other names:  FS07
Also defines:  square wave, odd square wave, square-wave Fourier series, odd-harmonic spectrum, Fourier partial sum, half-wave antisymmetry
Keywords:  Fourier series, square wave, odd harmonics, sine coefficients, partial sums, harmonic spectrum, half-wave symmetry, discontinuity, Gibbs phenomenon

Cross-references: periodic function, units, superposition, oscillation, phase shift, frequencies, phase, relation, magnitudes, spectrum, harmonic numbers, formula, Fourier series, function, period, partial sums, amplitudes, harmonics, periodic, Fourier coefficients, FS06, FS05, FS04
There are 4 references to this object.

This is version 1 of First Complete Fourier Series - Square Wave, born on 2026-11-05.
Object id is 1569, canonical name is FirstCompleteFourierSeriesSquareWave.
Accessed 6 times total.

Classification:
Physics Classification: 02.30.Nw (Fourier analysis)
 02.30.Lt (Sequences, series, and summability)

Pending Errata and Addenda

None.

Discussion

No messages.

Interact