-
Notifications
You must be signed in to change notification settings - Fork 12
Basic Signal Modulation
Frequency modulation is one common method used to encode data for transmission over radio or audio, or recording to a variety of media. One familiar application of this is encoding data to audio tape, a system used by a number of classic computers such as the BBC Micro.
Classic computers like the BBC used a standard for encoding data to tape known as the Kansas City Standard. This is exceedingly simple; '0' bits are represented as four cycles of a 1200Hz sine wave, and '1' bits are represented as eight cycles of a 2400Hz sine wave. Bytes were encoded using a standard serial system called UART - the same system used by Arduino's serial module.
With the Tsunami, writing something to encode data like this is very straightforward. So far, we've been using the Tsunami to generate a single frequency at a time, but the DDS the Tsunami uses has two registers. Which register is currently being used can be changed using the Tsunami library, but it can also be controlled from a digital pin. By using these facilities, we can encode data to audio with very little code required at all:
SoftwareSerial out(TSUNAMI_DDS_FSEL, TSUNAMI_DDS_FSEL);
void setup() {
Tsunami.begin();
Tsunami.sleep(true);
Tsunami.setFrequency(0, 1200);
Tsunami.setFrequency(1, 2400);
out.begin(300);
}
void loop() {
while(!Serial.available());
Tsunami.sleep(false);
while(Serial.available()) {
out.write(Serial.read());
}
Tsunami.sleep(true);
}
In the setup routine, we turn on the Tsunami, disable its output, and configure its two registers with 1200Hz and 2400Hz. Then, we set up a serial connection to send data to the digital pin that controls which frequency the Tsunami output.
In the main loop, we wait for data to come in on the Tsunami's USB serial connection. Whenever data arrives, we turn the Tsunami's signal generation on, and write the data out to our virtual serial port, before turning the Tsunami back off again.
That's it - all you need to do in order to encode data using frequency shift keying on the Tsunami. The example audio you hear in the Kickstarter video is encoded using exactly this method.