I fixed my radio transmitter

(This was originally posted on Google+.)

Well, I finally looked carefully at the signal coming out of my antenna and, yes, it turned out that most of the energy was being spent outside of the frequency I wanted to transmit on. However, it wasn't because of images and spurious transmissions that took most of the energy... It was because I was actually transmitting on the wrong frequency!

Keep reading because it wasn't just a case of "herp, derp, turned the knob to the wrong position."

In Software Defined Radio we work with quite basic transceivers whose mission is to receive a radio signal and transform it into a form a computer can process, and vice versa. To do that, a lot of mathematics are used in the computer, using something we call "complex numbers". Those complex numbers have two components: a real part and an imaginary part (the name "imaginary" was given to it when mathematicians didn't understand complex numbers yet, so they thought those numbers were less "real" than the numbers they had been using up to that point, but I digress).

So an SDR radio receiver takes a radio signal, does some electronic manipulations, and generates two signals that are converted into complex numbers by the computer. One of those signals, called I, will become those numbers' real parts, and the other signal, called Q, will become the imaginary parts.

When it's time to transmit, the computer takes the complex numbers' real parts and generates an I signal, and also generates a corresponding Q signal from the same numbers' imaginary parts. Those two signals go to the SDR transmitter, undergo some electronic transformations, and become a radio signal.

The problem with my setup was that the wires for the I and Q signals were crossed in the transmit path.

The effect of this is that the signal went out on the wrong frequency. Generally I had my "center frequency" set to 14.080 MHz and my transmit frequency set to 14.097 MHz. However, as I and Q were crossed, the transmitter took the real part as imaginary and the imaginary part as real, which mirrored the transmitted signal around the center frequency, and my transmission went out on 14.063 MHz. Oops!

Fortunately for me, I was transmitting with a small magnetic loop antenna, which has limited bandwidth (I explained this yesterday), so it is likely that only a very small fraction of this out-of-frequency signal actually went on the air, and the rest was converted to heat in the antenna.

Now, I don't know if I've mentioned this, but my signals had actually been received three or four times in the past two weeks. Also, when I used a shortwave radio to listen to my transmissions, I could hear my signal clearly on the right frequency. It's natural that you'd ask how this would be possible, if the signal was going out on the wrong frequency.

The answer is simple: before the complex numbers coming out of my computer get into the transmitter, they first go through a sound card, where they get turned into the I and Q electrical signals, and then they travel to the transmitter through audio cables. Stereo audio cables, to be precise, that have three wires: a ground wire, a wire for the left speaker, and a wire for the right speaker. In this setup, one of the speaker wires carries the I signal, and the other carries the Q signal. When you have two wires running in parallel carrying alternating currents, they induce small currents on each other, which causes a little bit of crosstalk.

So, with this crosstalk, by the time the signals arrive at the radio transmitter, the wire for the I signal will also carry a little bit of Q signal mixed in and vice versa, and when it's finally transmitted, there will be a tiny signal in the originally intended frequency. I could hear it on my radio because it was very close to the antenna, and it was sometimes heard farther away because I was using WSPR (pronounced "whisper"), a digital mode intended for low-power signals, so the people who received those signals were already listening for very faint transmissions.

After fixing this issue I sent another transmission through WSPR. This time, four stations heard me at once; the farthest of those stations was in Alaska. My second signal was heard in New Zealand. Both were transmitted with 1 watt of power. I think it is safe to say that both my transmitter and my homemade antenna work correctly now :)

And now I have a 50-watt amplifier to fix.

Improving my homemade amateur radio antenna

(This was originally posted on Google+.)

Yesterday I worked a bit on my magnetic loop antenna. More properly called a "small magnetic loop antenna" (or SMLA for short), it basically consists of a long loop of wire connected to a variable capacitor. The loop of wire forms an inductance, which together with the capacitance forms a resonant circuit. So by wiring it appropriately, you can use a SMLA to receive and transmit signals in the SMLA's resonant frequency, which you can change by turning a knob to vary the capacitance.

