Category: Electronics

Debugging poor home wifi at the Snell-Pym residence (by )

So, we have a fairly complicated network at home - the Snell-Pym Family Mainframe has a dedicated DSL link with a static IP for hosting various Internet-facing things, as well as providing internal services to the home LAN. The home LAN has the usual mix of desktop computers, the laser printer, and two wireless APs for mobile devices to connect to - one in the house and one in the workshop, because one can't get a good signal to both locations. And there's a separate infrastructure LAN for systems control and monitoring.

Now, we've often had on-and-off poor connectivity on the wifi in the house; this used to happen sporadically, usually for around a day, then just get better. The wifi signal strength would remain good, but packet loss was high (10-20%) so stuff just didn't work very well. TCP is poor at high packet loss; it's OK once a connection is open, but packet loss during the initial SYN/SYNACK/ACK handshake causes it to take a long time to retry on most implementations.

I went looking for interfering networks (we live in a pretty wifi-dense urban area) using an app called "Wifi Analyzer" on my Android phone, and it showed a strange network, always on the same channel as the house wifi (as in, if I changed the channel, it would move too). The network never had a name, and the signal strength was about the same as the house wifi; sometimes a bit stronger, sometimes a bit weaker. Read more »

12v DC Power Distribution (by )

What with not needing to spend quite so much of my time driving my family to places these days, I've been catching up on household maintenance, DIY, and vehicle maintenance tasks, and one of those has been to finish a 12v DC power distribution unit (PDU).

Why do I need such a thing? Well, our van has an auxiliary power system - a pair of large lead-acid batteries in the back that are charged from the engine while it's running, which then power internal and external lights, a microwave oven, a mobile amateur VHF/UHF band transceiver, and things like that.

This is useful compared to just running from the vehicle starter battery for three reasons:

  1. While the starter battery is optimised for brief, intense, surges of current to start an engine, the auxiliary battery pack is optimised for energy storage so can store a lot more energy more efficiently.
  2. If I leave things on and run the auxiliary batteries flat, I can still start the engine from the starter battery (and thus recharge the auxiliary batteries).
  3. I can mumble things like "Switching to auxiliary power" and pretend I'm piloting a spaceship.

However, the auxiliary power system was installed in the van's original life as a work crew support vehicle, so it was hardwired to a few appliances and the lights. Somebody who owned it since had attached a set of four "ligher sockets" - perhaps the nastiest 12v accessory socket in common use to a fuse marked as "spare" in the fusebox. But I ripped that out and used the "spare" circuit to run the transceiver instead. On the other hand, where the van had originally had a hot water system for making hot drinks that was removed before it came into our hands, a 50A fused circuit terminated in a large SB50 Anderson connector.

I had nothing that would plug into such a socket, but did want to plug in things such as:

  • Chargers for various kinds of batteries I use
  • USB sockets for charging phones
  • An inverter to run things I don't have DC power supplies for
  • Amateur radio equipment (which usually runs at 12v from 30A Anderson Powerpole connectors)

So the solution was obvious: Make a Thing that plugs into the 50A socket, and then itself has lots of different sockets on so I can plug stuff in. Desirable extra features are:

  • Individually fusing all those outputs, as if most of them pulled 50A in a short circuit (which the upstream circuit can provide) it probably wouldn't end well.
  • Integral voltmeter so I can check the battery status.
  • Usable in other off-grid power situations as well.
  • A commonning point for RF grounds for antennas and ground stakes and stuff for radio gear.

The design

