SQUARE WAVES

1012 Uses of Square Waves

Square waves have an interesting mix of practice and theory. In practice, they are extremely simple. In their simplest form, they consist of an alternating sequence of amplitudes; e.g. high/low or 1's and 0's. They're found in numerous applications. However in theory, they are somewhat difficult to analyze.

001 Harmonics

Often times square waves are used as a stimulus in a system. For example, in many PWM applications the square waves are low-pass filtered so that only the DC component used. In this case, the system consists of an imperfect low pass filter; imperfect in the sense that high frequencies are not totally suppressed. If we understood the harmonic content of the square wave we could ascertain which high frequency components are present and what their magnitudes are.

There are numerous ways to obtain the harmonic content of a square wave. I'll use Laplace Transforms and provide a few extra details along the way (in other words, the equations are derived as opposed to being referenced to another source). Consider the square wave shown below:

 ^ v(t)
 |      tau
 |     <---->
 |
A|     +----+                        +----+
 |     |    |                        |    |
-+-----+    +------------------------+    +--------->
                                                    t
   phi 
 <----->
       <-------------- T ------------>

There are four parameters that describe the square wave:

A - Amplitude.

phi - initial phase

tau - pulse width of the high pulses (less than T)

T - period or pulse rate

There are other parameters that we derive from these. For example:

f = 1/T is the pulse frequency

d = tau/T is the duty cycle

It's convenient for later analysis to define the square wave with all of these parameters. For example, if we wanted to see how the harmonics vary as a function of the duty cycle then we only need to change one parameter: tau.

The equation of the square wave can be written in terms of step functions. The first cycle, v0(t), can be written as

v0(t) = A(u(t-phi) - u(t-phi-tau))  for  0 <= t < T

Or graphically,

 | u(t-phi)
A|     +--------------------------------------------
 |     | 
-+-----+---------------------------------------------->
   phi                                              t
 <----->

 | u(t-phi-tau)
A|           +---------------------------------------
 |           | 
-+-----------+---------------------------------------->
   phi + tau                                         t
 <----------->

The whole square wave function can be expressed as a repetition of v0(t):

v(t) = v0(t - nT)    n = 0, +/-1, +/-2, 

Before diving into the details of finding the Laplace Transform of this square wave, it might be worth while studying the general theory behind the Laplace Transforms of Periodic Wave Forms. As discussed there, we only need to find the Laplace transform of a single cycle of the square wave.

The Laplace Transform of v(t) is then found from the following formula


             V0(s)
 V(s) = ---------------         (g=1 for this type of symmetry)
                  -sT
         1 - g * e
                        V0(s)
      = ------------------------------
          -s*T/2 /  s*T/2    -s*T/2 \
         e       | e      - e       |
                 \                  /
          s*T/2       V0(s)
      =  e     * ---------------
                  2*sinh(s*T/2)

Where V0(s) is the Laplace transform of v0(t), and g=1 (recall that this is a factor that describes the symmetry of the wave form as discussed in the LTPW page). The Laplace Transform of v0(t) is:

L[v0(t)] = L[A(u(t-phi) - u(t-phi-tau))]
            A  /  -s*phi    -s*(phi+tau) \
         = --- | e       - e             |
            s  \                         /
            A    -s*(phi+tau/2) /  s*tau/2   -s*tau/2 \
         = --- e                | e        - e        |
            s                   \                     /
           2*A  -s*(phi+tau/2)
         = --- e               *sinh(s*tau/2)
            s                  