As you might guess, the more resonant the antenna is, the better it works: the signals in that frequency are amplified more. Also, when the antenna is more resonant it has narrower bandwidth: the energy in the antenna is concentrated into a smaller band of frequencies. The amount of resonance is given by a number called "quality factor" (or Q, for short). Q is affected by the values of the inductance, capacitance, and resistance in the SMLA. In particular, the lower the resistance, the higher Q is. So if you make an SMLA you need to reduce the electric resistance as much as you can to get the best value of Q.

There is another reason why it's important to reduce the electric resistance if you want to make a transmitting SMLA: the antenna's radiation resistance is very small, in the order of milliohms, so any additional resistance reduces the antenna's efficiency dramatically.

People like me, who are used to dealing with continuous currents, would think that it would be enough to use wide-gauge wiring, solder all connections to reduce contact losses, etc. A couple of weeks ago I measured my SMLA's resistance as 50 milliohms, which doesn't sound so bad; however my antenna's Q factor seemed quite low and my transmissions were heard by nobody.

What I'd missed is that alternating currents (and radio waves in a cable are alternating currents) don't travel along the full section of the cable, like continuous currents: there's a phenomenon called "skin effect" by which those currents only travel on the surface of the conductor. The higher the frequency, the shallower the skin: for example, in copper, at 14 MHz, most of the current is concentrated at a depth of less than 17 micrometers.

The first consequence of this is that the resistance of a wire doesn't go down with the square of the diameter of its section as for continuous currents, but linearly with the diameter. So using wide gauge wire doesn't help much. What you need to use instead is flat ribbon or, even better, copper braid: braid has a lot of surface area for its volume, so it should present a low resistance to alternating current.

The second consequence is that you should avoid solder joints: since the current travels on the surface, spots where the surface is tinned will have a lower conductivity than the bare copper surface.

So yesterday I remade the connections between the loop and the capacitor in my SMLA, replacing the 10-AWG wires with copper braid ribbons. I fastened them using screws and washers so that they were pressed against the terminals on the ends of the loop and the capacitor, making sure that as much surface area as possible touches.

This change has apparently raised my SMLA's Q factor: I can work on about 40kHz before having to retune, while before I could use some 60kHz. I hoped that transmit performance would also be improved, but, alas, nobody heard my transmissions the whole day today. I guess my antenna is not good enough yet.

There may be another explanation for this failure to be heard, though. Using a shortwave receiver I could hear spurious signals around the signal I wanted to transmit. Using an RTLSDR dongle I could see the spectrum around the frequency my transceiver was tuned to, and there were lots of spurs and images on transmit. I don't know if it's a fault in the particular transceiver kit I'm using, or whether it's a drawback of the design itself. In any case, this suggests to me that perhaps too much energy is being wasted on those spurs. That's certainly something I'll need to look at again and more carefully.

Why a radio signal carrying Morse Code is called Continuous Wave even though it's turned on and off

(Originally published on Google+.)

As you may know, lately I'm into amateur radio. In this world, Morse code is still alive and well, though it is not necessary to learn it to get a license. When two operators use Morse code to communicate, quite often they use a mode called "Continuous Wave", or CW for short.

For quite a while I thought that CW was quite an odd name for a way to transmit Morse code. There's certainly a wave: that's the radio wave on which the Morse code is modulated. What I didn't see so clearly was the reason for the "continuous" adjective. After all, the wave is being turned on and off all the time: that's precisely how you can send Morse. If it's being turned on and off, it's not continuous. What's the deal?

Well, the deal is that before we had continuous waves, we already had Morse code on the radio, transmitted with a different kind of radio wave: the Damped Wave.

A Continuous Wave is a sinusoidal wave with a precise frequency. Nowadays it's very easy for us to produce precise and stable sinusoidal waves using pretty cheap electronics. However, in the early days of radio it wasn't so: there weren't good enough electronic oscillator circuits that could produce a quality continuous wave. So radio stations used a different mechanism to produce a different kind of radio waves.

