{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab 5 Part 2: Digital Communication with Audio Frequency Shift Keying (AFSK)\n", "\n", "In this part of the lab we are going to experiment with digital modulation and communication. Network Communication systems have layered architecture. The bottom layer is the physical which implements the modulation. Here we will use [AFSK](http://en.wikipedia.org/wiki/Frequency-shift_keying), which is a form of BFSK in the audio range (hence the 'A'). We will write a modulator/demodulator for AFSK. In the next part of lab we will leverage [AX.25](http://www.tapr.org/pub_ax25.html), which is an amateur-radio data-link layer protocol. [AX.25](http://www.tapr.org/pub_ax25.html) is a packet based protocol that will help us transmit data using packets. It implements basic synchronization, addressing, data encapsulation and some error detection. In the ham world, an implementation of AFSK and [AX.25](http://www.tapr.org/pub_ax25.html) together is also called a [TNC ( Terminal Node Controller )](http://en.wikipedia.org/wiki/Terminal_node_controller). In the past TNC's were separate boxes that hams used to attach to their radios to communicate with packet-based-communication. Today, it is easy to implement TNC's in software using the computer's soundcard.... as you will see here! \n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using matplotlib backend: MacOSX\n", "Populating the interactive namespace from numpy and matplotlib\n" ] } ], "source": [ "%pylab\n", "# Import functions and libraries\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import bitarray, time, urllib, ssl\n", "from scipy import signal, integrate\n", "from fractions import gcd\n", "\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# function to compute least common multipler\n", "def lcm(numbers):\n", " return reduce(lambda x, y: (x*y)/gcd(x,y), numbers, 1)\n", "\n", "# function to compute average power spectrum\n", "def avgPS( x, N=256, fs=1):\n", " M = floor(len(x)/N)\n", " x_ = reshape(x[:M*N],(M,N)) * np.hamming(N)[None,:]\n", " X = np.fft.fftshift(np.fft.fft(x_,axis=1),axes=1)\n", " return r_[-N/2.0:N/2.0]/N*fs, mean(abs(X)**2,axis=0)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## AFSK1200, or Bell 202 modem\n", "\n", "AFSK1200 encodes digital binary data at a data-rate of 1200b/s. It uses the frequencies 1200Hz and 2200Hz ( center frequency of $1700$Hz $\\pm 500$ Hz) to encode the '0's and '1's (also known as space and mark) bits. Even though it has a relatively low bit-rate it is still the dominant standard for amateure packet radio over VHF. It is a common physical layer for the AX.25 packet protocol and hence a physical layer for the Automatic Packet Reporting System (APRS), which we will describe later. \n", "\n", "The exact analytic frequency spectrum of a general FSK signal is difficult to obtain. But, when the mark and space frequency difference $\\Delta f$ is much larger than the bit-rate, $B$, then the bandwidth of FSK is approximately $2\\Delta f + B$. This is not exactly the case for AFSK1200 where the spacing between the frequencies is 1000Hz and the bit-rate is 1200 baud.\n", "\n", "