For a signal to travel over radio waves, it must be modulated first, which means having it transposed to a frequency bandwidth and format suitable to the transmission medium. Modulation techniques are closely related to telecommunications and information theory, and it is possible to play with modulation within the limits of a computer. This is a theme that I must confess I don't understand much, but I am mesmerized by it nevertheless. And to be honest, I find incredible how a couple simple calculations can make the miracle.
In this post, I am going to illustrate the AM modulation techniques, using WAV audio files. To begin with, we need a baseband signal, that is, some audio that fills all available bandwidth from 0Hz. I have recorded my own, ugly voice in order to torture your ears:
(paralelepipedo.wav)
By the way, I am using the EMBED tag to put all audios on page. If it does not work in your browser, you can get the audios at http://epx.com.br/wav.
AM modulation demands that signal is restricted to a bandwidth, so the modulated signal will also "fit" in a predetermined frequency band. So, we need to apply a low-pass filter on my voice, and we define the cut-off at 1000Hz. The result is my voice in lower quality.
(paralelepipedo_lopass.wav)
I have used an Audacity's low-pass filter plug-in. For the next post, I promise to write a filter from scratch, in Python. These Audacity filters that I am using are not perfect, but are enough to illustrate our points.
Amplitude modulation is just multiplying the original signal by a sinusoidal wave, the carrier. In this case, I have chosen a 3000Hz carrier, well above the cut-off of original signal, which is 1000Hz. The carrier noise itself is:
(carrier3000.wav)
Modulation result (voice multiplied by whistle) is:
(amsc.wav)
Note that it is almost impossible to understand the speech. To be exact, this modulation is named AM-SC (Supressed Carrier), for a reason that I will clarify a bit later.
Modulation makes my voice to exchange band from 0-1000 to 2000-4000Hz. Actually, AM modulation creates two "copies" of the original signal, one at 2000-3000Hz band and another at 3000-4000Hz. So, normal AM "wastes" bandwidth because modulated signal occupies twice as much of bandwidth.
Nevertheless, AM is still quite useful, because I can "move" my voice to frequencies suitable for electromagnetic transmission. And, even more important, modulation allows allocation of multiple signals on the same medium, each one occupying a different band, and each one can be recovered separately.
The "normal", old radio AM modulation sounds like this:
(am.wav)
In this modulation, we can hear the carrier, while we could not in AM-SC. The following Python program was employed to generate the modulated AM and AM-SC audios:
#!/usr/bin/env python
import wave, struct, math
baseband = wave.open("paralelepipedo_lopass.wav", "r")
amsc = wave.open("amsc.wav", "w")
am = wave.open("am.wav", "w")
carrier = wave.open("carrier3000.wav", "w")
for f in [am, amsc, carrier]:
f.setnchannels(1)
f.setsampwidth(2)
f.setframerate(44100)
for n in range(0, baseband.getnframes()):
base = struct.unpack('h', baseband.readframes(1))[0] / 32768.0
carrier_sample = math.cos(3000.0 * (n / 44100.0) * math.pi * 2)
signal_am = signal_amsc = base * carrier_sample
signal_am += carrier_sample
signal_am /= 2
amsc.writeframes(struct.pack('h', signal_amsc * 32767))
am.writeframes(struct.pack('h', signal_am * 32767))
carrier.writeframes(struct.pack('h', carrier_sample * 32767))
AM-SC is simply the original signal (whose band has been restricted by a lowpass filter) multiplied by the carrier, which is simply a sinusoidal wave.
AM modulation is the same as AM-SC, except that carrier is added afterwards. This allows the AM receiver to be much simpler, as we will see.
Well, it's time to proof that we can extract the original voice from these modulated audios. The AM-SC modulation is as simple as multiply the signal again by the same carrier, and then passing the result through a lowpass filter. There are the demodulated audios, before and after lowpass:
(demod_amsc_ok.wav)
(demod_amsc_ok_lopass.wav)
As said, AM-SC demodulation is almost equal to modulation. Multiplying a signal twice by the same carrier throws the voice back to its original band (0-1000Hz), and creates a new copy around 6000Hz which needs to be suppresed by the lowpass filter.
This is the AM-SC demodulator code:
modulated = wave.open("amsc.wav", "r")
demod_amsc_ok = wave.open("demod_amsc_ok.wav", "w")
demod_amsc_nok = wave.open("demod_amsc_nok.wav", "w")
demod_amsc_nok2 = wave.open("demod_amsc_nok2.wav", "w")
for f in [demod_amsc_ok, demod_amsc_nok, demod_amsc_nok2]:
f.setnchannels(1)
f.setsampwidth(2)
f.setframerate(44100)
for n in range(0, modulated.getnframes()):
signal = struct.unpack('h', modulated.readframes(1))[0] / 32768.0
carrier = math.cos(3000.0 * (n / 44100.0) * math.pi * 2)
carrier_phased = math.sin(3000.0 * (n / 44100.0) * math.pi * 2)
carrier_freq = math.cos(3100.0 * (n / 44100.0) * math.pi * 2)
base = signal * carrier
base_nok = signal * carrier_phased
base_nok2 = signal * carrier_freq
demod_amsc_ok.writeframes(struct.pack('h', base * 32767))
demod_amsc_nok.writeframes(struct.pack('h', base_nok * 32767))
demod_amsc_nok2.writeframes(struct.pack('h', base_nok2 * 32767))
One little big problem of AM-SC demodulation: the carrier wave generated at receiver must be EXACTLY equal to transmitter, both in frequency and phase. Any difference will wreck the demodulation. In the code above, I simulated two demodulation problems: carrier with wrong phase (90 degrees behind), and with wrong frequency (100Hz higher). The resulting demodulations are very bad, as you can hear below (already lowpassed):
(demod_amsc_nok_lopass.wav)
(demod_amsc_nok2_lopass.wav)
It is very difficult to generate a local carrier at receiver with these constraints. It would be easier in "old radio" AM because the carrier is sent together, so it could be extracted directly from the antenna signal. Due to this, AM-SC is seldom employed in practice. (*)
Now, let's see the "old radio" AM demodulator:
modulated = wave.open("am.wav", "r")
f = demod_am = wave.open("demod_am.wav", "w")
f.setnchannels(1)
f.setsampwidth(2)
f.setframerate(44100)
for n in range(0, modulated.getnframes()):
signal = struct.unpack('h', modulated.readframes(1))[0] / 32768.0
signal = abs(signal)
demod_am.writeframes(struct.pack('h', signal * 32767))
Note how simpler it is, the absence of transcendental functions. AM demodulator is simply a detector, which cuts off the negative part of wave. That's why you can build a galena radio with just a diode and a capacitor, the first being the abs() function and the latter being the lowpass filter.
There are the demodulation results, before and after the lowpass filter:
(demod_am.wav)
(demod_am_lopass.wav)
The remaining noise is likely due to the abs()-based detector in demodulation; In a real-world AM radio, the noise generated by detector would be of a far higher frequency, and lowpass filter would remove it completely. (Remember that we have modulated to a very low frequency, 3000Hz).
Both AM and AM-SC modulations waste bandwidth, because they generate two "copies" of the same content around carrier. Moreover, AM sends the carrier all along with content. We can say that an AM transmitter spends 75% of power just sending "garbage" which does not increase range -- it is there just to help receivers (an heritage from galena days).
But there is a way to improve AM efficiency. Since AM-SC signal has two copies, we can just filter out one of them, sending only the other. This is called AM-SSB (supressed side band). This is how AM-SSB sounds like (lower band removed, only upper band is kept):
(amssb.wav)
Not much different from AM-SC; and in fact the AM-SC demodulator can cope with AM-SSB signal without any changes:
(demod_amssb_ok.wav)
(demod_amssb_ok_lopass.wav)
Besides saving power by sending only one copy of original content, without the carrier, AM-SSB has a second, definite advantage over AM-SC. See what happens when we demodulate AM-SSB with an out-of-phase carrier:
(demod_amssb_nok_lopass.wav)
The voice has been recovered perfectly. So, an AM-SSB receiver does not need to worry with carrier's phase. Only the frequency is important, and it must be watched closely; any frequency deviation causes audio distortion pretty much like AM-SC:
(demod_amssb_nok2_lopass.wav)
AM-SSB is the standard modulation for ham radio, police, aviation, analog TV video etc. And the same technique is employed in FDM multiplexers and countless other devices that need to fit many signals in a single path. Removal of the unneeded sideband in tranmission can be done with an analog filter, but such filter is difficult and expensive to build. DSP-powered radios use a technique called Hilbert Transform to generate the AM-SSB signal directly, without the need of a filter.
(*) A surprising usage of AM-SC is the FM stereo. The second audio channel is encoded within the audio signal, with a 38KHz carrier. A 19KHz pilot tone is transmitted all the time so the receiver can generate a local carrier with perfect frequency and phase. Of couse this implies that FM audio can not be more treble than 19KHz.

0 comentários:
Postar um comentário