{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# p03: Band-limited interpolation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We will interpolate following functions using band limited interpolation on an infinite grid.\n",
"\n",
"**Delta function**\n",
"\n",
"$$\n",
"v(x) = \\begin{cases}\n",
"1, & x =0 \\\\\n",
"0, & \\textrm{otherwise}\n",
"\\end{cases}\n",
"$$\n",
"\n",
"**Square wave**\n",
"\n",
"$$\n",
"v(x) = \\begin{cases}\n",
"1, & |x| \\le 3 \\\\\n",
"0, & \\textrm{otherwise}\n",
"\\end{cases}\n",
"$$\n",
"\n",
"**Hat function**\n",
"\n",
"$$\n",
"v(x) = \\max(0, 1-|x|/3)\n",
"$$\n",
"\n",
"Since all functions are zero away from origin, we can restrict to some finite interval, say $[-10,10]$."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%config InlineBackend.figure_format='svg'\n",
"from numpy import arange,maximum,abs,zeros,sin,pi\n",
"from matplotlib.pyplot import subplot,figure,plot,grid,axis"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"h = 1.0;\n",
"xmax = 10.0;\n",
"x = arange(-xmax,xmax+h,h)\n",
"xx = arange(-xmax-h/20, xmax+h/20, h/10) # for plotting\n",
"figure(figsize=(10,10))\n",
"for pl in range(3):\n",
" subplot(4,1,pl+1)\n",
" if pl==0:\n",
" v = (x==0) # delta function\n",
" elif pl==1:\n",
" v = (abs(x) <= 3.0) # square wave\n",
" else:\n",
" v = maximum(0.0,1.0-abs(x)/3.0) # hat function\n",
" plot(x,v,'o'); grid(True)\n",
" \n",
" # Evaluate interpolant on xx\n",
" p = zeros(len(xx))\n",
" for i in range(len(x)):\n",
" p = p + v[i]*sin(pi*(xx-x[i])/h)/(pi*(xx-x[i])/h)\n",
" plot(xx,p)\n",
" axis([-xmax,xmax,-0.5,1.5]);"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}