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

Derivation of the Fourier Cosine Coefficients

(Topic)

Derivation of the Fourier Cosine Coefficients

The previous articles built the machinery required for Fourier coefficient extraction. FS02 introduced the function inner product and projection coefficient. FS03 proved that the functions

1,   cosx,   cos2x,   cos3x,...
(1)

are mutually orthogonal on [−π,π], and that every sine harmonic is orthogonal to every cosine harmonic there.

This article now uses those facts to derive the cosine coefficients of a Fourier series from first principles. The central idea is simple:

multiply by the harmonic you want, (2)
integrate over a full period, (3)
and let orthogonality remove the others. (4)

The algebra deserves to be seen slowly, because the same mechanism appears throughout Fourier analysis, eigenfunction expansions, normal modes, and quantum mechanics.

PIC

Figure 1. Fourier coefficient extraction is function-space projection. The coefficient of a cosine harmonic is found by measuring the component of f along that harmonic.

1 What we are trying to determine

For now, work on the interval

− π ≤  x ≤ π.
(5)

A real trigonometric expansion has the form

               ∑N
S  (x) =  a0+     [a  cos(nx ) + b sin(nx)].
  N       2         n            n
               n=1
(6)

The quantities

a0,a1,a2,...
(7)

measure the constant and cosine content, while

b1,b2,b3,...
(8)

measure the sine content.

In FS04 our main goal is to derive

        ∫
      1   π
am =  π-    f(x)cos(mx  )dx,     m ≥  1,
         −π
(9)

and to understand why this formula is a projection formula rather than a rule to memorize.

We will also derive the constant coefficient

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

The full derivation of the sine coefficients is reserved for FS05.

2 First work with a finite trigonometric polynomial

There is a subtle mathematical point worth handling cleanly.

If we begin immediately with an infinite Fourier series and integrate term by term, we have already assumed that interchanging the sum and the integral is legitimate. The conditions under which this is allowed belong to the later convergence articles.

So begin with the finite expression in Equation (6). For a finite sum there is no difficulty: integration distributes across the sum exactly.

Assume therefore that

        a0   ∑N
f (x ) = ---+     [an cos(nx) + bnsin(nx )].
        2    n=1
(11)

We ask:

How  can we isolate one particular coe fficient am?
(12)

3 Choose the cosine harmonic we want

Suppose we want the coefficient am multiplying

cos(mx ).
(13)

Multiply both sides of Equation (11) by cos(mx):

f(x) cos(mx) = a0-
2 cos(mx) (14)
+ ∑ n=1Na n cos(nx) cos(mx) (15)
+ ∑ n=1Nb n sin(nx) cos(mx). (16)

Nothing has been integrated yet. We have only multiplied the entire expansion by the basis function whose coefficient we want.

PIC

Figure 2. The extraction procedure has two deliberate operations: multiply the entire expansion by the target harmonic and then integrate across one complete symmetric period.

4 Integrate across the full interval

Integrate Equation (16) from −π to π:

∫ −ππf(x) cos(mx) dx = a0
---
 2 ∫ −ππ cos(mx) dx (17)
+ ∫ −ππ ∑ n=1Na n cos(nx) cos(mx) dx (18)
+ ∫ −ππ ∑ n=1Nb n sin(nx) cos(mx) dx. (19)

Because the sums are finite, move the integrals through the sums:

∫ −ππf(x) cos(mx) dx = a0-
 2 ∫ −ππ cos(mx) dx (20)
+ ∑ n=1Na n ∫ −ππ cos(nx) cos(mx) dx (21)
+ ∑ n=1Nb n ∫ −ππ sin(nx) cos(mx) dx. (22)

Equation (22) is the crucial line. FS03 tells us the value of every integral on the right-hand side.

5 The constant term disappears

For any positive integer m,

∫ π
    cos(mx )dx =  0.
 −π
(23)

Therefore

  ∫  π
a0-   cos(mx ) dx = 0.
2   −π
(24)

The constant component cannot contaminate the measurement of a nonzero cosine harmonic because the constant basis function and cos(mx) are orthogonal.

6 Every sine term disappears

FS03 proved

∫  π

  −π sin(nx )cos(mx )dx = 0
(25)

for all positive integers m and n.

Consequently,

∑N    ∫ π
    bn    sin(nx) cos(mx  )dx = 0.
n=1    − π
(26)

So none of the sine coefficients affects the extraction of am.

7 All the wrong cosine harmonics disappear

The cosine-cosine orthogonality relation is