So I settled on the following design:

  • SB50 connector on the end of a few metres of nice flexible 8AWG silicone-insulated cable, to plug into the van.
  • Incoming +ve splits into an eight-way blade fuse box I had lying around
  • Two lighter sockets, for legacy devices.
  • A panel-mounting 12v-fed USB charger, with two outlets (with a power switch, as it draws a tiny idle current even when not in use).
  • A voltmeter, powered through a pushbutton so it's not draining the battery when not in use (I ran this from the same fuse as the USB charger).
  • A set of binding posts, for attaching arbitrary wires or banana plugs (also useful as a power INLET by hooking up my bench PSU in the workshop).
  • Four 30A Powerpole sockets.
  • Four banana plug sockets for RF earthing, joined together, with a switch to join them to the -ve DC power line (I can turn it on to bind RF earth to DC -ve at the box, or turn it off to break a ground loop if it's bound elsewhere - basically, just fiddle with the switch and see which produces less noise in the current situation).
  • Every output has a ceramic 100nF filter capacitor in parallel across it, to try and cut down on power line noise.

Then, as the supporting cast:

  • A set of battery clamps hooked up to another SB50 via a 50A fuse (plus a single Powerpole connector on a 20A fuse in parallel so I can plug small stuff in directly) so I can also run the system away from the van, from an old car battery in my possession, or nicer deep-cycle batteries I might own in future.
  • A powerpole connector with a 5A fuse hooked up to a little 1.2Ah sealed lead acid battery I happened to have lying around, so I can run the system away from the van without lugging a huge battery around at all, for small loads only.

Building it

Electrically, the system is dead simple. But mechanically, fitting it all in the box and making it sturdy enough to survive camping trips was challenging.

  • Cables capable of carrying 50A without a problem are bulky
  • I didn't have panel-mount Powerpole connectors, so needed to improvise.
  • The fuse box I had just had spade terminals for each end of each fuse, without a common busbar.
  • The fuse box was meant for mounting to a bulkhead; I wanted the fuses to be accessible from outside the box, while keeping all the spade terminals inside the box so no live stuff was easily pokable.

I dealt with the latter point by cutting a rectangular hole in the front panel so that fuses could stick up, while the electrical connections where beneath the front panel. Long screws through the front panel went down through the mounting holes on the fuse box that should have mounted it to a bulkhead, and a nut on either side of the mounting flange held the fuse box in place at a fixed distance behind the front panel so the fuses stuck out enough to be easily accessed, while the spade terminals were kept amply away from the front panel. I covered the back of it in insulating tape, just in case.

To common the positive connection in, I crimped a massive ring terminal onto the incoming positive wire (I had to buy a special massive hex crimper to do this!), and bolted it to a strip of thick copper I cut to size. I drilled eight holes in it such that I could pull the insulation off of eight female spade terminals and solder them into the holes, then press the entire strip onto the spade terminals along the top of the fuse box, thereby commoning them. Lots of insulating tape and heat shrink then covered all the live (and directly connected to the 50A incoming circuit) parts.

For the Powerpole connectors, I 3D printed some mounting places with suitably sized rectangles, then used them as a guide to cut slightly larger holes in the metal case. I had PCB-mounting powerpoles connectors, which I soldered the filter caps directly onto the backs of, then soldered the negative lines together to common them. Wires were soldered onto the common negative and individual positive lines, and protected with heat-shrink.

I then poked the connectors into the holes (they were a push fit) and used generous gobs of Sugru to protect them against being pulled out or - worse - pushed in. Since Sugru is slightly flexible, I increased the rigidity of the setup by using a length of thick steel TIG welding wire across the backs of all the connectors, embedded in the sugru (and electrically isolated from everything).

I couldn't easily fit filter caps onto the lighter sockets and the USB charger, as they used crimped spade terminals, so I made a bank of filter capacitors fitted to a screw terminal block on the front panel. I glued it in place with epoxy.

Here's a shot of the interior partway through construction, to give you an idea:

12v PDU internals

I put in 15A fuses for the lighter sockets, a 3A fuse for the USB and voltmeter, 10A for the binding posts, and a range of fuses for the powerpoles - 10A, 10A, 20A and 30A.

Finally, to document what each fuse drives, I put a simple schematic of the circuit on the outside - by drawing lines with a permanent marker from each fuse to its load (going via the switch in the case of the USB outlet).

The finished product

Once all those fiddly details had been addressed, and many many crimp connections made, I was delighted to find that the box would close with only gentle pressure!

I carefully tested it for short circuits with a meter and, none found, gingerly plugged it into my bench PSU through the binding posts on the front and crept the current limit up from zero... it didn't explode!

So, I plugged the small sealed lead-acid battery into a Powerpole socket and tested the internal voltmeter:

Testing the internal voltmeter

It doesn't show so well in the nice sunlight we've been having, but that's registering a healthy 12.79v. And not catching fire or exploding.

Next, I plugged it into the car battery using the big SB50 plug, and checked the voltage with my multimeter on the binding posts:

Big battery and DMM

Also all good. Finally, I plugged a USB voltmeter into a USB outlet and turned on the outlet:

USB 5v works nicely

(And, of course, I checked every outlet with the multimeter to make sure everthing was connected properly and all of my fuses were good).

So, with testing complete, it was time to put it to work. I was due to check the tyre pressures on the van, so I plugged the SB50 into that auxiliary power socket that started this whole adventure, and plugged my tyre compressor thingy into a lighter socket, and did all the tyres - after quickly checking how the auxiliary batteries were doing, as I'd not driven the van in weeks:

Active in the van

The pump actually draws eight amps according to the label on the underneath, so this was a test of the system under non-trivial current. It still didn't catch fire.

Things I'd do differently

  • Use proper powerpole panel mounting outlets. Doing it myself was skanky.
  • Put a handle on the thing. As the surface is so covered in sockets and things, it's not actually easy to hold it. Fine when it's sat on a surface, which is what I designed for, but carrying it around feels ungainly.

What next?

I've already got a 240v AC inverter and various chargers with Powerpole connectors, but I want a few more Powerpole accessories:

  • Lighting strips on hooks, so I can set this up inside a tent and light the tent (while also charging all my batteries). I've ordered some cheap 12v LED light strips; I'll put cables with Powerpole connectors on them.
  • A plugtop 12v mains PSU, so I can run this lot from a wall socket easily (for small loads).
  • A DC-DC 12v battery charger, so I can charge my car battery and my little sealed battery from the van's auxiliary power system (just wiring 12v batteries to each other isn't a good way of charging them...) or, in an emergency, charge the van's starter battery from the auxiliary power system.
  • A portable solar powered 12v battery charger for free, clean, energy.
  • A boost-converter DC power supply for my laptop, so I can run it without the wasteful step of running an inverter to generate 240v AC for my laptop charger to drop back down to 18v DC.

Our radio adventures (by )

My last post was about amateur radio in general, but for those of you who are interested, here's a summary of where we're at and where we're heading.

Jean and I did the Foundation Licence course together and passed, so we have UK Foundation licences. That means we can transmit in nearly every amateur frequency allocation, covering the HF, VHF, UHF and microwave bands discussed in my blog post. We're limited to ten watts of output power (details vary slightly in some bands), which is enough to do most things: at that power level you can communicate over intercontinental distances on HF, especially using Morse or data modes. I'd like to progress to the higher levels of licence, not so much for the increased power levels (although those might be handy), but because at Intermediate level you can use transmitters you have built yourself; and at the Full level, you can operate outside of the UK (as that level of licence meets the requirements of international radio law).

What we've done so far:

  • Obtained FM VHF/UHF handhelds - the ubiquitous Baofeng UV-5Rs - and experimented with external accessories for them; we have a magmount antenna on the car and a UV-5R hooked up to the 12v socket in the car and a fist make, as a cheap mobile rig, and various different headsets, antennas, and pouches to find comfy ways to wear the things out and about.
  • I've tinkered with antenna construction; I built a quarter-wavelength vertical with a radials, hinged so it collapses down flat, for the VHF amateur band. It seems to work pretty well.
  • Chatted to each other on the handhelds. We've done some experiments for the sake of it around town, and used them to usefully keep in touch at a couple of outdoor events.
  • I've played with APRS a bit. I didn't explain that in my last blog post: it's a protocol for announcing position and basic status information in digital data packets over the radio, meaning you can track the positions of other stations near you.
  • Chatted to each other on a local repeater, as an experiment. (Repeaters are set up by volunteers on tall masts so they have a good view of a lot of the local area, and re-broadcast your signal for you, so that two people down on the ground amongst buildings and obstructions can still talk to each other).
  • I've joined in some conversations with strangers on the local repeaters, but it's still a bit nerve-wracking doing so!
  • I've done some experiments with building simple HF antennas and hooking them up to a wide-band receiver I already have, and picked up a few signals - but mainly noise at home.

