I have the following function defined for a quasi-square wave:

Clear[x, f, T, s, s0];
f = 60;
T = 1/f;

sa[x_] := 
 Which[x > 2*Pi, s0[Mod[x, 2*Pi]], x < 0, s0[Mod[x, 2*Pi]], 
  0 < x < 2*Pi, s0[x]]
s0[x_] := Piecewise[{{0, x < Pi/6}, {1, Pi/6 < x < 5*Pi/6}, {0, 
     5*Pi/6 < x < 7*Pi/6}, {-1, 7*Pi/6 < x < 11*Pi/6}, {0, 
     11*Pi/6 < x < 2*Pi}}];

Plot[{sa[2*Pi*f*x], sa[2*Pi*f*x - 2*Pi/3], sa[2*Pi*f*x + 2*Pi/3], 
  Sin[2*Pi*f*x], Sin[2*Pi*f*x - 2*Pi/3], 
  Sin[2*Pi*f*x + 2*Pi/3]}, {x, -0*T, 1*T}]


The plot shows three quasi-square waveforms time-shifted by multiples of $\frac{2\pi}{3}$. When I calculate the Fourier series for $s_a(2\pi ft)$, I get the following output:

a = FourierTrigSeries[sa[2*Pi*f*x], x, 7, 
  FourierParameters -> {1, 2 Pi/T}]

$\frac{2 \sqrt{3} \sin (120 \pi x)}{\pi }-\frac{2 \sqrt{3} \sin (600 \pi x)}{5 \pi }-\frac{2 \sqrt{3} \sin (840 \pi x)}{7 \pi }$

which shows only odd harmonics without triplen harmonics. This is expected.

However, when I try to calculate the FourierCosCoefficient, I get the following expression for the code snippet:

aSa[n_]=FourierCosCoefficient[sa[2*Pi*f*x], x, n, 
 FourierParameters -> {1, 2 Pi/T}]

$\frac{2 \left(\sin \left(\frac{5 \pi n}{6}\right)-\sin \left(\frac{\pi n}{6}\right)\right)}{\pi n}$

which gives:

aSa[2] // FullSimplify

$-\frac{\sqrt{3}}{\pi }$

This implies that an even harmonic exists at $2f$, which is inconsistent with the first result from the Fourier series.

Could someone please explain what is causing this or what I am doing wrong? I am confused about the usage of FourierParameters.


1 Answer 1


It is because FourierCosCoefficient or FourierCosSeries assumes the function is even.

enter image description here

You can ca see it in the definition of coefficients of FourierTrigSeries where integral is taken over interval (-Pi,Pi).

enter image description here

while for FourierCosSeries the interval of integration is (0,Pi) and coefficient is multiplied by 2 (i.e. it is assumed function is even).

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.