This mechanism was the spark-gap transmitter. The general idea is that a high voltage across a gap produces an electric arc (a spark). The transmitter contains a circuit that, when an arc starts, produces a "ringing" oscillation, like the sound of a bell being struck once by a hammer. This oscillation is fed to an antenna to transmit it as a radio wave, which is called a "damped wave" because it loses amplitude with time, just like the sound of a bell stroke.

As the damped wave only lasts for a tiny fraction of a second, the spark gap is set up so that those sparks are extinguished almost as soon as they start, and a new one starts almost immediately, which produces another damped wave. In this way, lots of damped waves are produced and transmitted every second, like a school bell ringing seemingly continuously because its hammer strikes the bell several times per second.

The problem with spark-gap transmitters is that they are very inefficient and produce a prodigious amount of interference, so a lot of effort was spent in discovering a good way to generate a "continuous wave" that doesn't lose strength with time so you only need to produce the one wave and turn it on and off as needed.

Eventually, several systems were developed, like high-frequency electric generators, electronic oscillators, etc. As those became commonplace, the old spark-gap transmitters and the damped waves they produced were retired and then banned worldwide (so big was the interference problem).

And that's why a radio signal carrying Morse Code is called Continuous Wave even though it's turned on and off.

How magnetic stripe cards work

Lately I've been experimenting with a magnetic stripe card reader. In summary, I bought the cheapest one I could find on Amazon, opened it up, soldered some wires to it, added some electronic components, plugged it to my computer's microphone socket and recorded things like this: the raw signal read from a magnetic stripe. In this post I'll explain how magnetic stripe cards work and how to decode them.

Magnetic stripe cards were invented by Forrest Parry in 1969, which was quite the prolific year for giant leaps for humankind. The first company to develop and produce those cards was IBM, which chose to leave the basic ideas "open" for the rest of the industry to develop their own card systems. Some time later, the banking and airline industries met up and defined a set of standards so that all magnetic stripe cards would have the same size, their magnetic stripes in the same position, use the same encodings, etc.

The magnetic stripe is the usually dark-colored strip that appears in the back of the card. The data in the card are recorded in the magnetic stripe, but to read on how those data are stored, you'll need to click the "read more" link.

Mystery signal challenge