Things we're interested in doing include:

  • Volunteering with the local RAYNET group, to get some practice in doing useful things with short-range comms (VHF and UHF). In particular, we both want to gain experience with radio etiquette and build up confidence.
  • Talking to the International Space Station, which our licences allow - we have all the required equipment apart from a more directional antenna! We'll probably start with relaying digital data from the ISS digipeater as it doesn't rely on an astronaut being around to say hi.
  • Talking to amateur satellites; requires the same equipment as the ISS, but involves talking to other people on the ground. This will be fun because (a) SPACESHIP!!!! and (b) you get to talk to people much further away.
  • Getting onto HF! Our home isn't great for an HF antenna installation, from my experiments, so I'm interested in "portable operation". This looks fun - there are contests such as SOTA based around making contacts from hilltops and mountaintops, or IOTA for making contacts from islands - and I like the flexibility of being able to set up anywhere.
  • Getting a VHF/UHF antenna on the roof at home, with a base station transceiver. I'd like to be able to sit at my desk and monitor the local repeater, for instance, so that Jean can get in touch with me while she's out and about. Access to our chimney is tricky and my desk is in the workshop which is at the other end of the garden to the house (requiring a long cable or an expensive remote-controlled transceiver), so I might need to build a small mast on top of the workshop: the signal might be good enough for the repeater, at least, and making a truss mast out of aluminium would be a fun welding project.
  • Maybe build a "magnetic loop" HF antenna on the workshop roof; those are supposed to get better results in circumstances such as mine. Experiments must be done!
  • We both want to learn Morse; this opens up the ability to make longer-distance contacts with smaller, cheaper, transmitters, and is kinda fun in its own right.

Amateur radio (by )

The radio spectrum is a complicated and varied thing.

Although some people seem to separate "radio" from "microwaves", I tend to lump them together, so I'm going to consider "the radio spectrum" to be the section of the electromagnetic spectrum from the very lowest frequencies we can usefully use (a few Hertz) up to frequencies that we'd start to count as "infrared light" (several terahertz).

Those bounds are based on practicality - for very low frequencies, the antennas required to efficiently transmit become impractically large and the bandwidth available to communicate gets ridiculously low; at very high frequencies, our electronics cannot process the signals and we have to switch to optical methods, which is a whole different ballgame.

I'm going to give you a whirlwind tour of the radio spectrum - but with an agenda: I'm just setting the scene so I can talk to you about amateur radio... Read more »

Mind your Is and Qs: The Art of Frequency-Division Multiplexing (by )

As previously discussed, I've been learning about radio lately. As part of that, I've been diving into things I've always found confusing in the past and trying to properly understand them; when I succeed at this, I'd like to share what I've found, hopefully clarifying things that aren't explained so well elsewhere and helping others in the same situation I was in...

I'm going to start by explaining some pretty basic stuff about waves, which most of yuo will already know, but bear with me - I'm trying to emphasise certain things (phase!) that are often glossed over a bit at that level, and cause confusion later.

Today, we're going to talk about modulation. To be specific, frequency-division multiplexing: the technique of sharing some communication medium between lots of channels by putting them on different frequencies.

This is used to great effect in the radio spectrum, where the shared medium is the electromagnetic field permeating all of space; but it applies just as well to any medium capable of carrying waves between a bunch of transmitters and receivers. The media vary somewhat in how signals at different frequencies propogate, and what background noise exists, and what hardware you need to interface to them, but the principle remains the same. Examples other than radio include:

  • Ripples on a lake
  • Electrical impulses in a coaxial cable connecting multiple stations (old Ethernet, cable TV)
  • Noises in air

The key thing about these media is that if a transmitter emits a wave into them, then that wave (subject to propogation distortions) plus some ever-present background noise will arrive at a receiver. So if we can find a way for everyone to communicate using waves, without messing up each other's communications, we're good. It doesn't matter that impulses in a cable travel along one dimension, ripples on a lake travel in two, and noises (or radio waves) in air travel in three: as we're usually thinking about a wave coming from a transmitter to a receiver, we can just think about the one-dimensional case all the time. That's enough for communication - more dimensions are involved when we use waves to find our position (GPS!), but that's not what we're talking about here.

Waves

Waves can be all sorts of shapes: square waves with sharp transitions between two levels, triangular waves that go up smoothly then turn around and go down smoothly, and then turn around again and go back up, between two levels; complex wiggly waves that go all over the place... but, it turns out, all of those wave shapes can be made by adding up a bunch of smoothly curving sinusoidal waves.

Such a wave is "periodic": it's the same pattern, repeated again and again, each repitition identical to the last. Each repitition of the pattern is called a "cycle"; as that word suggests, the origin of sinusoidal waves is in the geometry of circles - we don't need to go into that properly here, but what we do need to know is that each full cycle of the wave corresponds to going around a circle, and as such, we can talk about how far along the cycle we are in terms of the circular angle covered. A full cycle is 360 degrees. Half of it is 180 degrees; since the wave goes from the middle, to a peak, to the middle, to a trough, to the middle again before repeating, 180 degrees is enough to get you from the middle on the wave to another, with a single peak or trough inbetween; or to get you from a peak to the next trough. 90 degrees gets you from where the wave crosses the middle to the next peak or trough, or from a peak or trough to the next middle-crossing.

