5.7. Summing sinusoids#

In the previous sections, we’ve made use of the fact that the samples of a wave at an analysis frequency must sum to zero. However, we never actually proved this from first principles.

In fact, we can say something a little stronger, and exactly characterize the sum of samples for a wave at any frequency:

n=0N1cos(2πfnfs+ϕ)=?

Computing this sum requires adding up wave samples, which can be done directly, though it can be tedious. As we’ll see, this is a case where the complex exponential form is more convenient to work with.

5.7.1. Aside: geometric series#

Recall that Euler’s formula (4.1) converts between rectangular and polar coordinates:

ejθ=cos(θ)+jsin(θ).

Since this holds for any angle θ, it must also hold for nθ as we vary n:

ejnθ=cos(nθ)+jsin(nθ),

and by the product rule for exponents, we can re-write the left-hand side as follows:

ejnθ=(ejθ)n.

This will allow us to turn a summation of wave samples into a summation of the form zn, which is also known as a geometric series. Geometric series have many nice properties, but for now, the one we’ll need is a formula for calculating the sum of the first N terms.

Lemma 5.1 (Summing finite geometric series)

Let z0,1 be a complex number, and N>0 be an integer. Then

n=0N1zn=1zN1z.

In plain language, this lemma says that summing up increasing powers of a number z (even a complex number z) can be equivalently expressed as a ratio, rather than adding up individual terms.

Proof. To prove Lemma 5.1, observe that if we multiply the left-hand side (the summation) by (1z), then successive terms in the summation will partially cancel each-other out.

(1z)n=0N1zn=n=0N1(1z)znDistribute (1z)=n=0N1(znzn+1)Multiply through by zn=(z0z1)+(z1z2)+(z2z3)++(zN1zN)Expand sum=z0+(z1+z1)+(z2+z2)++(zN1+zN1)zNRe-group terms=z0zNCancel terms (zk+zk)=1zNz0z0=1

Since z1 (by hypothesis), we know that 1z0, so we can safely divide both sides of this equation by 1z to get the identity:

n=0N1zn=1zN1z.

5.7.2. Summing complex exponentials#

Now that we have Lemma 5.1, we can state the following theorem.

Theorem 5.1 (Complex exponential sums)

Let θ0 be an angle, and let N>0 be an integer. Then,

n=0N1ejnθ=0if and only ifθ2πkN

for an integer k0modN.

In plain language, Theorem 5.1 says that a complex sinusoid with a frequency that completes a whole number of cycles in N samples must sum to 0. An example of this is illustrated below by Fig. 5.18. We can actually say a bit more than that, and also characterize what happens for any frequency, and see that if the wave does not complete a whole number of cycles, then its sum cannot be 0.

Note that this does not handle the special case of θ0 (f0=0) case, for which the summation simplifies to 1+1+1+=N+0j.

Fig. 5.18 An example of the running summation n=0N1zn where N=9 and z=e2πj/9. The angle of z (shaded region) is 2π1/N, so this summation will total to 0.#

5.7.2.1. Proof#

Theorem 5.1 has an “if and only if” form, so we’ll need to prove both directions:

  • () θ of the given form implies the summation must be zero, and

  • () the summation being zero implies θ takes the given form.

Note that ejnθ=(ejθ)n by the product rule for exponents. If θ0 then ejθ1, so we are allowed to use the geometric series identity with z=ejθ:

(5.13)#n=0N1ejnθ=n=0N1(ejθ)n=1ejNθ1ejθ.

Proof. ()

If θ=2πk/N for integer k, then the numerator can be equivalently expressed as

1ejNθ=1ejN2πk/Nsubstitute θ=1ej2πkcancel N/N=1ej0cancel extra rotations 2πk=11=0.

Since the numerator is 0, so too is the entire summation.

Proof. ()

In the other direction, if we assume the summation is 0, then we must have

0=1ejNθejNθ=1=ej0,

which implies Nθ=2πk for some integer k because Nθ must be equivalent to a whole number of rotations (in either direction). Dividing through by N, we get θ=2πk/N.

5.7.3. What about phase?#

We can generalize the statement above to handle phase offsets as well. Because the phase offset does not change with the sample index n, we can factor it out of the summation:

(5.14)#n=0N1ej(θn+ϕ)=n=0N1ejθnejϕ=ejϕn=0N1ejθn=ejϕ1ejNθ1ejθ.

This says that when a wave is shifted by ϕ, the summation is multiplied by ejϕ. Note that this is a pure rotation, so if the summation was 0 (i.e., we had an analysis frequency), then it will still be zero under any phase shift. Likewise, if the summation was non-zero, it will remain non-zero under any shift.

5.7.4. Back to the original question#

The theorem above is for complex exponentials, which involve both a real and imaginary component. However, our original question was about summations of general waves in standard form:

n=0N1cos(2πfnfs+ϕ)

For this, we can use the fact that cos(θ) is equivalent to the real part of ejθ, which implies

cos(θ)=12(ejθ+ejθ),

or when a sample index n and phase offset ϕ are introduced, and letting θ=2πf/fs:

cos(θn+ϕ)=12(ej(θn+ϕ)+ej(θn+ϕ)).

By using (5.14), we can transform each part of this summation independently. The end result is the rather unwieldy formula:

(5.15)#n=0N1cos(θn+ϕ)=ejϕ21ejNθ1ejθ+ejϕ21ejNθ1ejθ

5.7.5. Why does this matter?#

Many of the things we’d like to say about Fourier series depend on having waves “average out to zero”. For continuous (time) signals, we can show this kind of thing via symmetry arguments (like in chapter 1), but when using discretely sampled signals, a bit more care must be taken.

The main theorem in this section tells us that waves at analysis frequencies always sum to 0, but in proving that theorem, we got as a byproduct a general equation (5.15) for sums of waves at arbitrary (non-analysis) frequencies and phase offsets. While this equation could be used in principle to bypass computing sums sample-by-sample, it is more useful as an analytical tool: it allows us to reason about the properties of the sum (e.g., whether it is 0 or non-zero, real or complex, etc) just by knowing the wave’s parameters.