I'm currently doing some experiments with electronics, and in the process I captured the signal you can find in the attached file. I captured it through my sound card's microphone input, and I've amplified it in software so it's easier to "appreciate". (Update: I've managed to perform a way better capture, so this is as it comes straight from the sound card, with no extra amplification.) Obviously I know what it is, but I'd like to know who among the people who happen to read this will also be able to identify it — and better yet, tell me what's in the signal.

One clue: this signal is produced by something that was invented in 1969.

Post your guesses and comments in the story on Google+.

Cómo demodular radio FM estéreo

En el artículo anterior hablé de cómo demodular una señal de radio AM o FM, y en este artículo voy a hablar de lo que os encontraréis después de la demodulación (lo que di en llamar "el programa"). Tal vez os sorprenda que vaya a dedicar un artículo completo al asunto, pero, como podéis imaginar por su longitud, puede tener bastante tela. Al menos, para nuestro alivio, el asunto es muy sencillo en AM y en FM "mono": después de demodular la señal de radio, lo que tenemos es una onda sonora. Sin embargo, la cosa se complica cuando se trata de FM estéreo.

En un sistema de sonido monofónico sólo hay un altavoz, o hay varios altavoces pero todos reproducen la misma señal sonora. En un sistema de sonido estereofónico, en cambio, hay dos juegos de altavoces; uno que reproduce sonidos destinados al oído derecho y otros que reproducen sonidos destinados al oído izquierdo. Esto permite realizar efectos como hacer aparentar que un sonido procede de una determinada dirección (el sonido estereofónico se inventó para el cine en los años 30; la palabra "estéreo" viene de la palabra griega στερεός, que significa "sólido").

Cuando quisieron inventar un sistema para transmitir sonido estéreo por la radio, decidieron añadir esta capacidad a la radio FM. El objetivo era que una emisora FM pudiese transmitir sonido estéreo por el mismo canal que venía usando para el sonido mono de manera que las radios monofónicas que ya estaban en el mercado pudiesen recibir correctamente esas transmisiones estéreo, aunque (por supuesto) se escuchasen en mono. Para ello, las frecuencias audibles del programa demodulado deben contener una señal monofónica de manera que una radio FM mono pueda tratar el programa estéreo como si fuera un programa mono y que se oiga igual la música o las noticias o lo que sea. Sin embargo, no había nada que impidiese añadir más información en frecuencias superiores a estas frecuencias audibles. Lo que hicieron fue precisamente eso: generar una onda con toda la información necesaria para reconstruir la señal estereofónica y desplazarla en frecuencia hasta una frecuencia inaudible, y luego hacer que el receptor la vuelva a trasladar hasta las frecuencias audibles.

Tengo dibujitos y diagramas en el artículo completo, que podéis leer pulsando en "leer más". O podéis no pulsarlo y quedaros con la duda para siempre. Vosotros mismos.

Modulación en amplitud y modulación en frecuencia

Imaginad que tenemos un programa que queremos emitir por la radio. Este programa podría ser una canción, o un partido de fútbol, o un noticiero, o lo que sea. El programa puede ser en directo, o puede estar grabado en una cinta o en un CD o en un MP3. En todo caso, el programa se compone de ondas sonoras que queremos convertir en ondas de radio para que la gente pueda recibirlas y escuchar el programa en sus casas.

Obviamente, esto no es tan sencillo como enchufar directamente el micrófono o el reproductor de MP3 a la antena emisora. Si esto pudiese funcionar, sólo podría haber una emisora de radio en cada sitio. Además, las ondas de radio no se transmiten nada bien a las frecuencias de las ondas sonoras; para una buena transmisión, las ondas de radio necesitan tener frecuencias de cientos de miles o millones de ciclos por segundo. Por lo tanto, es necesario un proceso para convertir las ondas sonoras de baja frecuencia en ondas de radio de alta frecuencia; este proceso se llama modulación.

Pulsad en "leer más" para leer más. No pulséis en "leer menos" porque no lo hay.

Cómo funciona un descodificador de TDT

La TDT (Televisión Digital Terrestre) es un sistema de transmisión digital de televisión utilizando señales de radio transmitidas cerca de la superficie de la Tierra (en lugar de usar cable o satélites, que usan sistemas diferentes). En el sistema de televisión tradicional (analógico), las señales de radio representaban directamente las imágenes y sonidos transmitidos, mientras que en el sistema digital las señales de radio representan dígitos binarios que componen un "stream" digital de vídeo y audio. No os preocupéis por todas estas palabras raras, que si pulsáis en "leer más" os lo explico todo.

La transformada de Fourier y cómo sintonizar una radio

En el último artículo dije que había dos cosas súper importantes, hice un breve resumen de ellas e inmediatamente después terminé el artículo sin explicarlas mejor. Qué mala educación por mi parte. En este artículo no sólo voy a corregir ese paso en falso, sino que también hablaré de otras cosas que también os resultarán interesantes, como el dominio del tiempo y el dominio de la frecuencia (esos nombres parecen que cuadrarían mejor en una novela fantástica), cómo aumentar y reducir la frecuencia de una señal, y cómo funciona una radio. ¡Y no cuento más que una o dos mentiras!1

1 Podrían ser más.

Las ondas y los números complejos

En este artículo comento algunas de las cosas que se pueden hacer con números complejos. Hay dos formas de representar un número complejo: forma cartesiana y forma polar. Algunas operaciones con números complejos son más fáciles en forma polar y otras lo son en forma cartesiana, y este artículo se centra en la forma polar y en lo útil que es para hacer procesamiento de señales, que es un tema en el que estoy interesado últimamente.

Como bonus, para aquellos que hayan oído hablar de la Transformada de Fourier pero no entienden cómo funciona, este artículo puede servir de introducción. Ya hablaré de ella en más profundidad en otro artículo, y tal vez incluso despeje algunas dudas sin crear otras que las sustituyan :-)

Hala, pulsad en "leer más" para leer esta obra maestra de la literatura universal.