Those waves can be described entirely by three numbers:

  • Amplitude: How big the waves are. This can be measured from trough to peak, or can be measured in terms of how far the troughs and peaks deviate from the middle - the difference is just a factor of 2, as they're symmetrical.
  • Frequency / Wavelength: The frequency is how many complete cycles of the wave (measured, say, from peak to peak) pass a fixed point (such as a receiver) per second. As all waves in our media travel at the same speed, this means that you can also measure the same thing with the wavelength - how much physical distance, in metres, a complete cycle of the wave takes up. The frequency is in Hertz, which means "per second"; the wavelength is in metres; and multiplying the frequency by the wavelength always gives you a speed (in metres per second), that being the speed of wave propogation. In empty space, radio waves travel at the speed of light (because light is a radio wave, in effect): about 300,000,000 metres per second.
  • Phase: This is a trickier one, and often neglected. Unlike the other two, which are things you could unambiguously measure at any point on the wave and get the same answer, "phase" is relative to an observer. Imagine two waves are coming at you from different sources, with the same amplitude and frequency - but the peaks of wave A arrive slightly before the peaks of wave B. Remembering how each cycle of the wave can be considered as a 360 degree rotation, we might say that wave B is lagging 90 degrees behind A, if B's peak arrives when A is just crossing the middle after a peak.

So, unlike amplitude and frequency/wavelength, phase is always a relative measure between two waves, or perhaps between a wave and itself somewhere else: if a transmitter is emitting a wave and we're receiving it from a thousand metres away, because it takes time for that wave to travel, we will be seeing it phase-shifted compare to what the transmitter is emitting at that point in time. The size of the phase shift depends on the wavelength; if the wavelength is a thousand metres, then an entire cycle fits between us and the transmitter, so we'll get a 360 degree phase shift - but since the every cycle is identical, we won't be able to tell and it will look the same as a 0 degree phase shift. However, if the wavelength is two thousand metres, we'll be exactly half a cycle behind the transmitter, and we'll see a 180 degree phase shift.

(In order to try and innoculate my children against getting confused about phase when they learn about it at school, I have always referred to the situation when they're buttoning their clothes up and find that they've been putting button N into buttonhole N+1 or N-1 as a "phase error".)

The fact that the wave repeats exactly after a cycle is important: it means that phase shifts will always be somewhere between 0 and 360 degrees (for periodic waves, at least); but by measuring it a bit differently, you could also measure phases between -180 and +180 degrees, with negative numbers indicating that the wave is lagging behind the reference, rather than counting that as being nearly 360 degrees towards the next cycle.

Another important thing is that, for two waves of the same frequency, the phase difference between them is the same if the two waves travel along together in the same direction. That makes sense, as they travel at the same speed. But what about waves of different frequency? At some points, the two waves will briefly overlap perfectly, perhaps both peaking at the same time, or perhaps some other arbitrary point in the cycle - at that point, they have a zero phase difference. But even a microsecond later, the higher-frequency wave will be slightly further ahead in its cycle than the lower-frequency wave: the phase difference steadily increases until the higher-frequency wave sneaking ahead in the number of cycles it's covered, until finally, it gets an integer number of cycles ahead of the lower-frequency wave - and the phase difference is back at zero. The phase difference between two waves of different frequency therefore constantly changes, linearly (changing by the same amount every meter travelled), but wrapping around to always be between 0 and 360, or -180 and 180, depending on how you measure it. And the rate of change of phase depends on the frequency difference.

But let's put thinking about phase on the back burner for a moment and talk about the most basic way of sharing a communications medium: Continuous Wave (CW) modulation.

Continous Wave (CW)

In this scheme, a bunch of different transmitters can share a medium by using different frequencies - and choosing to either transmit on that frequency, or not. Receivers can look for waves with the frequency of the transmitter they're interested in, and either see a wave, or not.

We can use that to communication a very simple fact, such as "I am hungry": transmit when hungry, switch off when fed. This is used to good effect by babies in the "noises in air" medium (yes, parents can pick out their own baby in a room of crying babies, by the frequency). It can also be used to communicate arbitrarily complex stuff, by using it to transmit serial data using RS-232 framing; or by using short and long pulses to transmit a code such as Morse.

So how close together can be pack different CW channels? Can we have one transmitter on 1,000 Hz and another on 1,001 Hz? Well, not practically, no. A receiver needs to listen for a mixture of signals coming in, and work out if the frequency it's looking for is in there, to tell if the transmitter is on or off right now. As it happens, the techniques for doing this all boil down to ways of asking "In a given time period, how much total amplitude of wave was received between these two frequencies?"; and the boundaries of the two frequencies are always slightly fuzzy too - a signal just below the bottom frequency will still register a bit, albeit weakly.

If you are doing very fast CW, turning on and off rapdily to send lots of pulses per second because you have a lot to say, you'll need to use very small time periods in your receiver, so you get the start and stop of each pulse accurately enough to tell if it's a short or long pulse, and to avoid multiple pulses going into a single time period.

If you have lots of channels close together, you'll need a very narrow range of frequencies you look between. The width of that range of frequencies is known as the "bandwidth"; us computery people think of bandwidth in bits per second, the capacity of a communications link, but the reason we call that "bandwidth" is because it's fundamentally constrained by the actual width of a frequency band used to encode that binary data stream!

If you do both, then the amount of total amplitude you'll spot in your narrow frequency band and your short time period will be very low when the transmitter is transmitting - and it will get harder and harder to distinguish it from the background noise you receive even when nothing is transmitting.

So: Yes, you can have very close-spaced channels - if the noise level is low enough and your CW pulses are slow enough that you can have a long enough time period in your receiver, to get reliable detection of your pulses. But it's always a tradeoff between pulse speed, how wide your frequency band is, background noise levels, and how often your receiver will be confused by noise and get it wrong.

You might think "Wait a minute, that's silly. If the transmitter emits a sinusoidal wave and that turns up at the receiver, you can simply measure the wavelength and frequency; and if you start a clock ticking at the same frequency you can even detect any sudden changes in phase in the wave. How is that in any way fuzzy or unclear?"; but that doesn't scale to when your receiver is picking up the sum of a load of different waves. If there's two waves of very different frequency then it's easy to tell them apart, but if they're of very similar frequency it's another matter entirely.

Amplitude Modulation (AM)

