{ "metadata": { "name": "", "signature": "sha256:20880da2712107cdf826fa4ff75a8dd21791a96a23a0e9131caed4e4606ac43a" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab3 - Multimedia Lab\n", "\n", "The Multimedia Lab will be a two part lab designed to discuss each aspect of the life-cycle of a multimedia file. This story begins with generation of the file, which is the digitization of some analog phenomenon of interest (e.g. sound -> music, light -> image, both -> film). Once this process is complete, the generated digital media file can be operated on (stored, read, copied, etc.) by a finite precision computer. Each of these operations, however, would be quite a bit faster if the file were small, so we'll investigate compressing the file into a more compact representation. As the honorable Snoop Dogg knew well, it \"ain't no fun if the homies can't have none,\" so you'll naturally want to share this media file with your friends. We'll look at the complications that may arise in transmission, and investigate techniques to ensure that your friend recieves the file error-free. Sadly, all good things must come to an end, and if your file is stored on some physical medium, it will eventually be corrupted.\n", "\n", "Naturally, the process of capturing, storing, transmitting, and eventually deleting a media file is composed of a harmony of instruments across **all** EECS disciplines, but this lab will focus in particular on the role of probabilistic analysis, reasoning, and algorithm design in this symphony. Probability in EECS does not exist in a vacuum but, as you will see in this lab, often forms the theoretical underpinning to analyze the efficacy of an idea.\n", "\n", "This notebook covers Part 1 of the lab, in which we'll cover the first half of this process: digitization and compression of media. Next week, Part 2 of the lab will be assigned, which covers transmission and corruption. Hope you enjoy the lab!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Part 1: Quantization and Huffman Compression\n", "\n", "When capturing media, we must go from a real world analog media to a digital representation. In general, this process is a matter of sampling, quantization, and compression. As technology improves, sampling methods become faster and more precise, quantized representations of media allow for more bits of precision, and both lossy and lossless compression algorithms improve performance. The tools to measure the effectiveness of these improving technologies, however, remain largely the same, and many of them are built on probabilistic analysis.\n", "\n", "In this lab, we will talk about quantization for audio signals, and compression of tweets. This should give you an introduction to two of the key aspects of digitally storing analog media." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Audio Quantization \n", "\n", "We live in an analog world, where input values may be continous and uncountable. This isn't very useful if we want to do any sort of digital signal processing. What we do instead to deal with this is to create a mapping from our huge set of continuous input values, to a smaller set that we can manage. We essentially bucket-off all of our input values before working with them (rounding is a form of quantization as well). However, as you might imagine, by mapping a large set to a smaller one, we introduce some level of quantization error (think integer division in python). The amount of distortion you experience will be determined by the method and parameters used during the quantization process. \n", "\n", "In this portion of the lab, we will step you through the process of generating and playing a wav file in iPython. You will then implement a quantizer method, and play the resulting quantized song. We will wrap up this section of the lab by exploring the effects of quantization error.\n", "\n", "The following modules and functions will allow you to generate, load, and play a wav file in iPython. You don't need to understand how they work, but you should understand how to use them." ] }, { "cell_type": "code", "collapsed": false, "input": [ "import scipy.constants as const\n", "import scipy\n", "from scipy.io import wavfile\n", "from IPython.core.display import HTML\n", "from IPython.display import display\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from __future__ import division\n", "%matplotlib inline\n", "\n", "# this is a wrapper that take a filename and publish an html