{
"metadata": {
"name": "",
"signature": "sha256:5555b64f3ace56c5e9ac0050eb6cd49ca3cc59ca0e22bf20f1b34f5f20947c54"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#Lab 3 - Time Frequency\n",
"
\n",
"originally designed by John Pauly, modified and extended by Michael Lustig, Translated to python by Frank Ong\n",
"\n",
"This week we will look at the processing and spectrum of time-varying signals. In the first part of the lab we will look at the short-time fourier transform and spectrograms. We will use this to analyze audio signals and broadcast FM. In the second we will look at frequency offset correction of the SDR using GSM cellphone basestation signals. In the last part we will look at generating digital packets using frequency modulation. "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Import functions and libraries\n",
"from __future__ import division\n",
"import numpy as np, matplotlib.pyplot as plt, bokeh.plotting as bk\n",
"from numpy import *\n",
"from numpy.fft import *\n",
"import scipy.signal as signal\n",
"from matplotlib.pyplot import *\n",
"from rtlsdr import RtlSdr\n",
"\n",
"%matplotlib inline"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stderr",
"text": [
"/Users/frankong/anaconda/lib/python2.7/site-packages/pytz/__init__.py:29: UserWarning: Module argparse was already imported from /Users/frankong/anaconda/lib/python2.7/argparse.pyc, but /Users/frankong/anaconda/lib/python2.7/site-packages is being added to sys.path\n",
" from pkg_resources import resource_stream\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part I: Spectrograms\n",
"In class we used the DFT to estimate the frequency of a segment of a signal. When we do this, we are implicitly assuming that the frequency is constant over that interval. This is a reasonable assumption for some signals, especially for a very short time windows. \n",
" \n",
"There are many times when we'd like analyze signals whose frequency is changing over time. In fact, most signals aren't interesting unless they do change! There are many examples, including speech, music, and the sounds that surround you in daily life. In this lab we will learn how to process these signals to determine how their spectrum changes with time.\n",
"\n",
"The basic problem is that we have long segment of a signal $x[n]$, where $n=0, ... ,N-1$. We want to know what its frequency is as a function of time. There are two basic approaches. One is to pass the signal through a bank of bandpass filters, and plot the outputs of the filters as a function of time. \n",
"\n",
"\n",
"The second approach is based on the short-time Fourier transform and is to break the signal up into short segments, and compute the spectrum of each of these separately. This is the approach we will use in this lab.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A sample signal is shown in Figure 1. You've seen this signal during the class. Obviously you can tell that the amplitude is changing as a function of time. When you examine the signal closely, you can also tell that the frequency is changing.\n",
"Since the frequency is changing, we want to break the signal into segments over which the frequency is relatively constant. Then we will analyze each segment using the DFT. The result of analyzing the first 256 samples, and another block of 256 samples that is 1024 samples later is shown in Figure 2. As is the convention with the DFT, zero frequency is the first sample, and the Nyquist rate corresponds to the middle sample. The sampling rate in this example was 8192Hz, so the maximum frequency is 4096Hz. Note that the frequency has dropped about 300 Hz between the first and second block."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"