Sometimes we want to send something more complicated than just an on/off signal. Often, we want to send voices, or pictures - both of which can be encoded into a single-dimensional signal: a quantity that varies with time, such as the voltage encountered on a microphone (pictures get a little more involved, but let's not worry about that right now). Rather than just turning our transmitter on and off, we could vary the amplitude of the signal it sends along a spectrum, and thus communicate a varying signal.

Of course, this only works if the signal we're sending (known as the "baseband signal") has a maximum frequency well beneath that of the frequency we're transmitting at (the "carrier frequency"); the same limits as with turning a CW transmitter on and off quickly apply - your carrier wave needs to complete at least a few cycles for its amplitude to be reliably measured, before it changes.

Because you're changing the amplitude of the carrier to convey the baseband signal, this is known as "amplitude modulation", or AM. You can think of it as multiplying the baseband signal with the carrier signal and transmitting the result.

Of course, this operation is symmetrical - the result of sending a 10kHz sine wave baseband on a 1MHz carrier is the same as sending a 1MHz baseband signal on a 10kHz carrier - but we agreed to only do this when the maximum baseband frequency is well below the carrier frequency, so we always know which way round it goes!

By convention, let's treat our baseband signals as being between -1 and +1; our carrier signal is generated at the power level we want to transmit at, so if the baseband signal is 1 we're just transmitting at full power, and if the baseband signal is 0, we're not transmitting anything.

Indeed, continuous wave is just a special case of AM, where the baseband signal is either a train of rectangular pulses, switching at will between 0 and 1.

Now, we mentioned that we need to place CW frequencies a little way apart, because otherwise a receiver couldn't distinguish them reliably - and the distance apart depended, amongst other things, on how quickly the CW signal turned on and off. This of course applies to general AM signals, too: the rate at which they turn on and off, in the general case, being replaced by the maximum frequency in the baseband signal. The higher the frequencies, the further apart your carrier frequencies need to be before the multiple signals interfere with each other.

But... what does that really look like?

Imagine you have a receiver configured with a very narrow input bandwidth; one intended for receiving slow Morse CW might have a bandwidth of 500Hz or so. What would you pick up if you tuned it to the frequency of an AM transmitter? What if you went a bit above or a bit below?

Clearly, if the transmitter was just transmitting a constant level, that's what you'd pick up - which is easy to think about if it's transmitting zero (you receive nothing) or some positive quantity. Of course, if the receiver doesn't know what the maximum amplitude of the transmitter is, it will have no way of knowing if a signal it receives at any given level is 100% of the transmitter power, or merely 10% of it - so it's kind of hard to say what the level means, unless it's zero. More annoyingly, if the transmitter transmits -1, then what we'll get is the full carrier power but inverted. As that inversion swaps peaks for troughs and leaves the middles the same, this is the same as a 180 degree phase shift; the only way to tell it apart from transmitting +1 is to have observed the signal when it's transmitting something positive, and started a clock ticking at the carrier frequency, so we can notice that we're now receiving peaks when we would normally have been receiving troughs.

It's certainly possible to make this kind of thing work: you have to periodically transmit a reference signal, say +1 for a specified time period, so that receivers can wait for that "synchronisation pulse" and therefore learn the phase and maximum amplitude of the signal, and then compare that against the signal received going forward.

But a more common convention is to avoid negative baseband signals entirely. Squash the baseband input range of -1 to +1 up into 0 to 1, by adding 1 and then dividing by 2. This means that a baseband input of 0 maps to a signal transmitting the carrier at half power; a baseband input of +1 maps to full carrier power; and a baseband input of -1 maps to zero carrier power. That avoids the problems of identifying negative baseband signals, but seemingly still leaves the problem of working out what the actual transmit power is... However, if we're not transmitting constant baseband amplitudes, but are instead transmitting an interesting baseband signal, that wiggles up and down around zero with approximate symmetry, then the average signal power we receive will be half of the peak carrier power. Tada!

But, our narrow-bandwidth CW receiver can't pick that up, because it will be changing too rapidly for it. So what WILL it pick up? I'm afraid we're going to need to break out some maths...

As we mentioned earlier, any wave can be made by adding up a bunch of sinuusoidal waves, with varying amplitudes, frequencies, and phases (relative to what, though, as phase is always relative? Well, don't worry too much abut that for now, we'll get into it when I talk about Fourier transforms in a future post). If we can work out what our receiver will pick up when we transmit a single sinusoidal wave as our baseband signal, we can easily work out what it will receive when we transmit a complex signal - because if our baseband signal is the sum of a load of sinusoidal waves A+B+C+D, and we multiply that by a carrier signal X and transmit X(A+B+C+D), that's the same as XA + XB + XC + X*D: in other words, if we amplitude-modulate the sum of a number of baseband signals, the transmitted signal is just the sum of the transmited signals we'd get if we'd modulated each of the baseband signals separately.

So, let's just think about how a single sine wave gets modulated. Let's do that by introducing the sine function, sin(x), whose value is the instantenous amplitude of a sinusoidal wave (with amplitude 2 from peak to trough, or 1 from middle to peak) as x moves from 0 to T. T is 360 if you're working in degrees; people doing this properly prefer to use a quantity that's two times pi (because they're working in radians), but we'll just call the unit of a full circle T and let you use whatever units you like.

So if we want a sinusoidal wave of amplitude A (from middle to peak), frequency F, and phase (relative to some arbitrary starting point) P, then its signal at time t will be:

A * sin(t*F*T + P)

Now, imagine that's our baseband signal (or, to be precise, one sinusoidal component of it). Imagine we have a carrier signal, with amplitude Ac, frequency Fc, and carrier phase Pc, which at time t will be:

Ac * sin(t*Fc*T + Pc)

If we push the baseband signal up from the -1..+1 range into 0..1, as discussed, and then multiply it by the carrier, our modulated output signal will be:

Ac * sin(t*Fc*T + Pc) * (1 + A * sin(t*F*T + P) / 2)

If you distribute the central multiplication over the brackets on the right, you get:

Ac * sin(t*Fc*T + Pc) + A * Ac * sin(t*Fc*T + Pc) * sin(t*F*T + P) / 2

That has two parts, joined by a +.

The left hand part is just the carrier signal.

The right hand part is more interesting. It's got A*Ac/2 in it: the product of the carrier and baseband amplitudes, divided by two - and it's got this intriguing sin(X)*sin(Y) factor, where X = t*Fc*T + Pc and Y = t*F*T + P. I'll spare you the maths, and tell you now that sin(X)*sin(Y) = sin(X-Y + T/4) / 2 - sin(X+Y + T/4) / 2.

Now, X-Y+T/4 is (t*Fc*T+Pc) - (t*F*T+P) + T/4, which simplifies to t*T(Fc-F) + Pc - P + T/4, and X+Y+T/4 simplies to t*T(Fc+F) + Pc + P + T/4.

Also, we noticed earlier that inverting a sine wave is the same as a 180 (T/2) phase shift, so we can swap that subtraction by an addition, and adding an extra T/2 phase to the second sin. As the first one already has a + T/4 phase shift let's keep it symmetrical (remember that phases wraps around at T) and turn the second one into a - T/4.

Putting it all back together, our modulated signal is:

Ac * sin(t*Fc*T + Pc) + A * Ac * sin(t*T(Fc-F) + Pc - P + T/4) / 4 + A * Ac * sin(t*T(Fc+F) + Pc + P - T/4) / 4`

So we have three sinusoidal signals added together.

  1. The carrier, unchanged: amplitude Ac, frequency Fc, phase Pc.
  2. A signal with amplitude A * Ac / 4, frequency Fc-F, and phase Pc - P + T/4.
  3. A signal with amplitude A * Ac / 4, frequency Fc+F, and phase Pc + P - T/4.

Unless F, the baseband frequency, is very low, our narrow-bandwidth receiver tuned to the carrier frequency Fc will only pick up the first part: the unchanged carrier - it will be seemingly blind to the actual modulation! All the baseband signal ends up on the two other signal components, whose frequencies are above and below the carrier frequency by the baseband frequency. If we tune our receiver up and down around the carrier frequency, we'll pick up these two copies of the baseband signal, phase shifted and with quartered amplitude.

These two copies of the baseband signals are known as "sidebands". The first one, with frequency equal to the carrier frequency minus the baseband frequency, is the "lower sideband"; the other, with frequency equal to the carrier frequency plus the baseband frequency, is the "upper sideband".

You'll note that the phases of the two sideband signals, relative to the carrier phase (so subtract Pc from both) are -P + T/4 and P - T/4. Note that these are the same apart from a factor of -1.

If our baseband signal was a complex mixture of sinusoids, then the modulated signal will be the carrier, plus a "copy" of the baseband signal shifted up in frequency by the carrier frequency, and shifted forward in phase by the carrier phase minus a quarter-cycle; plus a second copy of the baseband signal, shifted up like the first, but then inverted in frequency difference from the carrier, and in phase.

And this tells us how closely we can pack these AM signals - we need a little more than the maximum baseband frequency above and below the carrier frequency, to make space for the two sidebands.

"But wait wait wait, that doesn't make sense," I hear you cry. "Where do these sidebands come from? If I have my transmitter and it has a power knob on it and I turn that power knob up and down, so it emits a sine wave of varying amplitude, there's nothing more complicated going on than a sine wave of varying amplitude. How can you tell me that's actually THREE sine waves?!"

Well, that's a matter of perspective. But if you do the maths and add up three sine waves of equally-spaced frequency with the right phase relationship, you'll get what looks like a single sine wave that varies in amplitude. So when a receiver receives it, it's powerless to "tell the difference". A varying-amplitude sine wave and the sum of those three constant-amplitude sine waves are exactly the same thing.

And that's how amplitude modulation works. When you listen to an AM radio, you're listening to an audio frequency signal (converted from vibrations in the air into an electronic signal by a microphone) that's been modulated onto a radio frequency carrier signal and transmitted as radio waves through space. You can do this without very complicated electronics at all!

Single Sideband (SSB)

If you're trying to pack a lot of channels in close together, however, having to transmit both sidebands, both carrying a copy of the baseband signal, is a bit wasteful. Also, it wastes energy - transmitting a signal takes energy, and our modulated signal consists of the unmodulated carrier plus the two sidebands, each at at most a quarter of the amplitude of the raw carrier (remember that A is at most 1) - at least two thirds of the energy is in that unchanging carrier!

If we can generate a signal that looks like an AM signal, but remove the constant carrier and one of the sidebands, we can use a quarter of the energy to get the same modulated signal amplitudes in the surviving sideband (or, for the same energy, get four times the signal amplitude). Therefore, single-sideband is popular for situations where we want efficient use of power and bandwidth, such as voice communications between a large number of power-limited portable stations. But for broadcasting high-quality sounds such as music, we tend to want to use full AM - power isn't such an issue for a big, fixed, transmitting station and we can afford to use twice the bandwidth to get a better signal; as an AM signal has two copies of the baseband signal in the two sidebands, the receiver can combine them to effectively cancel out some of the background noise.

Of course, you need to make sure that the transmitter and the receiver both agree on whether they're using the upper sideband (USB) or the lower one (LSB) - otherwise, they won't hear each other as one will be transmitting signals on the opposite side of the carrier frequency to the side the other's listening! And if the receiver adjusts the carrier frequency they're listening on to try and find the signal, they'll hear it with the frequencies inverted, which won't produce recognizable speech... A single sideband receiver can listen to an AM signal by just picking up the expected sideband, but an AM receiver will not pick up a SSB signal correctly, due to the lack of the constant carrier to use as a reference.

But amplitude modulation (of which SSB is a variant) is, fundamentally, limited by the fact that background noise will always be indistinguishable from the signal in the sidebands; all you can do is to transmit with more power so the noise amplitude is smaller in comparison. However, there is a fundamentally different way of modulating signals that offers a certain level of noise immunity...

Frequency Modulation (FM)

What if we transmit a constant amplitude signal, but vary its phase according to the baseband signal?

If we go back to our carrier:

Ac * sin(t*Fc*T + Pc)

And baseband signal:

A * sin(t*F*T + P)

Rather than having the carrier at some constant phase Pc, let's set Pc to the baseband signal, scaled so that the maximum baseband range of -1..+1 becomes a variation in phase of, say, at most T/4 each side of zero:

Pc = A * sin(t*F*T + P) * T/4

Thus making our modulated signal:

Ac * sin(t*Fc*T + A * sin(t*F*T + P) * T/4)

This is called "phase modulation". But you never hear of "phase modulation", only "frequency modulation". Why's that?

Well, a receiver has a problem with detecting the phase of the signal. Phase is always relative to some other signal; in this case, the transmitter is generating a signal whose phase varies compared to the pure carrier. The receiver, however, is not receiving a pure carrier to compare against. The best it can do is to compare the phase of the signal to what it was a moment ago - in effect, measure the rate of change of the phase. To make that work, the transmitter must change the phase at a rate that depends on the baseband signal, rather than directly with the baseband signal. But how to do that?

You may recall, from when we first talked about phase, that the phase difference between two signals of slightly different frequency changes with time - it goes from 0 to T (or -T/2 to T/2, depending on how you measure it) at a constant rate, and that rate depends on the frequency difference. That means that a frequency difference between two waves is the same thing as the rate of change of phase between the two waves...

This makes sense if you look at our basic wave formula A * sin(t*F*T + P) - if P is changing at a constant rate, then P is some constant X times time t, so we get A * sin(t*F*T + t*X), or A * sin(t*(F*T + X)), or A * sin(t*T*(F + X/T)) - we've just added X/T to the frequency (and T is a constant).

So all the transmitter needs to do is to vary the frequency of the signal it transmits, above and below the carrier frequency, in accordance with the baseband signal; and the receiver can measure the rate of change of phase in the signal it receives to get the baseband signal back.

Therefore, we call it frequency modulation (FM). The neat this is that, because we don't care about the amplitude of the received signal - just its phase - we don't tend to be affected by noise as much because noise is added, so mainly changes the amplitude of the received signal.

So what would we see if we tuned across an FM signal with our narrow-bandwidth receiver? How much bandwidth does an FM channel need, for a given maximum baseband frequency?

Surely, we get to choose that - if we decide that a baseband signal of +1 means we add 1kHz and -1 means we substract 1kHz, then the channel width we need will be 1kHz either side of the carrier frequency, 2kHz total, regardless of the baseband frequency involved? Unless the baseband frequency becomes a sizeable fraction of the carrier frequency, of course; we can't really measure the frequency of the modulated signal if it's varying drastically in phase at timescales approaching the cycle time!

But just as multiplying our carrier by the baseband frequency for AM caused Strange Maths to happen and create sidebands out of nowhere, something similar happens with FM. Now, I could explain the AM case by hand-waving over the trigonometic identities and show how sidebands happened, but the equivelant in FM is beyond my meagre mathematical powers. I'll have to delegate that to Wikipedia.

General Modulation: Mind your Is and Qs

Before we proceed, I must entertain you with an interesting mathematical fact.

Imagine our carrier signal at time t again:

A * sin(t*F*T + P)

Imagine we're using that as a carriar, so F is constant, and we're thinking about modulating its amplitude A or its phase P to communicate something. We're varying two numbers, so it should be no surprise that we can rearrange that into a different form that still has two varying numbers in it. It just so happens that we can write it as the sum of two signals:

I * sin(t*F*T) + Q * sin(t*F*T + T/4)

This is kinda nice, because that's just varying amplitudes of two constant-amplitude constant-phase sinusoidal signals at the same frequency, with a quarter-wave phase difference between them. This form means we don't have P inside the brackets of the sin() any more - and it was varying things inside the brackets of sin() that made the maths of AM and FM so complicated to work out.

But what's the connection between our original variables A and P, and our new ones I and Q? Well, it's quite simple:

I = A * sin(P)

Q = A * sin(P + T/4)

This can be used to build a kind of "universal modulator": given a carrier signal and two inputs, I and Q, output the sum of the carrier times I and the carrier phase-shifted by T/4, times Q.

You can then build an AM, FM, USB or LSB transmitter by working out I and Q appropriately. If your input baseband signal is X:

For AM (varying A, holding P = 0): I = X, Q = 0.

For FM (holding 'A = 1', varying P so that X is the rate of change of P): I = sin(X * t), Q = sin(X * t + T/4).

For LSB, I = X, Q = X phase-shifted by T/4

For USB, I = X, Q = -(X phase-shifted by T/4)

The latter two deserve some explanation! Let's imagine that X, our baseband signal, is a single sine wave, with zero phase offset to keep it simple:

Ax * sin(t*Fx*T)

For LSB, that gives us:

I = Ax * sin(t*Fx*T)

and

Q = Ax * sin(t*Fx*T + T/4)

Feeding that into the modulation formula to get our modulated signal:

I * sin(t*F*T) + Q * sin(t*F*T + T/4)

gives us:

Ax * sin(t*F*T) * sin(t*Fx*T) + Ax * sin(t*F*T + T/4) * sin(t*Fx*T + T/4)

We've got sin(X)*sin(Y) again, so can use sin(X)*sin(Y) = sin(X-Y + T/4) / 2 - sin(X+Y + T/4) / 2 to expand them out, and cancel out like terms to get:

(Ax / 2) * sin(t*F*T - t*Fx*T + T/4)

Or:

(Ax / 2) * sin(t*T*(F - Fx) + T/4)

That's a single sine wave, at frequency F - Fx - just the lower sideband!

Handily, we can get I and Q back from a modulated signal by just multiplying it by the same two carrier signals again. If we take our modulated signal:

I * sin(t*F*T) + Q * sin(t*F*T + T/4)

...and multiply it by sin(t*F*T) we magically get I back; and multiplying it by sin(t*F*T + T/4) magically gets us Q back (if anyone can explain how that works with maths, please do, because I can't figure it out; but I've experimentally verified it...).

We can visualise a modulated carrier in terms of I and Q on a two-dimensional chart. Conventionally, I is the X axis and Q is the Y axis. If there is no signal, I and Q are both zero - we get a dot in the middle of the chart. The amplitude of the received signal is the distance from the center to the dot, and the phase relative to the expected carrier is the angle, anti-clockwise from the positive X axis (extending to the right from the origin). If there is an amplitude-modulated signal, then that dot moves away from the centre by the baseband signal, at some angle depending on the phase difference between the received signal and the reference carrier in the receiver.

What will that angle be? Well, if we lock our reference carrier in the received to the phase of the signal when we first pick it up, then as AM doesn't change the phase, it will remain zero - the dot will just move along the positive I axis. If we don't have any initial phase locking, and just go with whatever arbitrary phase difference exists between our reference oscillator and the received signal (which will depend on when the referenced oscillator was started compare with when the transmitter's oscillator was started, and the phase shift caused by the propogation time of the signal, which depends on your distance - so, pretty arbitrary overall), we will find that our I/Q diagram is just rotated by some arbitrary angle. But that's fine, as with FM, it's the change of phase that matters, not the actual phase.

If we receive an FM signal, then the amplitude will remain constant but the phase will change, meaning that the dot will wiggle back and forth along a curved line - an arc of a circle about the origin.

Noise in the signal will cause the distance from the origin to vary, but it won't cause much variation in the angle unless it gets overpoweringly strong.

The fun thing about I/Q modulation is that it means we can take any two baseband signals and modulate them onto a single carrier, as long as their frequencies are well below the carrier frequency. We can modulate amplitude and frequency at the same time. We could have stereo audio by using I and Q as the left and right channels, respectively.

But, in practice, we tend to use such general I/Q modulation for digital data, rather than putting two analogue baseband signals together!

Digital data modes (QAM)

Say, rather than sending an analogue signal such as voice, you want to send a stream of symbols - such as characters of text.

You can assign each symbol in the alphabet you want to send to a particular I/Q value pair, and feed that into your transmitter.

At the receiver, we'll pick them up, with some arbitrary rotation due to the reference oscillator being at an arbitrary phase and thus being at an arbitrary difference and some arbitrary scaling of the I/Q pairs because we don't know how much the signal has been degraded by distance.

Bbut if we can somehow work out that phase difference and rotate the I/Q diagram to get it the right way around again, and can work out the peak signal strength expected from the transmitter and scale the I/Q values up to their proper range, we can decode the signal by comparing the received I/Q against our list of I/Q values assigned to each symbol in the alphabet, and picking the nearest - noise will shift the signal around a bit, but the nearest one is our best bet.

As usual, if we send symbols faster (so there's less signal at each I/Q value for each symbol) then the influence of noise rises, so we must trade off the rate at which we send symbols (the "baud rate"), how far apart the symbol I/Q points are, and how many symbols we get wrong per second.

How do we get that original phase-lock, though, to rotate the pattern to the right angle? Well, we might make our choice of points (which is known as a "constellation") not rotationally symmetrical, and make sure that we transmit enough different symbols to make the rotation of the constellation obvious at least once every time unit (which might be "a second" or it might be "at the start of every message" or whatever). For instance, make the constellation look like a big arrow pointing along the I axis, and start each message with a few symbols including the tip of the arrow and a couple each from the central line and the two lines in the arrow-head. The receiver can watch the pattern until it becomes clear which phase angle it needs, and then decode merrily on that basis. It will need to keep checking the phase angle and updating it - if there's even the slightest difference between the frequency in the transmitter's oscillator and the frequency in the receiver's oscillator, the I/Q signals at the receiver will slowly rotate as time passes.

Or, you can avoid the need in the same way that FM does - rather than having the constellation defined in terms of points in the I/Q diagram, define it in terms of distance from the origin and rotation angle for each symbol. Each symbol then goes to an I/Q pair that's at the specified distance, but at an angle that depends on the last symbol transmitted, plus or minus that offset. The receiver doesn't need to synchronise at all; it just needs to grab I/Q values and work out the distance from the origin, and the rotation angle between symbols received. If none of the symbols have a phase difference of zero, we get an extra benefit - every symbol involves a change in the modulated signal, even if it's the same symbol again, so we can automatically detect the rate at which symbols are being sent, and not get confused as to how many are being sent when the same symbol is sent repeatedly! You need to send a single symbol before any transmission that is used purely for the receive to use as a phase reference for the NEXT symbol which actually carries some data, of course, but that's a small price to pay.

To find the distance from the I/Q origin of peak transmitter power, we have to either make sure we transmit a symbol using maximum power at suitable intervals so the receiver can update their expectations and scale the I/Q diagram to the right size, or put our entire constellation in a circle so the amplitude is always the same; or, perhaps, have our constellation consist of a series of circles that use different phase differences in each circle - if you have three symbols in the smallest circle, and four in the next circle, and five in the next one up, and those three circles are rotated so that no two points on different circles are on the same phase angle, then for any two received symbols, we will be able to tell what circles they are on just from the phase difference between them - and thus know how much to scale them to place them on those circles. But if we're transmitting a reference symbol at the start of every transmission to establish the phase difference to the first actual message symbol, as suggested in the previous paragraph, we can just send that at a known power level and use that as a reference for both phase AND distance from the origin.

The modulated signal is a mixture of AM and FM, as the transmitted symbol's point in the constellation varies both in distance from the origin (amplitude) and in angle rotated since the last symbol (frequency shift).

Because the I/Q representation of a signal with respect to a carrier is known as "quadrature" (the I and Q stand for "in-phase" and "quadrature", respectively), this combined AM-and-FM is known as "Quadrature Amplitude Modulation", or "QAM". Standard constellations have names such as "256-QAM" (which has 256 different symbols, handy for transmitting bytes of data!).

Conclusion

So there you have it. That's not a complete summary of all the tips and tricks used to jam information into communications media; but it should explain the basics well enough for you to make the best of the Wikipedia pages for things like OFDM and UWB!

Note: In order to try and reduce the cognitive load, I've simplified the maths above somewhat - using sin with a phase difference rather than cos, for instance. It still works to demonstrate the concepts, and produces the same results as the conventional formulae apart from perhaps a changed sign here or there!

I'd like to clarify the explanations of various kinds of waves with diagrams, but I don't have the time to draw any right now! I may be able to come back to it later.

WordPress Themes

Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales
Creative Commons Attribution-NonCommercial-ShareAlike 2.0 UK: England & Wales