# Call it! Even or Odd?

Thu 09 May 2013 - 11:07:00 CDT

In my earlier post about Mr. Gibbs I discussed using the Fourier series to break down a periodic signal into consitituent sine waves. The example was a 50% duty-cycle square wave, and, as it happens, the Fourier series only included sine terms and only included every other one. Real world signals tend not to be so uniform, and now I want to take a quick closer look at what happens when you break the symmetry.

The first step is straightforward. The earlier square wave was defined as having a transition at t=0 (assuming the signal is a function of time, t). Likewise, sin(t) also transitions through zero at t=0, but cos(t) is has a maximum at 0. So the square wave is in-phase with a sine function, and only exhibits non-zero b coefficients—the coefficients of the sine harmonics—as shown in the following plot.

But if we shift the square wave by one-quarter period, the center of one of its lobes will be at t=0, similar to a cosine. Also, by definition, shifting a sine by a quarter period gives you a cosine. Together this suggests that the shifted square wave is in phase with a cosine, and its Fourier series should have only cosine terms—a coefficients instead of b coefficients. The next plot shows this. And also note that the magnitudes of the coefficients match between the two plots, but due to the mathematical details, the a coefficients alternate between positive and negative values.

Now what happens if the shift is by some amount other than a quarter period (or some multiple)? Remember odd and even functions from high-school math? An odd function follows:

$$f(-x)=-f(x)$$

A sine function is an example. A cosine function, on the other hand, is even and follows:

$$f(-x) = f(x)$$

So another way of looking at the two examples above is that the first square wave is an odd function and the second (shifted by a quarter period) is even. If you add even functions together, you end up with an even function. Likewise with adding odd functions to get an odd sum. So it makes sense that the odd square wave only has sine constituents, and the even square wave is built from cosines.

If we do shift the square wave by some arbitrary amount it will no longer be an odd or even function, and it will take some mixture of sines and cosines to build it up. If you shift the sine-phased square wave to the left by some amount t’ and crunch the calculus, you end up with these coefficients:

$$a_n = \frac{2 \sin(n t’)}{n \pi} \left( 1-\cos(n\pi)\right)$$

$$b_n = \frac{2 \cos(n t’)}{n \pi} \left( 1-\cos(n\pi)\right)$$

The next plot shows the result.

When we superimpose the sum of just the cosine terms—the first 10 harmonics—and the sum of just the sine terms on the shifted square wave, a pattern emerges. Note in the plot below that the cosine terms (red) fill in the portion of the shifted square wave that is even, and the sine terms (blue) fill in the portion that is odd.

Now you may have noticed one other detail: regardless of the shift, the coefficients for even harmonics—not talking about even functions, rather simply even indexes (2, 4, 6, …)—are always zero. We’ll look at that in a future post and also look at applying this stuff to some real-world problems. Stay tuned.