∫  π                      {
                            0,  n ⁄= m,
  −π cos(nx )cos(mx )dx =   π,  n = m.
(27)

The sum

∑N     ∫ π
    an     cos(nx )cos(mx ) dx
n=1     −π
(28)

therefore contains many zero terms.

Write a small portion explicitly:

a1 ∫ −ππ cos x cos(mx) dx (29)
+ a2 ∫ −ππ cos 2x cos(mx) dx (30)
+ ⋅⋅⋅ (31)
+ am ∫ −ππ cos 2(mx) dx (32)
+ ⋅⋅⋅ (33)
+ aN ∫ −ππ cos Nx cos(mx) dx. (34)

Every term with n≠m is zero.

Only the n = m term survives:

   ∫
     π    2
am     cos (mx )dx.
    − π
(35)

But FS03 also established

∫  π
    cos2(mx ) dx = π.
  −π
(36)

Hence the entire cosine sum reduces to

πam.
(37)

PIC

Figure 3. Orthogonality acts like a harmonic filter. The constant term, all sine harmonics, and all cosine harmonics except the selected mth cosine give zero inner product with cos(mx).

8 The surviving equation

Substitute Equations (24), (26), and (37) into Equation (22).

We obtain

∫ π
    f(x) cos(mx )dx =  πa  .
 − π                     m
(38)

Now divide both sides by π:

       ∫
      1   π
am =  --   f (x)cos(mx ) dx.
      π  −π
(39)

This is the Fourier cosine-coefficient formula on [−π,π].

The result was not guessed. It followed from three facts:

  • the cosine harmonics are mutually orthogonal,
  • sine harmonics are orthogonal to cosine harmonics,
  • the squared norm of cos(mx) on [−π,π] is π.

9 The same result as a projection formula

FS02 derived the coefficient for projection of a function f onto a nonzero basis function ϕ:

     ⟨f,ϕ⟩
c =  -----.
     ⟨ϕ, ϕ⟩
(40)

Choose

ϕm (x) = cos(mx ).
(41)

Then

         ∫  π
⟨f, ϕm ⟩ =    f (x)cos(mx ) dx,
           −π
(42)

and

           ∫ π
⟨ϕm, ϕm ⟩ =     cos2(mx )dx =  π.
            − π
(43)

Therefore

cm = ∫
  π f(x) cos(mx )dx
-−-π----------------
         π (44)
= am. (45)

Thus the Fourier cosine coefficient is exactly the ordinary function-space projection coefficient onto cos(mx).

This is the deeper meaning of Equation (39).

10 Why the denominator is π

It is tempting to memorize the factor 1∕π. It is better to understand where it comes from.

The denominator is simply the squared norm of the basis function:

               ∫ π
∥ cos(mx  )∥2 =      cos2(mx  )dx = π.
                −π
(46)

If we instead used the normalized basis function

^        cos(mx-)
ϕm (x ) =   √ π-  ,
(47)

then

⟨^ϕm, ^ϕm ⟩ = 1.
(48)

The corresponding normalized-basis coefficient would simply be

^cm =  ⟨f, ^ϕm ⟩.
(49)

Because

         ∫
     --1-   π
^cm = √ π-    f (x)cos(mx )dx,
           −π
(50)

and

      ^c
am =  √m-,
       π
(51)

the two descriptions contain the same information.

11 Deriving the constant coefficient a0

The constant term must be handled separately because its basis function is

1
(52)

rather than cos(mx) with m ≥ 1.

Start again from

        a    ∑N
f (x ) = -0-+     [an cos(nx) + bnsin(nx )].
        2    n=1
(53)

This time multiply by 1. That changes nothing:

             ∑N
f (x ) = a0-+     [an cos(nx) + bnsin(nx )].
        2    n=1
(54)

Integrate from −π to π:

∫ −ππf(x) dx = a0-
2 ∫ −ππ1 dx (55)
+ ∑ n=1Na n ∫ −ππ cos(nx) dx (56)
+ ∑ n=1Nb n ∫ −ππ sin(nx) dx. (57)

All sine and cosine integrals vanish over the complete symmetric period.

Also,

∫ π
    1dx =  2π.
 −π
(58)

Therefore

∫ −ππf(x) dx = a0-
2(2π) (59)
= πa0. (60)

Hence

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

PIC

Figure 4. The constant component is the projection of f onto the constant basis function. The Fourier convention writes this projection as a0∕2.

12 Why the series contains a0∕2 instead of a0

This convention often looks arbitrary until it is compared with the nonzero harmonics.

The projection coefficient onto the constant basis function 1 is

     ⟨f,1⟩
c0 = ------.
     ⟨1,1⟩
(62)

Now

        ∫ π
⟨1, 1⟩ =     1dx =  2π.
         −π
(63)

Thus

        ∫ π
c =  1--    f(x) dx.
 0   2π  −π
(64)

But Equation (61) gives

       ∫
      1   π
a0 = --    f (x)dx.
     π   −π
(65)

Therefore

     a0
c0 = --.
     2
(66)

So the actual constant component in the Fourier series is

a0    1 ∫ π
--=  ---    f(x )dx.
2    2π  − π
(67)

The right-hand side is precisely the average value of f over an interval of length 2π.

Therefore the term

a
-0-
2
(68)

is the DC component, or mean value, of the periodic function.

13 Formal definitions

13.1 Fourier cosine coefficient

For positive integer n, the Fourier cosine coefficient of f on [−π,π] is

      1 ∫ π
an =  --    f(x)cos(nx )dx.
      π  −π
(69)

It is the projection coefficient of f onto the non-normalized basis function cos(nx).

13.2 Constant Fourier coefficient

The constant Fourier coefficient is

      1∫  π
a0 = --    f (x)dx.
     π   −π
(70)

The constant term appearing in the Fourier series is a0∕2.

13.3 DC component

The DC component is the mean value of the function over one complete period. On [−π,π],

        1 ∫ π           a0
fDC =  ---    f(x) dx = ---.
       2π  −π            2
(71)

13.4 Harmonic coefficient extraction

Harmonic coefficient extraction is the procedure of multiplying a function by a selected basis harmonic, integrating over a complete orthogonality interval, and dividing by the squared norm of that basis harmonic.

13.5 Cosine projection coefficient

The cosine projection coefficient onto cos(nx) is

---⟨f,cos(nx)⟩---.
⟨cos(nx ),cos(nx)⟩
(72)

On [−π,π], this quantity equals an.

14 Example 1: extracting a coefficient from a known finite sum

Let

f(x) = 5 + 2cos x − 4sin 2x + 7cos 3x.
(73)

Find a3 using the integral formula, even though the answer can already be read from the expression.

Start with

     1 ∫  π
a3 = --    f (x )cos3x dx.
     π   −π
(74)

Substitute f:

a3 = 1
--
π∫ −ππ[5 + 2 cosx − 4sin 2x + 7cos 3x] cos 3xdx. (75)

Distribute:

a3 = 1
--
π[5 ∫ −ππ cos 3xdx (76)
+ 2 ∫ −ππ cos x cos 3xdx (77)
− 4 ∫ −ππ sin 2x cos 3xdx (78)
+ 7 ∫ −ππ cos 23xdx]. (79)

The first three integrals are zero by orthogonality. The final integral is π.

Thus

a3 = -1
π[7π] (80)
= 7. (81)

The integral has isolated the third cosine harmonic exactly.

15 Example 2: x2 on [−π,π]

Consider

        2
f(x) = x .
(82)

We first calculate a0:

a0 = 1-
π∫ −ππx2 dx. (83)

Because x2 is even,

a0 = 2-
π∫ 0πx2 dx (84)
= 2
--
π[   ]
 x3
 ---
  30π (85)
= 2-
ππ3-
3 (86)
= 2π2
----
 3. (87)

Therefore the constant term is

a0    π2
---=  --.
 2     3
(88)

Now find an for n ≥ 1:

an = 1-
π∫ −ππx2 cos(nx) dx (89)
= 2
--
π∫ 0πx2 cos(nx) dx. (90)

The remaining integral requires integration by parts twice.

Let

     2
u = x ,     dv = cos(nx) dx.
(91)

Then

                     sin (nx)
du =  2x dx,     v = -------.
                        n
(92)

Hence

∫ 0πx2 cos(nx) dx = [x2 sin (nx)]
 ----------
     n0π −2
--
n∫ 0πx sin(nx) dx. (93)

Because

sin(n π) = 0,     sin 0 = 0,
(94)

the boundary term vanishes:

∫                      ∫
  π  2               -2   π
    x cos(nx )dx = − n     x sin (nx )dx.
 0                       0
(95)

Integrate again. Let

u = x,     dv =  sin(nx )dx.
(96)

Then

                   cos(nx-)
du = dx,     v = −    n    .
(97)

Therefore

∫ 0πx sin(nx) dx = [  x cos(nx )]
 − ---------
       n0π + 1
--
n∫ 0π cos(nx) dx. (98)

The last integral is zero, so

∫ 0πx sin(nx) dx = −πcos(n-π)-
    n (99)
= −      n
π(−-1)--
  n. (100)

Insert this into Equation (95):

∫ 0πx2 cos(nx) dx = −2
--
n[   π(− 1)n]
  − --------
      n (101)
= 2π(−-1)n-
   n2. (102)

Finally use Equation (90):

an = 2
--
π2π (− 1 )n
---------
   n2 (103)
= 4(−-1)n-
  n2. (104)

Thus the cosine coefficients are

           n
      4(− 1)-
an =    n2   .
(105)

PIC

Figure 5. The cosine coefficients of x2 alternate in sign and decay like 1∕n2. The coefficient pattern already hints at the later connection between smoothness and spectral decay.

16 Example 3: an even rectangular pulse

Define a 2π-periodic function by specifying one period:

       {
f(x) =   1,  |x| < π∕2,
         0,  π∕2 <  |x | ≤ π.
(106)

The value at the two jump points will not affect the coefficient integrals.

First find a0:

a0 = 1-
π∫ −ππf(x) dx (107)
= 1
--
π∫ −π∕2π∕21 dx (108)
= 1-
π(π ) (109)
= 1. (110)

So the mean value is

a0-=  1.
2     2
(111)

Now calculate an:

an = 1-
π∫ −ππf(x) cos(nx) dx (112)
= 1
--
π∫ −π∕2π∕2 cos(nx) dx. (113)

Integrate:

an = 1-
π[       ]
 sin(nx)-
    n−π∕2π∕2 (114)
= 1
---
πn[   ( nπ )      (  n π) ]
 sin  ---  − sin  − ---
       2            2. (115)

Because sine is odd,

sin (− 𝜃) = − sin 𝜃,
(116)

so

            (    )
a  =  2--sin  nπ- .
 n    πn       2
(117)

This immediately gives

a1 = 2-
π, (118)
a2 = 0, (119)
a3 = −-2-
3 π, (120)
a4 = 0, (121)
a5 = 2--
5π. (122)

Only odd cosine harmonics survive for this particular pulse.

PIC

Figure 6. A centered rectangular pulse has a nonzero mean and an alternating sequence of odd cosine coefficients, while the even cosine harmonics vanish.

17 Example 4: an odd function has zero cosine coefficients

Consider

f (x) = x
(123)

on [−π,π].

For n ≥ 1,

       ∫ π
a  = 1-    x cos(nx)dx.
 n   π  − π
(124)

Now x is odd and cos(nx) is even. Therefore the product

x cos(nx)
(125)

is odd.

Hence

∫  π
    x cos(nx) dx = 0,
  −π
(126)

so

an = 0.
(127)

Also,

       ∫ π
a0 = 1-    xdx  = 0.
     π  −π
(128)

Thus an odd function has no constant or cosine component on a symmetric interval.

A systematic treatment of even and odd symmetry appears later in FS09. Here the example simply demonstrates how symmetry can make a coefficient integral vanish before any antiderivative is computed.

18 From coefficients to a cosine spectrum

Once the numbers

a1,a2,a3,...
(129)

have been calculated, they can be plotted against harmonic number n.

Such a plot is a discrete cosine spectrum.

It answers the question:

How  much  of each cosine harmonic is present in the function?
(130)

Large |an| means a strong cosine projection at harmonic n. Small |an| means a weak projection. A zero coefficient means the function is orthogonal to that cosine harmonic over the chosen interval.

PIC

Figure 7. Fourier cosine coefficients may be viewed as coordinates of the function along the orthogonal cosine directions. Plotting coefficient amplitude against harmonic number produces a discrete spectrum.

19 The general projection pattern

The derivation can now be summarized without referring specifically to cosine.

Suppose

ϕ ,ϕ  ,...
 1   2
(131)

are mutually orthogonal basis functions and

f = ∑   c ϕ  .
         n n
      n
(132)

Take the inner product with ϕm:

          ⟨             ⟩
            ∑
⟨f,ϕm ⟩ =       cnϕn,ϕm   .
             n
(133)

Use linearity:

          ∑
⟨f, ϕm⟩ =     cn⟨ϕn,ϕm ⟩.
            n
(134)

Orthogonality eliminates all terms except n = m:

⟨f,ϕm ⟩ = cm⟨ϕm, ϕm ⟩.
(135)

Therefore

      -⟨f,ϕm-⟩-
cm =  ⟨ϕm, ϕm⟩ .
(136)

The Fourier cosine coefficient formula is simply this statement with

ϕ  (x) = cos(mx ).
 m
(137)

20 A short preview of a general interval

FS06 will derive the full rescaling carefully. For orientation, on [−L,L] the cosine basis becomes

   (     )
cos  nπx-  .
      L
(138)

Its squared norm is

∫
  L    2( nπx-)
    cos    L    dx = L.
 −L
(139)

Therefore the corresponding projection coefficient is

        ∫ L         (     )
an =  1-    f(x )cos  nπx-  dx.
      L  − L           L
(140)

The factor 1∕L plays exactly the same role that 1∕π plays on [−π,π].

21 What has and has not been proved

The calculations above rigorously extract coefficients from a finite trigonometric polynomial.

For a more general function f, the same integrals define its Fourier coefficients. However, several deeper questions remain:

  • Does the resulting infinite Fourier series converge?
  • If it converges, does it converge to f?
  • What happens at a discontinuity?
  • In what sense can a non-smooth function be represented by the series?
  • When is term-by-term integration or differentiation justified?

Those questions are postponed deliberately to the convergence part of the FS sequence.

At this stage, the important result is that orthogonal projection gives a unique and natural number measuring the cosine content of f.

22 Common mistakes

  1. Forgetting the factor 1∕π in an on [−π,π].
  2. Assuming the 1∕π factor is arbitrary rather than recognizing it as the reciprocal squared norm of cos(nx).
  3. Forgetting that the constant basis function has squared norm 2π, not π.
  4. Writing the Fourier series with a0 as the constant term instead of a0∕2 under the standard convention used here.
  5. Confusing the coefficient a0 with the mean value. The mean value is a0∕2.
  6. Multiplying by cos(mx) but failing to integrate over the full orthogonality interval.
  7. Assuming every product integral vanishes. The selected equal-frequency cosine product has integral π rather than zero.
  8. Using sine-cosine orthogonality on an interval where the required symmetry or full-period condition is absent.
  9. Reading a coefficient from a graph without remembering that its sign matters.
  10. Treating coefficient extraction as an unrelated Fourier trick instead of recognizing the projection formula from FS02.

23 Self-check questions

  1. Why do we multiply by cos(mx) when trying to determine am?
  2. Why does the constant term disappear from the am derivation for m ≥ 1?
  3. Why do all sine terms disappear?
  4. What is special about the n = m cosine term?
  5. Where does the denominator π come from?
  6. What is the difference between a0 and the DC component?
  7. Why is it mathematically cleaner to perform the first derivation with a finite trigonometric sum?
  8. Explain the coefficient formula using the language of function projection.
  9. If f is odd on [−π,π], what can you say about all its cosine coefficients?
  10. What changes in the coefficient denominator when the interval becomes [−L,L]?

24 Summary

For m ≥ 1, multiplying a trigonometric expansion by cos(mx) and integrating over [−π,π] gives

∫ π
    f(x) cos(mx )dx =  πam.
 − π
(141)

Therefore

       ∫
      1   π
am =  --   f (x)cos(mx ) dx.
      π  −π
(142)

The constant coefficient is

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

while the actual constant or DC term in the series is

        ∫ π
a0=  -1-    f(x )dx.
2    2π  − π
(144)

Most importantly,

      ---⟨f,cos(mx-)⟩----
am =  ⟨cos(mx ),cos(mx )⟩.
(145)

The Fourier cosine coefficient is therefore a projection coordinate in function space.

PIC

Figure 8. FS04 isolates cosine components. FS05 repeats the same projection logic for sine harmonics and consolidates the complete real Fourier coefficient set.

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]   G. B. Arfken, H. J. Weber, and F. E. Harris, Mathematical Methods for Physicists, Academic Press.

[4]   M. L. Boas, Mathematical Methods in the Physical Sciences, Wiley.


"Derivation of the Fourier Cosine Coefficients" is owned by bloftin.
(view preamble)
View style:
Other names:  FS04
Also defines:  Fourier cosine coefficient, constant Fourier coefficient, DC component, harmonic coefficient extraction, cosine projection coefficient
Keywords:  Fourier series, cosine coefficient, a_n, a_0, orthogonality, projection, harmonic extraction, DC component, trigonometric basis

Attachments:
Fourier Cosine-Coefficient Derivation and Projection Exercises (Example) by bloftin

Cross-references: complete real Fourier coefficient set, function projection, graph, amplitude, spectrum, harmonic number, boundary, periodic function, norm, inner product, relation, period, operations, FS05, formula, work, mechanics, normal modes, Fourier series, harmonic, functions, FS03, projection coefficient, function inner product, FS02, Fourier coefficient
There are 9 references to this object.

This is version 1 of Derivation of the Fourier Cosine Coefficients, born on 2026-10-26.
Object id is 1537, canonical name is DerivationOfTheFourierCosineCoefficients.
Accessed 13 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