And finally after inserting the expression for V0(s), we get the Laplace Transform of a square wave:

         s*(T/2-phi-tau/2  2*A* sinh(s*tau/2)     1
 V(s) = e                * ------------------- * ---
                            2*sinh(s*T/2)         s
           s*(T/2-phi-tau/2)   sinh(s*tau/2)
      = A*e                 * ---------------
                               s*sinh(s*T/2)

It probably goes without saying that this is certainly a complicated way to express something as simple as a square wave. Fortunately, the powerful tools associated with Laplace Transforms can efficiently utilize these closed-form analytical expressions. Our immediate goal is to find the harmonic content of the square wave. And you could argue that this is what we achieved with the Laplace Transform. However, let's take this one step further and find the discrete frequency expansion like that obtain from a Fourier Transform.

010 Fourier Series

The technique of finding the discrete transform amounts to finding the poles of the Laplace transform and the residues associated with those poles. Poles and residues are layman's terms for describing certain mathematical features of a function. Specifically, the poles are those values of the dependent variable that cause the function to evaluate to infinity. For example

1/(x-5), approaches infinity when x, the dependent variable, is equal to 5. Residues describe the magnitude of the function evaluated at the pole after the pole has been removed or canceled. A pole is "removed" by multiplying the function with a term (s-p)^a, where p is the pole and a is the order of the pole.

The poles of the Laplace transform of the square wave are at those values of s for which the denominator evaluates to zero. This occurs for s=0 (those of you familiar with LT theory may note the indeterminacy at s=0, but if you look closely through the lens of L'Hopital you will find that indeed s=0 is a pole) and for sinh(s*T/2) = 0. The latter case is only zero for imaginary frequencies:

    sinh(s*T/2) = 0
-j*sin(j*s*T/2) = 0
        j*s*T/2 = arcsin(0)
              s = j*2/T * (n*pi)     n = 0,+/-1, +/-2
                        2*pi
                = j*n * ----          n = 0,+/-1, +/-2
                          T

Now that we have all of the possible poles it's time to find the residues. I say possible because it may turn out that in the process of finding the residues we discover that some the poles are canceled. Let's find out. The formula for finding the residues is:

/                 \         (s-s_n)*sinh(s*tau/2)exp(s(T-tau)/2-phi)  |
| L[v(t)]*(s-s_n) |       = ----------------------------------------- |
\                 / s=s_n        s*sinh(s*T/2)                        |s=s_n

Note that both the numerator and the denominator evaluate to zero. This indeterminacy is resolved with L'hopital's rule. After applying one iteration of L'hopital's rule we get:

                             sinh(s_n*tau/2)exp(s_n(T-tau)/2-phi) 
                          = --------------------------------------
                                  T/2*s_n*cosh(s_n*T/2)
                             sinh(j*n*pi*d)                    j*n*2*pi/T*((T-tau)/2 - phi)
                          = --------------------------------* e
                             T/2* j*n*2*pi/T * cosh(j*n*pi)
                              j*sin(n*pi*d)         jn*pi   -j*n*2*pi/T*(tau/2+phi)
                          = -------------------- * e     * e
                              j*n*pi*cos(n*pi)

The exp(j*n*pi) term cancels the cos(n*pi) term leaving:

                               sin(n*pi*d)      -j*n*2*pi/T*(tau/2+phi)
                      R_n =  --------------- * e 
                                  n*pi
         ----------------------------------------------------------------

And this is the expression for the residues of the square wave. There is yet one more problem to be solved. Note that n=0 results in an indeterminacy. This is resolved by again applying L'hopital's rule. Differentiating the numerator and denominator with respect to n and then evaluating at n=0 results:

                    R_0 = d

In other words, the residue associated with the DC term is simply d, the duty cycle. Perhaps your intuition and knowledge of square waves is telling you that this is really a tremendous waste of effort going through this mathematical exercise to show something you already know. Appease any frustration by calling the duty cycle result a sanity check. One more good sanity check is for the 50% duty cycle case. In other words, you may be aware that no even harmonics are present in the expansion of a square wave with a 50% duty cycle. So as a check, substitute d=0.5 in the R_n equation


        |         sin(n*pi/2)  -j*n*pi/2   -j*n*phi*2*pi/T
    R_n |      = ------------ e         * e 
        | d=0.5      n*pi

And sure enough, if n is even the sin(n*pi/2) term in the numerator evaluates to zero.

At this point, we have got the poles and residues. We could consider our job done. The results are an infinite series expansion:

         infinity
           ----  sin(n*pi*d)     -j*n*2*pi/T*(tau/2+phi)
L[v(t)] =  \    ------------- * e                       * del(s-j*n*2*pi/T)
           /___     n*pi
        n=-infinity

Where the function del() is my way of denoting a delta function (in ASCII art). There is one more step that may be applied to convert this rather intimidating series into a more familiar form. Consider the Laplace transform of the cosine function:

                        s           s*ph/w
L[cos(w*t + ph)] =  ------------ * e
                     s^2 + w^2
                           s              s*ph/w
                 = ------------------- * e
                   (s + j*w)*(s - j*w)

The poles are seen to be:

 s_p = +/- j*w

And the residues associated with them are:

   |          j*w      j*ph            j*w
 R |      = ------- * e       = 0.5 * e
   |s=j*w    2*j*w

or writing both residues in one expression:

              +/-j*w
 R_p = 0.5 * e

Finally, the Laplace Transform can be written as:

                     /  j*w                -j*w             \
L[cos(w*t+ph)] = 0.5*| e   * del(s-j*w) + e    * del(s+j*w) |
                     \                                      /

To apply this result to our square wave expansion we need to pair up the poles of opposite signs. This amounts to folding the infinite series about n=0.

        infinity
           ----                               *
L[v(t)] =  \    (R_n * del(s-j*n*2*pi/T) + R_n * del(s+j*n*2*pi/T) )
           /___ 
            n=0

Where R_n is the n'th residue:

        sin(n*pi*d)     -j*n*2*pi/T*(tau/2+phi)
R_n =  ------------- * e           
           n*pi

If we make the substitution n=-n, then we get the residues:


           sin(-n*pi*d)     j*n*2*pi/T*(tau/2+phi)
R_(-n) =  ------------- * e           
             -n*pi
           sin(n*pi*d)     j*n*2*pi/T*(tau/2+phi)      *
R_(-n) =  ------------- * e                       = R_n
              n*pi

Substitute this result back into the series expansion of the square and wave we get:

                   infinity
                     ----  sin(n*pi*d)     /   /   2*pi   /     tau       \\\
L[v(t)] = d*del(0) + \    ------------- * L|cos|n* ---- * | t - --- - phi |||
                     /___     n*pi         \   \     T    \      2        ///
                      n=1

And finally (really), we get the series expansion of the square wave in terms of cosine waves:

          infinity
             ----  sin(n*pi*d)       /   2*pi   /     tau       \\
 v(t) = d +  \    ------------- * cos|n* ---- * | t - --- - phi ||
             /___     n*pi           \     T    \      2        //
              n=1

Here's a screen shot of the first 100 harmonics of the repeating bit stream 10010001110000111100010101101010. If you want to create this plot yourself, then grab fftsq.m. This is an Octave script.

010 Square Waves and Circuits

As an example, let's consider the response of a low-pass RC filter to a pulse-width-modulated square wave. You perhaps know from experience that the output has a DC component that's proportional to the width of the pulses. There's also a little ripple riding on the DC. But let's quantify it.

                  R
           +----/\/\/----------+
           |                   |
       /---+---\               |           
       | x(t)  |             -----  C      +
       \---+---/             -----         y(t)
           |                   |           -
           +-------------------+

The square wave input, x(t), is applied to the RC network and the output, y(t) is measured across the capacitor. We can use Laplace transforms to find y(t).

Y(s) = H(s) * X(s) 

We know X(s) from above. H(s) is found from circuit analysis to be

           1/RC
H(s) = ---------------
         s + 1/RC
So Y(s) is: 

           s*(T/2-phi-tau/2)   sinh(s*tau/2)      1/RC
 Y(s) = A*e                 * --------------- * -----------
                               s*sinh(s*T/2)     s + 1/RC

It's going to be slightly more useful to manipulate this expression with hyperbolic sines expressed in terms of sums of exponentials. Feel free to do the arithmetic and feel better if you derive this result:

                         -s*tau
           -s*phi   1 - e          1       1/RC
 Y(s) = A*e      * ------------ * --- * ----------
                         -s*T      s     s + 1/RC
                    1 - e

Now we have an expression for Y(s). However, we also want y(t). Perhaps the best approach here is to use partial fraction expansion.

            K1          K2        P_o(s)
Y(s) =  ----------  +  ---  +  -----------
         s + 1/RC       s              -sT
                                 1 -  e 

The first two terms are the natural response while the last term is the forced response. The constants associated with the natural response are solved by multiplying both sides of the equation by the poles and evaluating the resulting expression at the pole.

                       |
K1 = Y(s) * (s + 1/RC) |
                       |s= -1/RC

                             tau/RC
              phi/RC   1 -  e     
   = -A*RC * e      * ---------------
                             T/RC
                       1 -  e 

And similarly for K2 (after applying L'Hopital's once):

              |
K2 = Y(s) * s |
              |s = 0
   = tau/T

The only thing left is to find the expression for the periodic portion of the response, P_o(s).


               -sT              K1         K2 
P_o(s) = (1 - e   )*(Y(s) - ----------  -  --- )
                             s + 1/RC       s 
            -s*phi   RC        RC          -s*tau         K1        K2          -sT
       = A*e      *(---- - ----------)*(1 - e    ) -( ---------- + --- ) *(1 - e   )
                      s     s + 1/RC                   s + 1/RC     s

This ominous looking expression is very close to being in a standard form for inversion. But before we go back to the time domain, let's make an observation that will save some effort. Note that p(t) is a periodic expression with a period of T. In other words, p(t) = p(t-T). The expression above defines p_0(t) which is p(t) over one period. The significance is that the very last exponential term, exp(-s*T), can be dropped. In other words, this exponential term induces a time shift in p_0(t) beyond which p_0(t) is defined. Finally, after taking the inverse Laplace transform of the above expression we get:

                    -t/RC                                        -t/RC
P_0(t) = A*RC*(1 - e     )*(u(t-phi) - u(t-phi-tau)) - (K1 + K2*e     )*u(t)

Wouldn't be interesting to see the plot of this?

011 Harmonic Content of a Periodic Pulse Train

011.1 Hamonic Cancellation

Suppose you wish to generate a stream of pulses devoid of certain frequencies. For example, Don Lancaster's Magic Sinewave algorithm attempts to produce a pulse stream that when low-pass filtered will leave behind a relatively spectrally pure sine wave. His algorithm minimizes the number of pulses over one cycle of the sinewave as contrasted to similar PWM algorithms that attempt to maximize the number of pulses over one cycle. Another example is for tone detection. Here you may be interested in DTMF decoding or perhaps a 60Hz digital phase locked loop. In either case, it's important to minimize or optimize the detection algorithm so that not all of the CPU's resources are consumed.

So how do you go about cancelling harmonics? Certainly there are hardware techniques that use analog filters. But the focus here is on algorithms and mathematics.

Here is a completely arbitrary square wave:


 ^ v(t)
 |      tau
 |     <---->
 |
A|     +----+                        +----+
 |     |    |                        |    |
-+-----+    +------------------------+    +--------->
                                                    t
   phi 
 <----->
       <-------------- T ------------>

And just to be clear, here is a description of each parameter:

A - Amplitude.

phi - initial phase

tau - pulse width of the high pulses (less than T)

T - period or pulse rate

Two useful parameters derived from these are:

f = 1/T is the pulse frequency

d = tau/T is the duty cycle

Now, it can be shown that(1) the Fourier series is given by:


               sin(n*pi*d)      -j*n*2*pi/T*(tau/2+phi)
      R_n =  --------------- * e 
                   n*pi

Where n is the harmonic number. (More specifically, this is the n'th term of the Fourier series; the whole series is in fact the infinite summation of each term). Before diving into the details, here are a couple of octave programs that you may use to study the harmonic content of square waves:

ms.m

ms2.m

The expression above is a complicated way to express a square wave, so let's look at this equation more closely. First let's see how we can reconcile it with what we know (or have been taught) about square waves. You may be aware that a square with a 50% duty cycle does not have even harmonics and that the strength of each (or the remaining odd) harmonics is inversely proportional to harmonic number. A 50% duty cycle means that the square wave is high for half of its cycle. In terms of the parameters above, tau = T/2 and d = 1/2. We can make phi be zero:



  ^ v(t)
  |    tau=T/2
  |<------------->
  |
A +--------------+              +------------+
  |              |              |            |
--+              +--------------+            +->
                                                    t
   <------------- T ------------>

And the expression for the harmonics:

               sin(n*pi/2)      -j*n*2*pi/T*(T/4 + 0 )
      R_n =  --------------- * e 
                   n*pi


               sin(n*pi/2)      -j*n*pi/2
      R_n =  --------------- * e 
                   n*pi

A closer examination of sin(n*pi/2) reveals:

     n    |   sin(n*pi/2) | exp(-j*n*pi/2)
 ---------+---------------+---------------
     1    |       1       |      -j1
     2    |       0       |       -1
     3    |      -1       |       j1
     4    |       0       |        1
     5    |       1       |      -j1
     6    |       0       |       -1
     7    |      -1       |       j1
     8    |       0       |        1

The sine term is responsible for suppressing the even harmonics. Combining each of the terms yields:


     n    |     R_n
 ---------+------------
     1    |  -j(1/pi)
     2    |     0
     3    |  -j(1/pi/3)
     4    |     0
     5    |  -j(1/pi/5)
     6    |     0
     7    |  -j(1/pi/7)
     8    |     0
     9    |  -j(1/pi/9)

The even harmonics have been suppressed and the strength of the odd harmonics vary inversely proportional to harmonic number. In general, we can suppress any given harmonic by varying the width of the pulse. For example, to suppress the n'th harmonic:


               sin(n*pi*d)      -j*n*2*pi/T*(tau/2+phi)
   R_n = 0 =  --------------- * e 
                   n*pi

         0 =   sin(n*pi*d)

    n*pi*d = arcsin(0)

    n*pi**T/7, 3*T/7, ...

Note that suppressing one harmonic will cause others to reappear. For example, if we do suppress the 7th harmonic, the 2nd,3rd, etc. harmonics will be present.

011.10 Canceling Multiple Harmonics

So how would you suppress two harmonics that are not multiples of one another? As long as there's just one pulse per period, you can't. But if you introduce additional pulses over the period, then you can! This is where the phase term becomes important. It's probably easiest to see how this works by starting with an example. Suppose the period, T, is divided into 12 equal portions and that we would like to construct a waveform consisting of several pulses each 1/12 of T. Using the parameters for the square wave we've got:

M = 12, this is the number of pulses for one period.

tau = T/M = T/12

d = tau/T = 1/12

phi = m * tau = m * T/12 where m =0,1,2,...,11

In other words, each pulse has the same width, tau, and duty cycle, d. The phase of the pulse, phi, depends on its quantized position. The m'th pulse is the one that 'm' units from the beginning of the pulse stream. And of course, the pulse stream repeats with a period, T.

The Fourier series for the m'th pulse can be written



               sin(n*pi*d)      -j*n*2*pi/T*(tau/2+phi)
   R_n,m  =  --------------- * e 
                  n*pi

              sin(n*pi*d)      -j*n*2*pi/T*(tau/(2*M) + m*T/M)
          =  --------------- * e 
                  n*pi

              sin(n*pi/12)     -j*n*2*pi/T*(T/24 + m*T/12)
          =  --------------- * e 
                  n*pi

              sin(n*pi/12)     -j*n*pi*(1 + 2*m)/12
          =  --------------- * e 
                  n*pi
              sin(n*pi/12)     -j*n*pi/12   -j*n*pi*m/6
          =  --------------- * e         * e
                  n*pi

From this we can observe that the magnitude at a given harmonic depends only on the harmonic number, n, and not on the pulse position, m. The phase, on the other hand, depends on both the harmonic and pulse position.

Now let's look at how two pulse interact with one another. Let's call them m1 and m2 for right now.


 ^ v(t)
 |      tau
 |     <-->
 |      m1    m2                 m1    m2
A|     +--+  +--+               +--+  +--+
 |     |  |  |  |               |  |  |  |
-+-----+  +--+  +---------T-----+  +--+  +-------> t
   phi1
 <----->
      phi2
 <----------->

 <----------- T ----------> 

 phi1 = m1 * tau
 phi2 = m2 * tau  (m1 and m2 are integers between 0 and 11)

To obtain the Fourier series of the two-pulse pulse train we only need to add together the Fourier series obtained from the pulses when they're taken individually:


  Rn = Rn,m1 + Rn,m2

Which says that the nth Fourier term of the composite wave is the sum of the nth terms of the m1 and m2 pulses.



         sin(n*pi/12)   -j*n*pi*(1+2*m1)/12  sin(n*pi/12)   -j*n*pi*(1+2*m2)/12
 R_n  =  ------------ * e                 +  ------------ * e 
            n*pi                                 n*pi

         sin(n*pi/12)   / -j*n*pi*(1+2*m1)/12   -j*n*pi*(1+2*m2)/12 \
      =  ------------ * |e                 +   e                    |
            n*pi        \                                           /

         sin(n*pi/12)    -j*n*pi/12  / -j*n*pi*m1/6   -j*n*pi*m2/6 \
      =  ------------ * e          * |e           +   e            |
            n*pi                     \                             /

The term outside of the brackets depends only on the harmonic number (and not position or phase of the pulse. As seen earlier, this can be made zero only by varying the pulse width. However the pulse width has been fixed to T/12. Consequently we need to study the term in the brackets if we wish to investigate harmonic cancellation.

Before simplifying the equation, it's worth while observing the tabulation of the exponential terms for the first few harmonics:


  pulse          phase
     m     |  exp(-j*n*pi*m/6)
-----------+---------------------------------------------
     0     |  cos(n*pi*0/6) -j*sin(n*pi*0/6)  = 1
     1     |  cos(n*pi*1/6) -j*sin(n*pi*1/6)  
     2     |  cos(n*pi*2/6) -j*sin(n*pi*2/6)  = cos(n*pi/3) -j*sin(n*pi/3)
     3     |  cos(n*pi*3/6) -j*sin(n*pi*3/6)  = cos(n*pi/2) -j*sin(n*pi/2)
     4     |  cos(n*pi*4/6) -j*sin(n*pi*4/6)
     5     |  cos(n*pi*5/6) -j*sin(n*pi*5/6)
     6     |  cos(n*pi*6/6) -j*sin(n*pi*6/6)  = cos(n*pi)
     7     |  cos(n*pi*7/6) -j*sin(n*pi*7/6)
     8     |  cos(n*pi*8/6) -j*sin(n*pi*8/6)
     9     |  cos(n*pi*9/6) -j*sin(n*pi*9/6)
     10    |  cos(n*pi*10/6) -j*sin(n*pi*10/6)
     11    |  cos(n*pi*11/6) -j*sin(n*pi*11/6)

For the fundamental, n=1, this table can be re-written:

  pulse          phase
     m     |  exp(-j*n*pi*m/6)
-----------+---------------------------------------------
     0     |              1
     1     |  cos(pi/6)   - j*sin(pi/6)  
     2     |  cos(pi/3)   - j*sin(pi/3)
     3     |  cos(pi/2)   - j*sin(pi/2)
     4     |  cos(pi*2/3) - j*sin(pi*2/3)
     5     |  cos(pi*5/6) - j*sin(pi*5/6)
     6     |             -1
     7     | -cos(pi*6)   + j*sin(pi/6)
     8     | -cos(pi/3)   + j*sin(pi/3)
     9     | -cos(pi/2)   + j*sin(pi/2)
     10    | -cos(pi*2/3) + j*sin(pi*2/3)
     11    | -cos(pi*5/6)   + j*sin(pi*5/6)

Or if you prefer, the phasor graph is shown below. The number next to each '*' is the pulse position, 'm', from the table above. (A phasor diagram is essential a vector plot. The 'real component' of the phase is the magnitude of the x=axis and the 'imaginary component' is the magnitude of the y-axis. The vector (or phasor) starts at the origion of the graph and extends to the (x,y) coordinate defined by the real and imaginary portions of the phasor). As we shall see below, the phasor diagram is a convenient way to visualize harmonic cancellation. Phasor are combined vectorially. So two phasors that point in opposite directions (and have the same magnitude) will cancel one another.

             j
             ^
             | 9
        8    *     10
        *    |    *
    7     \  |  /      11
    *.     \ | /     .*
 6     '  . \|/.  '       0
--*----------+----------*--------->
       .  '/ |\'  .       
    *'    /  | \    ' *
   5     /   |  \       1 
        *    |    * 
       4     *      2
             | 3

For the second harmonic, the table and graph are:


     m     |  exp(-j*n*pi*m/6)
-----------+---------------------------------------------
     0     |              1
     1     |  cos(pi/3)   - j*sin(pi/3)  
     2     |  cos(pi*2/3) - j*sin(pi*2/3)
     3     |             -1
     4     | -cos(pi*1/3) + j*sin(pi*1/3)
     5     |  cos(pi*2/3) + j*sin(pi*2/3)
     6     |              1
     7     |  cos(pi/3)   - j*sin(pi/3)
     8     |  cos(pi*2/3) - j*sin(pi*2/3)
     9     |             -1
     10    | -cos(pi*1/3) + j*sin(pi*1/3)
     11    |  cos(pi*2/3) + j*sin(pi*2/3)


             ^
             |  
        4,10 |      5,11
        *    |    *
          \  |  /      
           \ | /        
 3,9        \|/           0,6
--*----------+----------*--------->
           / |\            
          /  | \          
         /   |  \         
        *    |    * 
       2,8   *     1,7 
             |  

It's interesting to see how the pulses 6 through 11 are aliased to pulses 0 through 5. This trend of aliasing the phase continues as long as the harmonic, n, divides evenly into the number of pulses, M.

Finally, for n=3:


     m     |  exp(-j*pi*m/2)
-----------+---------------------------------------------
     0     |        1
     1     |       -j
     2     |       -1
     3     |        j
     4     |        1
     5     |       -j
     6     |       -1
     7     |        j        
     8     |        1
     9     |       -j
     10    |       -1
     11    |        j


             ^
             | 3,7,11
             *
             |
             |
             |
 2,6,10      |
--*----------+----------*--------->
             |          0,4,8
             |
             |
             |
             *
             | 1,5,9

Example two-pulse pulse trains for M=12

By either inspecting the table or examining the graph, we can easily see how two pulses may be paired such that their phases cancel for a given harmonic. For n=1, we could pair m=0 and m=6. This would cancel the fundamental (i.e. n=1 corresponds to the fundamental). In fact, if you draw the pulse train containing just pulses 0 and 6, you'll notice that the frequency is doubled. It's not our objective to cancel the fundamental. So let's look at the table and graph for n=2. We can see that 0 and 6 have exactly the same phase and that they are opposite of 3 and 9. So if formed a pulse train consisting of pulse at the m=0 position and one at the n=3 position, the second harmonics would cancel! Here are several examples:

Pulses at positions 1 and 7. This cancels the 'fundamental', which means that we created a new square wave with twice the frequency of the first.

 ^ v(t)
 |
A|  +--+              +--+              +--+
 |  |  |              |  |              |  |
-+--+  +--------------+  +-----------T--+  +-----> t
 0  1  2  3  4  5  6  7  8  9 10 11  0  1  2  3

Pulses at positions 1 and 4. This suppresses the 2nd harmonic. The fundamental and third harmonics are sqrt(2) times larger than the fundamental and third for just a single pulse.

 ^ v(t)
 |
A|  +--+     +--+                       +--+
 |  |  |     |  |                       |  |
-+--+  +-----+  +--------------------T--+  +-----> t
 0  1  2  3  4  5  6  7  8  9 10 11  0  1  2  3

Pulses at positions 1 and 3. This suppresses the 3rd harmonic.


 ^ v(t)
 |
A|  +--+  +--+                          +--+
 |  |  |  |  |                          |  |
-+--+  +--+  +-----------------------T--+  +-----> t
 0  1  2  3  4  5  6  7  8  9 10 11  0  1  2  3

Now let's return to the expression for the two pulse Fourier Series.



          sin(n*pi/12)    -j*n*pi/12  / -j*n*pi*m1/6   -j*n*pi*m2/6 \
   R_n =  ------------ * e          * |e           +   e            |
             n*pi                     \                             /

In general, we can induce phase cancellation when the term in the brackets is zero:



                   / -j*n*pi*m1/6   -j*n*pi*m2/6 \
              0 =  |e           +   e             |
                   \                             /

   -j*n*pi*m1/6      -j*n*pi*m2/6 
  e             =  -e          


   -j*n*pi*m1/6      -j*n*pi*m2/6 j*pi
  e             =   e           e

                     j*pi*(6 - n*m2)/6
                =   e

Resist the temptation of taking the natural log and saying that m1 = (m2 - 6/n). The reason is that there's the multiplication by 'n'. This has the effect in some instances of advancing the phase by more than 2*pi radians. And when this happens you'll need to account for the wrapping around. So we can cover ourselves by re-writing the equation slightly. First note:


   j*pi*x      j*pi*(x % 2)
  e       =   e          

And apply this to the expression above:


   -j*pi*((n*m1/6)%2)       -j*pi*(( (-6  n*m2)/6) % 2)
  e                    =   e          

The exponential implicitly performs the mod operation. We just made that explicit, so now it's safe to take the logarithm:


            -(n*m1/6)%2 = -((6 - n*m2)/6)%2

If n evenly divides into M/2, or stated equivalent, (M/2) % n = 0, then we may re-write this equation:

            (n*m1/6)%2 = ((6 - n*m2)/6)%2
                     0 = (n*m1/6 + n*m2/6 + 1)%2
                     0 = (-n*m1/6 + n*m2/6 + 6/6)%2

                          -n*m1 + n*m2 + 6
                     0 = ------------------ % 2
                                 6

                          n*(-m1 + m2 + 6/n)
                     0 = ------------------- % 2
                                 6

                          -m1 + m2 + 6/n
                     0 = ------------------- % 2
                               6/n

                          (-m1 + m2 + 6/n) % (2*6/n)
                     0 = ---------------------------  
                               6/n

                     0 =  (-m1 + m2 + 6/n) % (2*6/n)

Re-iterating, the last step assumes that 6%n is zero OR n = 1,2, or 3. Before generalizing this result, let's apply this to the tabulated results and see how well the equation works. For n = 1, we noticed that pulses separated by 6 units would cancel. So assigning n = 1:

             0 = (-m1 + m2 + 6) % 12

This equation is satisfied for m1=0 and m2 = 6, (1,7), etc. What about m1 = 7 and m2 =1?

             0 = (-7 + 1 + 6) % 12 = 0 % 12, yep

Let's examine the third harmonic, n=3. Our observations from the tabulated results concluded that pulses separated by two positions cancelled the 3rd harmonic.

             0 =  (-m1 + m2 + 6/3) % (2*6/3)
             0 =  (-m1 + m2 + 2) % 4

Which agrees with the observation. As long as m1 and m2 differ by 2, this equation is satisfied.

Generalizing the results for two pulses

Most of the time derivations are derived generically and then specific examples are studied afterwards. The opposite approach has been taken here. Deriving a specific case allowed us to continuously compare our derivation to our observations. Reality checks are always invaluable. Extrapolating to the general case turns out to be fairly straight forward. While we could rigorously repeat all of the above in generic terms, let's instead pick out the salient portions.

In the general case, there are M pulses. We're interested in suppressing the n'th harmonic by having the phase of two pulses cancel one another. The two pulses have been parameterized as m1 and m2. So here are the requirements for generalizing the above:

a)   0 = M % 2
b)   0 = (M/2) % n

The first says that M must be even. The second says that the n'th harmonic must evenly divide half of M. If these two conditions are met, then the harmonics due to the m1 and m2 pulses cancel when:

   +-------------------------------------+
   |  0 = (-m1 + m2 + (M/2)*n) % (M/n)   |
   +-------------------------------------+

Observations

If we wish to cancel the 2nd through n'th harmonics, it's necessary for each of these in turn to evenly divide M/2. The following table lists the minimum value for M such that the 2nd through n'th harmonics are cancelled:

    n   |   M
  ------+-------
    2   |   4
    3   |  12
    4   |  24
    5   |  120
    6   |  120
    7   |  840
    8   |  840
    9   |  2520

100 Tone Detection
101 Dual Tone Multi-Frequency (DTMF) Detection

And here's more software.

BACK HOME


This page is maintained by Scott Dattalo. You can reach me at home: scott@dattalo.com . Last modified on 10MAR00.