{ "metadata": { "name": "", "signature": "sha256:cceeee52c87df5f71212b1f496dc8c74aef9dc8113954389699c0c412f3673a1" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "%matplotlib inline\n", "import numpy as np\n", "import matplotlib.pyplot as plt" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Aliasing** \n", "The code below plots sine waves of a given frequency, along with their representation on a grid with $m$ points. Try changing $p$ and notice how for $m<2p$ the function looks identical to that for $2(m+1)-p$ due to aliasing. " ] }, { "cell_type": "code", "collapsed": false, "input": [ "from matplotlib import animation\n", "import matplotlib.pyplot as plt\n", "from clawpack.visclaw.JSAnimation import IPython_display\n", "\n", "fig = plt.figure()\n", "ax = plt.axes(xlim=(0, 1), ylim=(-1.2, 1.2))\n", "\n", "m=20\n", "x=np.linspace(0,1,m+2); # grid\n", "xf=np.linspace(0,1,1000) # fine grid\n", "\n", "line1, = ax.plot([],[], '-r', lw=2)\n", "line2, = ax.plot([],[],'o-',lw=2)\n", "\n", "def fplot(p):\n", " line1.set_data(xf, np.sin(p*np.pi*xf))\n", " line2.set_data(x,np.sin(p*np.pi*x))\n", " ax.set_title('p='+str(p))\n", " return line2,\n", "\n", "anim = animation.FuncAnimation(fig, fplot, frames=range(0,44))\n", "IPython_display.display_animation(anim, show_buttons=True)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Try to answer the questions below with pencil and paper; then check them by modifying the code above.\n", "\n", "1. For a given number of grid points $m$, which modes $p$ will be aliased to the $p=0$ mode?\n", "2. What is the highest frequency mode that can be represented on a given grid?" ] } ], "metadata": {} } ] }