Sine-Cosine Form and Symmetry
For real signals the complex Fourier series can be rewritten with real sines and cosines, the form in most engineering tables, or as amplitudes and phases, the form a spectrum analyzer shows. This lesson converts between the three forms and uses symmetry to predict which coefficients vanish before computing anything.
Three equivalent forms
For a real -periodic with :
with , , and . The factor 2 appears because and together make one real sinusoid.
import numpy as np
N = 1024
t = np.arange(N) / N
f = 1.5 + 2 * np.cos(2 * np.pi * t) - 3 * np.sin(2 * np.pi * 3 * t) + np.cos(2 * np.pi * 5 * t + 0.7)
c = np.fft.fft(f) / N
for k in (0, 1, 3, 5):
a, b = round(2 * c[k].real, 4) + 0.0, round(-2 * c[k].imag, 4) + 0.0
A, phi = 2 * abs(c[k]), round(float(np.angle(c[k])), 4) + 0.0
if k == 0:
print(f"k=0: c0 = {c[0].real:.4f}")
else:
print(f"k={k}: a={a:+.4f} b={b:+.4f} A={A:.4f} phase={phi:+.4f}")k=0: c0 = 1.5000
k=1: a=+2.0000 b=+0.0000 A=2.0000 phase=+0.0000
k=3: a=+0.0000 b=-3.0000 A=3.0000 phase=+1.5708
k=5: a=+0.7648 b=-0.6442 A=1.0000 phase=+0.7000
The program recovers each term: at , at (amplitude 3, phase ), and the cosine with phase 0.7 at .
Symmetry shortcuts
- Even (): all , a pure cosine series; the are real.
- Odd : all , a pure sine series; the are purely imaginary.
- Half-wave antisymmetric : only odd harmonics.
import numpy as np
N = 1024
t = np.arange(N) / N
tc = np.where(t < 0.5, t, t - 1) # t centered on [-1/2, 1/2)
shapes = {
"even (|t|)": np.abs(tc),
"odd (t)": tc,
"half-wave antisym.": np.sign(np.sin(2 * np.pi * t + 0.3)) * np.abs(np.sin(2 * np.pi * t)) ** 0.5,
}
for name, f in shapes.items():
c = np.fft.fft(f)[:7] / N
print(f"{name:20s} max|Re c_k| (k>0) = {np.max(np.abs(c.real[1:])):.3f} max|Im c_k| = {np.max(np.abs(c.imag)):.3f}"
f" |c_2|,|c_4| = {abs(c[2]):.1e}, {abs(c[4]):.1e}")even (|t|) max|Re c_k| (k>0) = 0.101 max|Im c_k| = 0.000 |c_2|,|c_4| = 0.0e+00, 0.0e+00
odd (t) max|Re c_k| (k>0) = 0.000 max|Im c_k| = 0.159 |c_2|,|c_4| = 8.0e-02, 4.0e-02
half-wave antisym. max|Re c_k| (k>0) = 0.067 max|Im c_k| = 0.544 |c_2|,|c_4| = 1.1e-11, 1.1e-11
The even function has (numerically) no imaginary parts, the odd one has no real parts beyond tiny sampling effects, and the half-wave antisymmetric one has no even harmonics.
In software
- Audio spectrum displays show in decibels; phase is usually hidden because the ear is mostly insensitive to it.
- Power engineers report harmonic distortion of the 50/60 Hz mains as the ratio of to (THD).
Exercises
Exercise 1: Convert
A real signal has . Write the corresponding real term.
Answer
, that is .
Solution
, . In amplitude-phase form and .
Exercise 2: Predict the zeros
Which coefficients vanish for the triangle wave on ?
Answer
All , and all with even .
Solution
is even, so the vanish. Subtracting its mean leaves a half-wave antisymmetric function, so the even harmonics vanish as well. The remaining for odd .
Exercise 3: Check the triangle coefficients (code)
Verify for .
Answer
, , .
Solution
import numpy as np
N = 100000
t = np.arange(N) / N
tc = np.where(t < 0.5, t, t - 1)
f = np.abs(tc)
c = np.fft.fft(f) / N
for k in (1, 3, 5):
print(k, round(2 * c[k].real, 4), round(-2 / (np.pi ** 2 * k ** 2), 4))1 -0.2026 -0.2026
3 -0.0225 -0.0225
5 -0.0081 -0.0081
Test yourself
For a real signal, the amplitude of harmonic in the cosine-with-phase form is…
An even real function has a Fourier series with…
- only sines
- only cosines (and a constant)
- only odd harmonics
- no constant term
If , which harmonics are present?
- only even
- only odd
- all
- none