## Tuesday, October 18, 2016

### SDR Notes: The Mixer Mathematics of Digital Down Conversion

(This post originally started as notes to myself, placed here so that I would not lose or forget them.)

The Digital Down Converter (DDC) is a basic block of FPGA-implemented SDR radios.  Per Wikipedia:
A digital down-converter (DDC) converts a digitized, band limited signal to a lower frequency signal at a lower sampling rate in order to simplify the subsequent radio stages.
Below is an illustration of a DDC stage (don't worry about the math -- it will be explained later in this post):

(Click on image to enlarge)

Note that, for demonstration purposes, the equations assume a simple cosine as the input signal.

This post will look at the math involved in the Mixer.  I will leave the low-pass filter and sample-rate conversion for later posts.

First, some basics...

Basic Down-Conversion Mixing:

Historically, down-conversion has been done in the analog domain with a "real" oscillator signal (e.g. cos(ωot)).  Let's first look at this type of basic mixer before tackling mixing in the Digital (and Complex) domain.

For demonstration purposes, I'll simplify the receive-signal to be a just simple cosine signal at a single frequency:  cos(ωit).

This mixer's math is straightforward.  Let the output of the mixer be y(t).

y(t) = cos(ωit)*cos(ωot)

We can use Trigonometric identities to express this equation in terms of sums and differences of frequencies:

y(t) = (cos((ωi−ωo)t))/2 + (cos((ωio)t))/2

But this basic form of mixing has a problem if one would like to down-convert an incoming RF signal directly to base-band:  both the desired signal and its image will appear in the base-band spectrum (which, for the typical shortwave receiver, is the audio spectrum we want to hear).

This type of conversion is known as "Direct Conversion."  For an example, see Rick Campbell's R1 receiver.

Visually, here's how the frequencies shift, shown as a single-sided spectrum (which one would see if one did a "Trigonometric" Fourier Transform on the RF input.  Refer to equation 27 in this paper by Robert Marcus for more detail)::

Note the overlap of the two signals down at base-band...our "desired" signal would be interfered with by any signal at its "image" on the other-side of the oscillator's frequency!

And if we were to consider the Mixer's input to be a band of frequencies:

You can see the spectrum fold-back with the result being the desired signal and its undesired image occupying the same base-band frequencies.  A single-sided spectrum graph has no negative frequencies, and any "calculated" negative frequencies become positive frequencies via the Trig identity: cos(−ωit) = cos(ωit).

We can get around this image problem by working in the domain of Complex Numbers (numbers with a real and an imaginary component).  Specifically, we will use exponentials with complex arguments.

Complex Exponentials -- A Quick Review of Some Important Identities:

Euler's Formula:

e = cos(θ) + jsin(θ)

Similarly,

e−jθ = cos(θ) - jsin(θ)

From Euler's Formula it can be shown that:

cos(θ) = (e + e−jθ)/2

sin(θ) = j(e−jθ − e)/2

Let's consider a real signal at a single frequency fo (Hz), and let's express this signal simply as a cosine: cos(2πfot).

Using the identities above this signal can be expressed in exponential form:

cos(2πfot) = (ej2πfot + e−j2πfot)/2

Below is a representation, in the complex frequency-domain, of this signal :

And, for completeness, here are a two more illustrations:

First, to complement the cosine representation above, here is a complex frequency-domain representation of a sine wave signal of the same frequency:

Second, we can use both of these illustrations of the signals in the complex frequency-domain to generate a visual representation of Euler's Formula, showing how the imaginary sine terms are rotated (when multiplied by j) to the real axis and then added to the real cosine terms:

(Click on image to enlarge)

Note that multiplying sin(2πfot) by j rotates the sine's complex frequency-domain imaginary components "clockwise" by 90 degrees to the real plane. If we were to instead multiply sin(2πfot) by -j, the rotation would be 90 degrees counter-clockwise, with the results again being on the real plane, but pointing in the opposite direction, and our final result (after adding the real components together) would represent Euler's Formula for a negative frequency, -fo, instead of fo.

Frequency Conversion using Complex Numbers in Exponential Form:

Let's use the above equations to shift signal frequencies.

First, for ease of demonstration, let's define an input RF signal, x(t), to be a simple cosine at a single frequency, fi Hz.  I.e.:

x(t) = cos(2πfit)

To minimize my typing, I will express this signal's frequency as its radian equivalent, where ωi = 2πfi.

x(t) = cos(ωit)

Using the identities above we can express cos(ωit) as the sum of two complex exponential numbers:

cos(ωit) = (eit + e−jωit)/2

Now let's now define our oscillator's signal as a complex exponential:

eot

(Note that from Euler's Formula eot  = cos(ωot) + jsin(ωot)).

Our next step is to multiply together the input signal and the oscillator signal.  We will call the output y(t).

y(t) =  cos(ωit) * eot

Replacing the input signal with its equivalent complex exponential form, the output equation becomes:

y(t) = [(eit + e−jωit)/2]*eot

Finally, let's finish the multiplying.  The result is:

y(t) = (ej(ωio)t + ej(−ωio)t)/2

Note that the frequency components in the arguments of both exponentials have been shift up by ωo.

By the way, we can use Euler's Formula to express this result in terms of sines and cosines:

y(t) = [cos((ωio)t) + jsin((ωio)t)]/2 + [cos((-ωio)t) + jsin((-ωio)t)]/2

You can also derive the same result using only sines, cosines, and trigonometric identities and not complex exponentials, but the math is more cumbersome.

OK, so an NCO's output that is a complex-exponential with an argument whose frequency is +ωwill shift the incoming signal's frequency up by ωo.  What happens if the NCO's frequency is negative, i.e. -ωo?

Using the same approach as above, the DDC's output can be shown to be:

y(t) = (ej(ωi−ωo)t + ej(−ωi−ωo)t)/2

In other words, both of the input signal's complex exponentials are shifted down in frequency by ωo. Voila, a Digital Mixer!

Again, note that y(t) can be expressed as the sum of sines and cosines.  Using the identities at the start of this post:

y(t) = [cos((ωio)t) + jsin((ωio)t)]/2 + [cos((ωio)t) - jsin((ωio)t)]/2

which is exactly equivalent to y(t) = (ej(ωi−ωo)t + ej(−ωi−ωo)t)/2.

Mixing with Complex Exponentials:

With a view towards understanding SDR building blocks, let's look at a Digital Mixer using the down-conversion math I've just discussed, and which shifts signal frequencies in the digital (rather than analog) realm.

Below is a Digital Mixer block diagram using complex numbers.  Let's drive the RF input with a simple cosine signal, cos(ωot):

Note that the oscillator's output is a complex exponential with a negative frequency in its argument.  This negative frequency, as I've discussed earlier in this post, will down-convert incoming RF.

The input signals' spectrum (shown below as two-sided, with negative frequencies, per the frequencies in the complex arguments in the exponential form of the input signal) will shift down:

(Click on image to enlarge)

The illustration below shows a more general case for a band of frequencies at the DDC's input:

(Click on image to enlarge)

Note that, unlike the analog mixer described at the start of this post, this spectrum has both positive and negative frequencies.  In other words, we do not (yet) have an issue with "image wrapping" while we remain in the complex domain.

Another take on the same topic, from "Complex Signal Processing is Not -- Complex," by Ken Martin, showing the same:

Note (again) that the input consists of only real, not complex, numbers, but the output Y(t) will be in complex form, with both real and imaginary components.

Regarding the mixer (c) in the image above, we can express its two outputs (yr(t) and yq(t)) in terms of sines and cosines.

First, for simplicity of analysis let's define the input xr(t) to be a simple cosine at frequency ωr:

x(t) = cos(ωrt)

Noting that the oscillator frequency is ωi in this example, the output yr(t) is therefore:

yr(t) = cos(ωrt)*cos(ωit)

which, using trig identities, expands to:

yr(t) = cos((ωr−ωi)t)/2 + cos((ωri)t)/2

Now let's do the same to derive yq(t), the imaginary term...noting that −sin(ωit) = sin(−ωit), yq(t) becomes:

yq(t) = sin((ωr−ωi)t)/2 − sin((ωri)t)/2

Is this result equivalent to the result derived (above) using complex-exponential equations?

Essentially, yes it is!

Let's multiply the yq(t) channel by j (i.e. add a phase shift of 90 degrees with, say, a Hilbert Transform) and call this output yq(t)' (note the 'prime').  Its equation is:

yq(t)' = jsin((ωr−ωi)t)/2 − jsin((ωri)t)/2

If we then add yr(t) and yq(t)', the result is:

yr(t) + yq(t)' = [cos((ωr−ωi)t) + jsin((ωr−ωi)t)]/2 + [cos((ωri)t)  jsin((ωri)t)]/2

Which, from Euler's Formula, we know is exactly equivalent to:

yr(t) + yq(t)' = (ej(ωr−ωi)t + ej(−ωr−ωi)t)/2.

and which is exactly equivalent in form to the equation we derived earlier:

y(t) = (ej(ωi−ωo)t + ej(−ωi−ωo)t)/2

In other words, the trigonometric signals representing yr(t) and yq(t) are the fundamental mathematical elements (when the sine terms are multiplied by j) that constitute the Digital Mixer's operation when expressed in complex-exponential form.

Links and Other Resources:

Representing a signal as the sum of two exponentials:  http://ece.mst.edu/media/academic/ece/documents/classexp/ee216labs/EE216_Lab4.pdf

The Significance of Negative Frequencies in Spectrum Analysis, Robert Marcus, IEEE Transactions on Electromagnetic Compatibility, Dec. 1967.  (A copy can be found here).

Good tutorial on Complex Number in Radio applications:  Complex Signal Processing is Not -- Complex, Ken Martin

Standard Caveat:

I could have easily made a mistake in any of the above text, equations, or drawings.  If something looks wrong or is confusing, please feel free to contact me.  Thanks!

## Tuesday, October 11, 2016

### More Notes on Directional Couplers for HF -- The Twin-Lead "Twin-Lamp" SWR Indicator

The Twin-Lead "Twin-Lamp," by W4HVV

At a recent swapmeet someone asked me how the venerable dual light-bulb "twin-lead" SWR indicator worked.  Although I was familiar with the device, I hadn't looked into its theory of operation, and so I said that it was probably similar to the Monimatch (described here) because, even though it used a length of twin-lead as its sensing element, that length was very short compared to an HF wavelength and thus it could be analyzed from a "lumped-element" perspective using capacitive and inductive coupling, rather than as a transmission line.

But the question made me curious as to what the analysis would be, and I decided to delve deeper...

The 'Twin-Lead "Twin-Lamp"' SWR indicator was a very simple device designed for use with twin-lead (or open-wire) transmission lines, and it used two inexpensive flashlight bulbs as Forward and Reflected Power indicators.  To my knowledge, it was first mentioned in an article by Charles Wright, W4HVV, in the October, 1947 issue of QST (The "Twin-Lamp" -- you can find a copy of the article here).  It then appeared in later editions of the ARRL's "The Radio Amateur's Handbook (up through 1961), as well as in editions of the "Radio Handbook" published by Editors and Engineers (such as the 13th edition, published in 1951, which I have).

The W4HVV's "Twin-Lamp" SWR Indicator is pictured above.  Below is a sketch of a similar design, for the 13th Edition of the Radio Handbook, published by Editors and Engineers:

In other words, the SWR indicator consists of a short length of twin-lead with two lamps attached to it.  The lamps can be attached at either end, or in the center.

Per W4HVV, the configuration shown above as (A) has greater sensitivity than configuration (B), no doubt due to the direct (rather than capacitive) connection of the top of the detection-loop to the transmission line.

W4HVV does an excellent job explaining the detector's operation, and I've included it below (from the original QST article, via the RF Cafe website).  First, the figures he references:

(Click on image to enlarge)
Figure 1

And here is his explanation (I've added some formatting changes for clarity):

Referring to Fig. 1-A, a current, IL, in the line would induce a current, I1, in a loop near the line, as shown. If the reactance of the loop is small compared to the resistance of the bulbs A and B, the current I1 will lag IL by 90°. This current will, of course, be the same through lamps A and B, and will cause them to burn with equal brightness if they are identical.

Now from Fig. 1-B, we see that bulbs A and B are across the line and in series with a small capacity C. This capacity is, of course, the distributed capacity between the loop and the line. If the reactance of this capacity is large compared to that of A and B the current I2 will flow and will lead the voltage across the line by 90°. If A and B are identical the current will divide equally between them.

Since I1 lags IL. by 90° and I2 leads EL by 90°, it is apparent that if IL and EL are in phase with each other, I1 and I2 will be exactly out of phase.

Fig. 1-C is a combination of the circuits explained above. Condenser C is the capacity between the wires of the loop and the line. Currents I1 and I2 are shown as they appear in Figs. 1-A and 1-B. It is now evident that bulb A will light from the sum of I1 and I2 and bulb B will light from the difference between these two currents. This is the case for a wave traveling toward the right. In the case of a wave traveling toward the left, the currents will add in bulb B and tend to cancel in bulb A. Thus the device is a form of "directional coupler." When the line is terminated on the right-hand side (marked "load" in Fig. 1-C) by a resistance equal to the characteristic impedance of the line, there is no reflected wave and only bulb A will light. If the load is something different, there will be some reflected energy, and lamp B will burn along with A, the relative brilliance depending upon the relative magnitudes of the transmitted and reflected energy. These facts are what make the device so useful as a standing-wave indicator.

In the foregoing discussion, three conditions were set up:
1. bulbs A and B should be identical;
2. the reactance of the loop should be small compared to the impedance of A and B; and
3. the reactance of the coupling capacity should be high compared to the bulb impedance.
To satisfy the first, bulbs of the same characteristics were used, and in the interests of sensitivity, these were 2-volt 60-ma. flashlight bulbs. For the second and third considerations, the length of the coupling loop must be kept short compared to a wavelength. It was found that, for 50-Mc. operation and a transferred power of about 20 watts, a loop length of about 4 inches was a good compromise between sensitivity and the satisfaction of the above conditions. For 28 Mc. it can run a few inches longer, and at 144 Mc. an inch or so shorter. In any event, the length is not critical.

A Closer Look...

Let's dive a bit deeper and see if we can't derive some equations to describe the operation of the "Twin-Lamp".

I'm going to use the principle of Superposition (a fundamental principle in Linear Network Theory and an essential tool for circuit analysis).  I'll first look at how the voltage across the transmission line creates currents in the two lamps of the detector (independent of the current through the transmission line).  I'll then look at how the current through the transmission line (independent of the voltage across the line) creates its own currents in the two lamps.  And then I'll combine these two currents, calculated independently, to get the final aggregate lamp currents.

First, let's consider a twin-lead (or open-wire) transmission line driven by a source at one end and terminated by a load (Zload) at the other end:

If Zload differs from the characteristic impedance of the transmission line (Zo), then there are reflections along the transmission line and, if we were to measure current and voltage at an arbitrary point along the transmission line, we would see an impedance, Zload' (i.e. Zload prime), where the value of Zload' changes as we move along the transmission line, and which only equals Zload at distances equal to integer half-wavelengths as we move away from the load back towards the generator.

(Click on images to enlarge)

So, if we were to measure V and I at the (arbitrary) point shown above, it would appear to us that we had a load of impedance Zload' attached at that point, so that the transmission-line circuit can be modeled now as a much shorter line with a new load, Zload':

where:  Zload' = V/I, measured at that point.

What happens if we put our "Twin-Lamp" SWR indicator at that point, so that it measures the same V and I that creates Zload?  (Remember, the length of the Twin-Lamp detector should be significantly shorter than the wavelength of the signal being measured to ensure that the I and V it measures are essentially the same as those at Zload' ).

(Click on image to enlarge)

First, let's look at the currents through the lamps due to the voltage across the transmission line (Ilamp-C).  We can consider the bulbs to be capacitively coupled to the transmission line and, if the bulbs have identical impedances, then the currents through them will be equal and in the same direction:

(Click on image to enlarge)

The circuit is a simple voltage divider, and thus the current Ic is equal to the voltage across the line at that point divided by the sum of the series-impedances across that point:

Ic = V/(1/jωC + (Rlamp || Rlamp)+ 1/jωC)

Ic = V/(Rlamp/2 + 2/jωC)

if (2/jωC) >> (Rlamp/2) -- per W4HVV's third condition, above (that is, if the capacitive reactance is much greater than the lamp resistance), then the equation reduces to:

Ic = V*jωC/2

Assuming the impedances of the two lamps are identical, then Ic splits equally through each lamp branch:

Ilamp-C = Ic/2 = V*jωC/4

Now let's look at our second lamp-current factor: lamp current due to transmission-line current (Ilamp-L).  The transmission-line current inductively couples to the detector loop:

(Click on image to enlarge)

If the reactance of the mutual coupling is very small compared to the bulb resistances (per W4HVV's second condition, above), then this coupling can be modeled as two voltage sources (refer to this post as to why):

(Click on image to enlarge)

The lamp current due to inductive coupling, Ilamp-L is simply the current in the detector's loop, and it can be derived as follows:

Ilamp-L = Vinduced/(Rlamp +  Rlamp)

therefore,

Ilamp-L = 2*jωM*I/(2*Rlamp)

substituting V/Zload' for I and reducing,

So, we've calculated the currents due to capacitive coupling and due to inductive coupling.  Now let's combine them and calculate the voltage across each lamp:

(Click on image to enlarge)

Notice that the two current-components through lamp-F are in the same direction.  Therefore they add, and the voltage across this lamp can be calculated as:

Vlamp-F = (Ilamp-C + Ilamp-L)*Rlamp

But the current-components through lamp-R are in opposite directions and therefore subtract.  The voltage across this lamp can be calculated as:

Vlamp-R = (Ilamp-C - Ilamp-L)*Rlamp

If the transmission-line is properly terminated in a load equal to the line's characteristic impedance Zo, then the SWR should be 1:1 and lamp-R should be extinguished -- the voltage across it should be zero.  Therefore, substituting Zo for Zload' and setting Vlamp-R to 0 volts, our last equation becomes:

0 = (Ilamp-C - Ilamp-L)*Rlamp

0 = (V*jωC/4 - jωM*V/(Rlamp*Zo))*Rlamp

Which reduces to:

0 = C/4 - M/(Rlamp*Zo

This last equation gives us the relationship we need to design the appropriate values of capacitive and inductive coupling between the "Twin-Lamp" detector and the transmission line:

4*M/C = Rlamp*Z

Note the similarity between this equation and the equation derived for the monimatch:

M/C = R1*Zo

Other notes:

The analysis above (and W4HVV's conditions) assume that the resistance of the two bulbs is identical.  But a bulb's resistance should increase as its filament heats up, so there will be a difference in the resistances of an illuminated "Forward" lamp compared to a dark "Reflected" lamp.  This difference shouldn't affect the capacitive coupling currents (as long as the capacitive reactance is significantly greater than the "hot-filament" resistance), but it will affect the current due to inductive coupling.  In this case (of unequal lamp resistances), Ilamp-L becomes:

Ilamp-L = 2*jωM*V/((Rlamp-F + Rlamp-R)*Zload')

and thus the final equation changes to:

8*M/C = (Rlamp-F + Rlamp-R )*Z

How will this difference affect the actual SWR reading?  I don't know.

As for the other conditions mentioned by W4HVV, if this device's length is kept short, then the overall capacitive coupling should be fairly small, and W4HVV's third condition of capacitive reactance being significantly larger than lamp resistance should be met.

As for W4HVV's second condition, that loop-reactance should be kept small compared to the reactance of the bulbs, I'm not sure how well this condition is met in this design, but as long as the "Reflected" bulb is dark when the line is terminated with a resistance equal to the line's characteristic impedance, Zo, I wouldn't worry too much -- after all, this device is not meant to be a laboratory-grade instrument!

And when verifying the operation of this type of SWR Indicator by terminating the transmission line with a resistive (non-inductive) load whose value equals the transmission line's characteristic impedance, Zo, (to ensure that the "Reflected" bulb is dark under "match" conditions), note that the actual Zo of twin-lead or ladder-line might differ from its assumed value.  For example, 450-ohm ladder-line might be closer to 400 ohms.

But, as W4HVV points out, his "Reflected" bulb typically did not begin to light up until SWR was at least 1.5:1, which represents a significantly larger difference in impedances than 400 ohms compared to 450 ohms.

OK, that's it for this analysis!

Some Twin-Lead SWR Indicator articles:

The "Twin-Lamp," Wright, W4HVV, QST, Oct., 1947

"The Eyes Have It," Paddon, VE3QV, QST, Oct., 1948

"The Coax Twin-Lamp," Keay, W0SJK, QST, Nov., 1948

"An Improved Twin-Lamp", Fisher, VE3ALQ, QST, Oct., 1949

"Measuring Center Impedance of Antennas with the "Twin-Lamp," Gross, W2OXR, QST, May, 1950

"The Balanced Twin-Lamp," Wood, K2BUZ, QST, Nov., 1956

"A Reflectometer for Twin-Lead," Brown, W6HPH, QST, Oct., 1980

Links to my Directional Coupler blog posts:

Notes on the Bruene Coupler, Part 2

Notes on the Bruene Coupler, Part 1

Notes on HF Directional Couplers

Building an HF Directional Coupler

Notes on the Bird Wattmeter

Notes on the Monimatch

Notes on the Twin-lead "Twin-Lamp" SWR Indicator

Calculating Flux Density in Tandem-Match Transformers

And some related links from my Auto-Tuner posts:

Part 5:  Directional Coupler Design

Part 6:  Notes on Match Detection

Part 8:  The Build, Phase 2 (Integration of Match Detection)