{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## EE 123 Lab 0 - Basic Python and DTFT
January 22st, 2018 "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### General iPython Notebook usage instructions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Click the `Play` button to run and advance a cell. The short-cut for it is `shift-enter`\n",
"- To add a new cell, either select `\"Insert->Insert New Cell Below\"` or click the white down arrow button\n",
"- You can change the cell mode from code to text in the pulldown menu. I use `Markdown` for text\n",
"- You can change the texts in the `Markdown` cells by double-clicking them.\n",
"- To save your notebook, either select `\"File->Save and Checkpoint\"` or hit `Command-s` for Mac and `Ctrl-s` for Windows\n",
"- To undo in each cell, hit `Command-z` for Mac and `Ctrl-z` for Windows\n",
"- To undo `Delete Cell`, select `Edit->Undo Delete Cell`\n",
"- `Help->Keyboard Shortcuts` has a list of keyboard shortcuts"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Basic Python Questions:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To complete this part of the lab, you will need to read and run the python tutorial posted on the class website.\n",
"\n",
"Double-click the answer cell to add your answer. You can also insert a new cell by selecting `\"Insert->Insert New Cell Below\"` or clicking the white down arrow"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Q0.__ What do you add after a function to get the help window?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__A0.__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Q1.__ This isn't really a question. We will use Bokeh to plot some things, so let's make sure it's working correctly. Run the cell bellow. You should get an interactive plot. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from bokeh.plotting import figure\n",
"import socket\n",
"from bokeh.io import output_notebook, push_notebook, show\n",
"from bokeh.resources import INLINE\n",
"output_notebook(INLINE)\n",
"\n",
"plot = figure()\n",
"plot.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color=\"navy\", alpha=0.5)\n",
"\n",
"handle = show(plot, notebook_handle=True)\n",
"\n",
"# Update the plot title in the earlier cell\n",
"plot.title.text = \"New Title\"\n",
"push_notebook(handle=handle)\n",
"\n",
"\n",
"print(socket.gethostname())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Q2.__ What are the standard abbreviations for `numpy` and `matplotlib.pyplot` ?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__A2.__ Answer here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Q3.__ What is the output of the following commands?\n",
"\n",
" x = np.array([1,2,3,4,5,6])\n",
" y = x[0:4]\n",
" y[0] = 7\n",
" print(x)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__A3.__ Answer here"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Q4.__ Write a code that prints `[5 4 3 2 1 0 1 2 3 4]`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A4."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Q5.__ Write a code that prints out an array of every other integer from 0 to 4"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A5."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Q6.__ Generate the same plot as in the following figure inline:\n",
" \n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import Image\n",
"Image('http://inst.eecs.berkeley.edu/~ee123/sp14/lab/tutorial_plot.jpg')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# A6."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### DTFT:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this part of the lab, we will look at the DTFT of rectangular windows and triangular windows and compare their performances as low-pass filters. There is a code template provided for each part to help you become familiar with numpy syntax."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part (a):"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Import libraries\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from __future__ import division\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the DTFT (at least 512 points) of the rectangular window:\n",
"\n",
"