{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# EE 123 Lab1 - Time Domain Sonar Lab\n", "\n", "### Written by Miki Lustig and Frank Ong 2016" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this lab, we will interact with physical time-domain signals. The first part will involve generating and recording sounds on your computer. We will use the chirp signal to characterize the response of the speaker-microphone system and look at detecting signals using cross-correlation.\n", "In the second part, we will build on part one and use the computer sound system to develop a simple sonar." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Import functions and libraries\n", "from __future__ import division\n", "import numpy as np, matplotlib.pyplot as plt, bokeh.plotting as bk\n", "import threading,time, Queue, pyaudio\n", "from matplotlib.pyplot import *\n", "import matplotlib.cm as cm\n", "from scipy import signal\n", "from numpy import *\n", "from bokeh.models import GlyphRenderer\n", "from threading import Lock\n", "bk.output_notebook()\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Part 1: Chirping!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For this assignment you will have to use iPython, and a laptop equipped with a speaker and a microphone. When playing a sound and recording on the computer speaker, the signal goes through several systems. In particular it goes through the response of the speaker, the room we are in and the response of the microphone recording system.\n", "\n", "A chirp is a a signal in which the frequency increases linearly with time. In this assignment we will generate a chirp signal and use it to measure the amplitude of the frequency response of our speaker-room-microphone system.\n", "\n", "A simultaneous frequency is defined as the derivative of the phase of a signal, $f = \\frac{1}{2\\pi} \\frac{d\\phi (t)}{ dt} $. For example, the simultaneous frequency of $\\cos(\\phi(t))=\\cos(2\\pi f_0 t)$ is \n", "\n", "$$f = \\frac{d\\phi (t)}{2\\pi dt} = f_0$$ \n", "\n", "\n", "For a linear chirp, the frequency changes linearly over time. The simultaneous frequency is therefore defined as \n", "\n", "