{ "cells": [ { "cell_type": "markdown", "metadata": { "nbpages": { "level": 0, "link": "[](https://jckantor.github.io/CBE30338/08.01-Zero-Order-Hold-and-Interpolation.html)", "section": "" } }, "source": [ "\n", "*This notebook contains material from [CBE30338](https://jckantor.github.io/CBE30338);\n", "content is available [on Github](https://github.com/jckantor/CBE30338.git).*\n" ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 0, "link": "[](https://jckantor.github.io/CBE30338/08.01-Zero-Order-Hold-and-Interpolation.html)", "section": "" } }, "source": [ "\n", "< [8.0 Predictive Control](https://jckantor.github.io/CBE30338/08.00-Predictive-Control.html) | [Contents](toc.html) | [Tag Index](tag_index.html) | [9.0 Discrete Events](https://jckantor.github.io/CBE30338/09.00-Discrete-Events.html) >
"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 1,
"link": "[8.1 Zero-Order Hold and Interpolation](https://jckantor.github.io/CBE30338/08.01-Zero-Order-Hold-and-Interpolation.html#8.1-Zero-Order-Hold-and-Interpolation)",
"section": "8.1 Zero-Order Hold and Interpolation"
}
},
"source": [
"# 8.1 Zero-Order Hold and Interpolation\n",
"\n",
"Implementation of control systems generally requires an interface between the sampled data computations of process control and the continuous time dynamics of the real world. A zero-order hold is the most common model for the reconstruction of a continuous time signal from sampled data. "
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 2,
"link": "[8.1.1 Interpolation Function](https://jckantor.github.io/CBE30338/08.01-Zero-Order-Hold-and-Interpolation.html#8.1.1-Interpolation-Function)",
"section": "8.1.1 Interpolation Function"
}
},
"source": [
"## 8.1.1 Interpolation Function"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"nbpages": {
"level": 2,
"link": "[8.1.1 Interpolation Function](https://jckantor.github.io/CBE30338/08.01-Zero-Order-Hold-and-Interpolation.html#8.1.1-Interpolation-Function)",
"section": "8.1.1 Interpolation Function"
}
},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"def interp0(x, xp, yp):\n",
" \"\"\"Zeroth order hold interpolation w/ same\n",
" (base) signature as numpy.interp.\"\"\"\n",
"\n",
" def func(x0):\n",
" if x0 <= xp[0]:\n",
" return yp[0]\n",
" if x0 >= xp[-1]:\n",
" return yp[-1]\n",
" k = 0\n",
" while x0 > xp[k]:\n",
" k += 1\n",
" return yp[k-1]\n",
" \n",
" if isinstance(x,float):\n",
" return func(x)\n",
" elif isinstance(x, list):\n",
" return [func(x) for x in x]\n",
" elif isinstance(x, np.ndarray):\n",
" return np.asarray([func(x) for x in x])\n",
" else:\n",
" raise TypeError('argument must be float, list, or ndarray')"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 2,
"link": "[8.1.2 Demonstration](https://jckantor.github.io/CBE30338/08.01-Zero-Order-Hold-and-Interpolation.html#8.1.2-Demonstration)",
"section": "8.1.2 Demonstration"
}
},
"source": [
"## 8.1.2 Demonstration"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"nbpages": {
"level": 2,
"link": "[8.1.2 Demonstration](https://jckantor.github.io/CBE30338/08.01-Zero-Order-Hold-and-Interpolation.html#8.1.2-Demonstration)",
"section": "8.1.2 Demonstration"
}
},
"outputs": [
{
"data": {
"text/plain": [
"
"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"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.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}