{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\" **Description**\n",
    "\n",
    "    Diamondback is package which provides Digital Signal Processing ( DSP )\n",
    "    solutions, organized in the form of commons, filters, interfaces, models, and\n",
    "    transforms.\n",
    "\n",
    "    Diamondback complements Artificial Intelligence ( AI ) frameworks, by\n",
    "    defining components which analyze, filter, extract, model, and transform\n",
    "    data into forms which are useful in applications including pattern\n",
    "    recognition, feature extraction, and optimization.\n",
    "\n",
    "    Diamondback also facilitates classical signal processing solutions\n",
    "    including communications, modeling, signal identification and extraction,\n",
    "    and noise cancellation.\n",
    "\n",
    "    **License**\n",
    "\n",
    "        `BSD-3C.  <https://github.com/larryturner/diamondback/blob/master/license>`_\n",
    "\n",
    "        © 2018 - 2021 Larry Turner, Schneider Electric Industries SAS. All rights reserved.\n",
    "\n",
    "    **Author**\n",
    "\n",
    "        Larry Turner, Schneider Electric, Analytics & AI, 2018-01-23.\n",
    "\n",
    "    **Definition**\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "import warnings\n",
    "\n",
    "warnings.simplefilter( 'ignore' )\n",
    "\n",
    "%matplotlib inline\n",
    "\n",
    "from diamondback import Log\n",
    "from diamondback import FirFilter, IirFilter, ComplexBandPassFilter, ComplexExponentialFilter\n",
    "from diamondback import ComplexFrequencyFilter, DerivativeFilter, GoertzelFilter, IntegralFilter\n",
    "from diamondback import PolynomialRateFilter, PolyphaseRateFilter, WindowFilter\n",
    "from diamondback import DiversityModel, PrincipalComponentModel\n",
    "from diamondback import ComplexTransform, FourierTransform, PowerSpectrumTransform, WaveletTransform\n",
    "from PIL import Image\n",
    "import ipywidgets\n",
    "import IPython\n",
    "import math\n",
    "import matplotlib    \n",
    "import matplotlib.pyplot\n",
    "import numpy\n",
    "\n",
    "\n",
    "def label( axis : any, title : str = '', x : str = '', y : str = '', grid : bool = True ) -> None :\n",
    "\n",
    "    \"\"\" Label plot title and axes, autoscale, and show grid.\n",
    "    \n",
    "        Arguments :\n",
    "\n",
    "            axis : any.\n",
    "\n",
    "            title : str.\n",
    "            \n",
    "            x : str - x-axis label.\n",
    "            \n",
    "            y : str - y-axis label.\n",
    "            \n",
    "            grid : bool.\n",
    "    \"\"\"\n",
    "\n",
    "    axis.set_xlabel( x )\n",
    "\n",
    "    axis.set_ylabel( y )\n",
    "    \n",
    "    axis.set_title( title )\n",
    "    \n",
    "    axis.grid( grid )\n",
    "\n",
    "    axis.autoscale( enable = True, axis = 'both', tight = True )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Finite\\;Impulse\\;Response\\;Filter.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & y_{n} = \\sum_{i = 0}^{N} b_{i,n} x_{n-i} = \\sum_{i = 1}^{N} b_{i,n} s_{i,n} + b_{0,n} x_{n} \\\\\\\\\n",
       "                                     & s_{1,n+1} = x_{n}\\qquad\\quad s_{i,n+1} = s_{i-1,n} \\\\\\\\\n",
       "                                     & H_{z,n} = \\sum_{i = 0}^{N} b_{i,n} z^{-i}\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Finite\\;Impulse\\;Response\\;Filter.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & y_{n} = \\sum_{i = 0}^{N} b_{i,n} x_{n-i} = \\sum_{i = 1}^{N} b_{i,n} s_{i,n} + b_{0,n} x_{n} \\\\\\\\\n",
    "                                     & s_{1,n+1} = x_{n}\\qquad\\quad s_{i,n+1} = s_{i-1,n} \\\\\\\\\n",
    "                                     & H_{z,n} = \\sum_{i = 0}^{N} b_{i,n} z^{-i}\n",
    "                                     \\end{align}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2e8e66be0aa649deadeb551315372430",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Dropdown(description='Classification', index=2, layout=Layout(width='340px'), options=('…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( classification = ipywidgets.Dropdown( description = 'Classification', value = 'Hann', options = [ 'Blackman', 'Hamming', 'Hann', 'Kaiser' ], layout = { 'width' : '340px' } ),\n",
    "               frequency = ipywidgets.FloatSlider( description = 'Frequency', value = 0.1, min = 0.001, max = 0.999, step = 0.001, readout_format = '0.3f', layout = { 'width' : '420px' } ),\n",
    "               order = ipywidgets.IntSlider( description = 'Order', value = 64, min = 1, max = 4096, step = 1, layout = { 'width' : '420px' } ),\n",
    "               count = ipywidgets.IntSlider( description = 'Count', value = 1, min = 1, max = 16, step = 1, layout = { 'width' : '420px' } ),\n",
    "               complement = ipywidgets.IntSlider( description = 'Complement', value = False, min = False, max = True, layout = { 'width' : '420px' } ) ) :\n",
    "    \n",
    "    \"\"\" Finite Impulse Response Filter.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            classification : str - in ( 'Blackman', 'Hamming', 'Hann', 'Kaiser' ).\n",
    "\n",
    "            frequency : float - relative to Nyquist in ( 0.0, 1.0 ).\n",
    "\n",
    "            order : int.\n",
    "\n",
    "            count : int.\n",
    "\n",
    "            complement : bool.\n",
    "    \"\"\"\n",
    "\n",
    "    try :\n",
    "        \n",
    "        firfilter = FirFilter.Factory.instance( FirFilter, classification, frequency, order, count, complement )\n",
    "\n",
    "    except Exception as ex :\n",
    "        \n",
    "        Log.write( 'ERROR', ex )\n",
    "            \n",
    "        return\n",
    "    \n",
    "    widget = [ ipywidgets.Dropdown( description = r'$\\vec{b_{n}}$', value = str( firfilter.b[ 0 ] ), options = [ str( x ) for x in firfilter.b ], layout = { 'width' : '340px' } ) ]\n",
    "    \n",
    "    display( ipywidgets.VBox( children = widget, layout = ipywidgets.Layout( display = 'flex', flex_flow = 'row' ) ) )\n",
    "    \n",
    "    axis = matplotlib.pyplot.subplots( 2, 2, sharex = False, sharey = False, figsize = ( 18, 18 ) )[ 1 ]\n",
    "    \n",
    "    # Coefficients\n",
    "    \n",
    "    length = 1024\n",
    "    \n",
    "    n = numpy.linspace( 0.0, order, order + 1 )\n",
    "            \n",
    "    axis[ 0, 0 ].plot( n, numpy.zeros( order + 1 ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "        \n",
    "    axis[ 0, 0 ].plot( n, firfilter.b, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )\n",
    "\n",
    "    label( axis[ 0, 0 ], r'$Coefficients$', r'$n$', r'$\\vec{b_{n}}$' )\n",
    "    \n",
    "    # Roots\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    p, z = firfilter.roots( count )\n",
    "    \n",
    "    ii = numpy.where( z.real > 10.0 )[ 0 ]\n",
    "    \n",
    "    z[ ii ] = 10.0 * numpy.sign( z[ ii ].real )\n",
    "\n",
    "    v = numpy.exp( 1j * math.pi * numpy.linspace( 0, 2.0 * math.pi, length ) )\n",
    "    \n",
    "    axis[ 0, 1 ].plot( [ -1.0, 1.0 ], [ 0.0, 0.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 0, 1 ].plot( [ 0.0, 0.0 ], [ -1.0, 1.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 0, 1 ].plot( v.real, v.imag, color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "        \n",
    "    plot.append( axis[ 0, 1 ].plot( p.real, p.imag, linestyle = 'None', marker = '+', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 0, 1 ].plot( z.real, z.imag, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.2, 0.2, 0.8 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    axis[ 0, 1 ].legend( plot, ( r'$\\vec{p_{n}}$', r'$\\vec{z_{n}}$' ), loc = 'upper right' )\n",
    "    \n",
    "    label( axis[ 0, 1 ], r'$Roots$', r'$real$', r'$imag$' )\n",
    "    \n",
    "    # Response\n",
    "    \n",
    "    h, f = firfilter.response( count = count )\n",
    "\n",
    "    h = 20.0 * numpy.log10( numpy.maximum( abs( h ), numpy.finfo( float ).eps ) )\n",
    "\n",
    "    ii, jj, = int( numpy.round( len( h ) // 2 * ( 1.0 - frequency ) ) ), int( numpy.round( len( h ) // 2 * ( 1.0 + frequency ) ) )\n",
    "    \n",
    "    axis[ 1, 0 ].plot( f, -3.0 * numpy.ones( len( h ) ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 1, 0 ].plot( f, h, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 1, 0 ].plot( -frequency, h[ ii ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = 'None', markersize = 8.0 )\n",
    "\n",
    "    axis[ 1, 0 ].plot( frequency, h[ jj ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = 'None', markersize = 8.0 )\n",
    "    \n",
    "    label( axis[ 1, 0 ], r'$Response$', r'$f$', r'$H_{f}\\ dB$' )\n",
    "    \n",
    "    # Delay\n",
    "    \n",
    "    d, f = firfilter.delay( count = count )\n",
    "\n",
    "    d = numpy.round( d * 10.0 ) / 10.0  \n",
    "\n",
    "    axis[ 1, 1 ].plot( -frequency, d[ ii ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = 'None', markersize = 8.0 )\n",
    "    \n",
    "    axis[ 1, 1 ].plot( frequency, d[ jj ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = 'None', markersize = 8.0 )\n",
    "\n",
    "    axis[ 1, 1 ].plot( f, d, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )\n",
    "\n",
    "    label( axis[ 1, 1 ], r'$Delay$', r'$f$', r'$\\tau_{f}\\ n$' )\n",
    "    \n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Infinite\\;Impulse\\;Response\\;Filter.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & y_{n} = \\sum_{i = 1}^{N} a_{i,n} y_{n-i} + \\sum_{i = 0}^{N} b_{i,n} x_{n-i} = \\sum_{i = 1}^{N} (\\ a_{i,n} b_{0,n} + b_{i,n}\\ ) s_{i,n} + b_{0,n} x_{n}\\qquad a_{0,n} = 0 \\\\\\\\\n",
       "                                     & s_{1,n+1} = \\sum_{i = 1}^{N} a_{i,n} s_{i,n} + x_{n}\\qquad\\qquad s_{i,n+1} = s_{i-1,n} \\\\\\\\\n",
       "                                     & H_{z,n} = \\frac{\\sum_{i = 0}^{N} b_{i,n} z^{-i}}{{1 - \\sum_{i = 1}^{N} a_{i,n} z^{-i}}}\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Infinite\\;Impulse\\;Response\\;Filter.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & y_{n} = \\sum_{i = 1}^{N} a_{i,n} y_{n-i} + \\sum_{i = 0}^{N} b_{i,n} x_{n-i} = \\sum_{i = 1}^{N} (\\ a_{i,n} b_{0,n} + b_{i,n}\\ ) s_{i,n} + b_{0,n} x_{n}\\qquad a_{0,n} = 0 \\\\\\\\\n",
    "                                     & s_{1,n+1} = \\sum_{i = 1}^{N} a_{i,n} s_{i,n} + x_{n}\\qquad\\qquad s_{i,n+1} = s_{i-1,n} \\\\\\\\\n",
    "                                     & H_{z,n} = \\frac{\\sum_{i = 0}^{N} b_{i,n} z^{-i}}{{1 - \\sum_{i = 1}^{N} a_{i,n} z^{-i}}}\n",
    "                                     \\end{align}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "06c53d80492847c4ba4382bf53f52f4a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Dropdown(description='Classification', index=1, layout=Layout(width='340px'), options=('…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( classification = ipywidgets.Dropdown( description = 'Classification', value = 'Butterworth', options = [ 'Bessel', 'Butterworth', 'Chebyshev' ], layout = { 'width' : '340px' } ),\n",
    "               frequency = ipywidgets.FloatSlider( description = 'Frequency', value = 0.1, min = 0.001, max = 0.999, step = 0.001, readout_format = '0.3f', layout = { 'width' : '420px' } ),\n",
    "               order = ipywidgets.IntSlider( description = 'Order', value = 6, min = 1, max = 16, step = 1, layout = { 'width' : '420px' } ),\n",
    "               count = ipywidgets.IntSlider( description = 'Count', value = 1, min = 1, max = 16, step = 1, layout = { 'width' : '420px' } ),\n",
    "               complement = ipywidgets.IntSlider( description = 'Complement', value = False, min = False, max = True, layout = { 'width' : '420px' } ) ) :\n",
    "    \n",
    "    \"\"\" Infinite Impulse Response Filter.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            classification : str - in ( 'Bessel', 'Butterworth', 'Chebyshev' ).\n",
    "\n",
    "            frequency : float - relative to Nyquist in ( 0.0, 1.0 ).\n",
    "\n",
    "            order : int.\n",
    "\n",
    "            count : int.\n",
    "\n",
    "            complement : bool.\n",
    "    \"\"\"\n",
    "    \n",
    "    iirfilter = IirFilter.Factory.instance( IirFilter, classification, frequency, order, count, complement )\n",
    "    \n",
    "    widget = [ ipywidgets.Dropdown( description = r'$\\vec{a_{n}}$', value = str( iirfilter.a[ 0 ] ), options = [ str( x ) for x in iirfilter.a ], layout = { 'width' : '340px' } ),\n",
    "               ipywidgets.Dropdown( description = r'$\\vec{b_{n}}$', value = str( iirfilter.b[ 0 ] ), options = [ str( x ) for x in iirfilter.b ], layout = { 'width' : '340px' } ) ]\n",
    "    \n",
    "    display( ipywidgets.VBox( children = widget, layout = ipywidgets.Layout( display = 'flex', flex_flow = 'row' ) ) )\n",
    "    \n",
    "    axis = matplotlib.pyplot.subplots( 2, 2, sharex = False, sharey = False, figsize = ( 18, 18 ) )[ 1 ]\n",
    "    \n",
    "    # Coefficients\n",
    "\n",
    "    plot = [ ]\n",
    "    \n",
    "    length = 1024\n",
    "    \n",
    "    n = numpy.linspace( 0.0, order, order + 1 )    \n",
    "    \n",
    "    axis[ 0, 0 ].plot( n, numpy.zeros( order + 1 ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 0, 0 ].bar( n, iirfilter.a, color = [ 0.8, 0.2, 0.2 ], width = 0.006 * ( order + 1 ) )\n",
    "\n",
    "    axis[ 0, 0 ].bar( n, iirfilter.b, color = [ 0.2, 0.2, 0.8 ], width = 0.006 * ( order + 1 ) )\n",
    "\n",
    "    plot.append( axis[ 0, 0 ].plot( n, iirfilter.a, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 0, 0 ].plot( n, iirfilter.b, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.2, 0.2, 0.8 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "        \n",
    "    axis[ 0, 0 ].legend( plot, ( r'$\\vec{a_{n}}$', r'$\\vec{b_{n}}$' ), loc = 'upper right' )\n",
    "\n",
    "    label( axis[ 0, 0 ], r'$Coefficients$', r'$n$' )\n",
    "    \n",
    "    # Roots\n",
    "\n",
    "    plot = [ ]\n",
    "    \n",
    "    p, z = iirfilter.roots( count )\n",
    "    \n",
    "    ii = numpy.where( z.real > 10.0 )[ 0 ]\n",
    "\n",
    "    z[ ii ] = 10.0 * numpy.sign( z[ ii ].real )\n",
    "        \n",
    "    v = numpy.exp( 1j * math.pi * numpy.linspace( 0, 2.0 * math.pi, length ) )\n",
    "    \n",
    "    axis[ 0, 1 ].plot( [ -1.0, 1.0 ], [ 0.0, 0.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 0, 1 ].plot( [ 0.0, 0.0 ], [ -1.0, 1.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 0, 1 ].plot( v.real, v.imag, color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    plot.append( axis[ 0, 1 ].plot( p.real, p.imag, linestyle = 'None', marker = '+', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 0, 1 ].plot( z.real, z.imag, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.2, 0.2, 0.8 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    axis[ 0, 1 ].legend( plot, ( r'$\\vec{p_{n}}$', r'$\\vec{z_{n}}$' ), loc = 'upper right' )\n",
    "        \n",
    "    label( axis[ 0, 1 ], r'$Roots$', r'$real$', r'$imag$' )\n",
    "    \n",
    "    # Response\n",
    "    \n",
    "    h, f = iirfilter.response( count = count )\n",
    "\n",
    "    h = 20.0 * numpy.log10( numpy.maximum( abs( h ), numpy.finfo( float ).eps ) )\n",
    "\n",
    "    ii, jj, = int( numpy.round( len( h ) // 2 * ( 1.0 - frequency ) ) ), int( numpy.round( len( h ) // 2 * ( 1.0 + frequency ) ) )\n",
    "    \n",
    "    axis[ 1, 0 ].plot( f, -3.0 * numpy.ones( len( h ) ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 1, 0 ].plot( f, h, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 1, 0 ].plot( -frequency, h[ ii ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = 'None', markersize = 8.0 )\n",
    "\n",
    "    axis[ 1, 0 ].plot( frequency, h[ jj ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = 'None', markersize = 8.0 )\n",
    "\n",
    "    label( axis[ 1, 0 ], r'$Response$', r'$f$', r'$H_{f}\\ dB$' )\n",
    "\n",
    "    # Delay\n",
    "    \n",
    "    d, f = iirfilter.delay( count = count )\n",
    "\n",
    "    d = numpy.round( d * 10.0 ) / 10.0  \n",
    "\n",
    "    axis[ 1, 1 ].plot( -frequency, d[ ii ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = 'None', markersize = 8.0 )\n",
    "\n",
    "    axis[ 1, 1 ].plot( frequency, d[ jj ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = 'None', markersize = 8.0 )\n",
    "\n",
    "    axis[ 1, 1 ].plot( f, d, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )\n",
    "\n",
    "    label( axis[ 1, 1 ], r'$Delay$', r'$f$', r'$\\tau_{f}\\ n$' )\n",
    "    \n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Derivative\\;Filter.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & y_{n} = \\sum_{i = 0}^{N} b_{i} x_{n-i} = \\sum_{i = 1}^{N} b_{i} s_{i,n} + b_{0} x_{n} \\\\\\\\\n",
       "                                     & s_{1,n+1} = x_{n}\\qquad\\quad s_{i,n+1} = s_{i-1,n} \\\\\\\\\n",
       "                                     & H_{z} = \\sum_{i = 0}^{N} b_{i} z^{-i} \\\\\\\\\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\\\\\\\\\scriptsize{\\begin{align}\n",
       "                                                   & b_{1,1} = \\lgroup\\matrix{ 1 & -1 }\\rgroup \\\\\\\\\n",
       "                                                   & b_{1,2} = \\lgroup\\matrix{ 1 & 0 & -1 }\\rgroup(\\ \\frac{1}{2}\\ ) && b_{2,2} = \\lgroup\\matrix{ 1 & -2 & 1 }\\rgroup \\\\\\\\\n",
       "                                                   & b_{1,4} = \\lgroup\\matrix{ -1 & 8 & 0 & -8 & 1 }\\rgroup(\\ \\frac{1}{12}\\ ) && b_{2,4} = \\lgroup\\matrix{ 1 & 0 & -2 & 0 & 1 }\\rgroup(\\ \\frac{1}{4}\\ ) && b_{3,4} = \\lgroup\\matrix{ 1 & -2 & 0 & 2 & -1 }\\rgroup \\\\\\\\\n",
       "                                                   && & b_{2,6} = \\lgroup\\matrix{ -1 & 8 & 1 & -16 & 1 & 8 & -1 }\\rgroup(\\ \\frac{1}{24}\\ ) && b_{3,6} = \\lgroup\\matrix{ 1 & 0 & -3 & 0 & 3 & 0 & 1 }\\rgroup(\\ \\frac{1}{8}\\ ) \\\\\\\\\n",
       "                                                   && & b_{2,8} = \\lgroup\\matrix{ 1 & -16 & 64 & 16 & -130 & 16 & 64 & -16 & 1 }\\rgroup(\\ \\frac{1}{144}\\ ) && b_{3,8} = \\lgroup\\matrix{ -1 & 8 & 2 & -24 & 0 & 24 & -2 & -8 & 1 }\\rgroup(\\ \\frac{1}{48}\\ )\n",
       "                                                   \\end{align}}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Derivative\\;Filter.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & y_{n} = \\sum_{i = 0}^{N} b_{i} x_{n-i} = \\sum_{i = 1}^{N} b_{i} s_{i,n} + b_{0} x_{n} \\\\\\\\\n",
    "                                     & s_{1,n+1} = x_{n}\\qquad\\quad s_{i,n+1} = s_{i-1,n} \\\\\\\\\n",
    "                                     & H_{z} = \\sum_{i = 0}^{N} b_{i} z^{-i} \\\\\\\\\n",
    "                                     \\end{align}\"\"\" ) )\n",
    "\n",
    "display( IPython.display.Math( r\"\"\"\\\\\\\\\\scriptsize{\\begin{align}\n",
    "                                                   & b_{1,1} = \\lgroup\\matrix{ 1 & -1 }\\rgroup \\\\\\\\\n",
    "                                                   & b_{1,2} = \\lgroup\\matrix{ 1 & 0 & -1 }\\rgroup(\\ \\frac{1}{2}\\ ) && b_{2,2} = \\lgroup\\matrix{ 1 & -2 & 1 }\\rgroup \\\\\\\\\n",
    "                                                   & b_{1,4} = \\lgroup\\matrix{ -1 & 8 & 0 & -8 & 1 }\\rgroup(\\ \\frac{1}{12}\\ ) && b_{2,4} = \\lgroup\\matrix{ 1 & 0 & -2 & 0 & 1 }\\rgroup(\\ \\frac{1}{4}\\ ) && b_{3,4} = \\lgroup\\matrix{ 1 & -2 & 0 & 2 & -1 }\\rgroup \\\\\\\\\n",
    "                                                   && & b_{2,6} = \\lgroup\\matrix{ -1 & 8 & 1 & -16 & 1 & 8 & -1 }\\rgroup(\\ \\frac{1}{24}\\ ) && b_{3,6} = \\lgroup\\matrix{ 1 & 0 & -3 & 0 & 3 & 0 & 1 }\\rgroup(\\ \\frac{1}{8}\\ ) \\\\\\\\\n",
    "                                                   && & b_{2,8} = \\lgroup\\matrix{ 1 & -16 & 64 & 16 & -130 & 16 & 64 & -16 & 1 }\\rgroup(\\ \\frac{1}{144}\\ ) && b_{3,8} = \\lgroup\\matrix{ -1 & 8 & 2 & -24 & 0 & 24 & -2 & -8 & 1 }\\rgroup(\\ \\frac{1}{48}\\ )\n",
    "                                                   \\end{align}}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "20d5580659d9401586e2561fc0dde3ae",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatRangeSlider(value=(-0.05, 0.1), description='Incident', layout=Layout(width='420px'…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( incident = ipywidgets.FloatRangeSlider( description = 'Incident', value = [ -0.05, 0.1 ], min = -1.0, max = 0.99, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               noise = ipywidgets.FloatSlider( description = 'Noise', value = 0.0, min = 0.0, max = 0.5, step = 0.01, layout = { 'width' : '420px' } ),               \n",
    "               derivative = ipywidgets.IntSlider( description = 'Derivative', value = 1, min = 1, max = 3, step = 1, layout = { 'width' : '420px' } ),\n",
    "               order = ipywidgets.IntSlider( description = 'Order', value = 2, min = 0, max = 8, step = 2, layout = { 'width' : '420px' } ) ) :\n",
    "    \n",
    "    \"\"\" Derivative Filter.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            incident : float - incident signal frequency [ epoch, terminus ] relative to Nyquist in [ -1.0, 1.0 ).\n",
    "\n",
    "            noise : float - incident signal deviation.\n",
    "            \n",
    "            derivative : int.\n",
    "\n",
    "            order : int.\n",
    "    \"\"\"\n",
    "    \n",
    "    order = int( max( min( order, 2.0 ** ( derivative + 1 ) ), 2.0 ** ( derivative - 1 ) ) )\n",
    "\n",
    "    derivativefilter = DerivativeFilter.Factory.instance( DerivativeFilter, derivative, order )\n",
    "    \n",
    "    widget = [ ipywidgets.Dropdown( description = r'$\\vec{b_{n}}$', value = str( derivativefilter.b[ 0 ] ), options = [ str( x ) for x in derivativefilter.b ], layout = { 'width' : '340px' } ) ]\n",
    "    \n",
    "    display( ipywidgets.VBox( children = widget, layout = ipywidgets.Layout( display = 'flex', flex_flow = 'row' ) ) )\n",
    "        \n",
    "    axis = matplotlib.pyplot.subplots( 2, 2, sharex = False, sharey = False, figsize = ( 18, 18 ) )[ 1 ]\n",
    "\n",
    "    # Coefficients\n",
    "    \n",
    "    phase, length = numpy.random.rand( 1 )[ 0 ] - 0.5, 1024\n",
    "    \n",
    "    n = numpy.linspace( 0.0, order, order + 1 )\n",
    "    \n",
    "    axis[ 0, 0 ].plot( n, numpy.zeros( order + 1 ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "        \n",
    "    axis[ 0, 0 ].bar( n, derivativefilter.b, color = [ 0.2, 0.2, 0.8 ], width = 0.006 * ( order + 1 ) )\n",
    "\n",
    "    axis[ 0, 0 ].plot( n, derivativefilter.b, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.2, 0.2, 0.8 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )\n",
    "\n",
    "    label( axis[ 0, 0 ], r'$Coefficients$', r'$n$', r'$\\vec{b_{n}}$' )\n",
    "    \n",
    "    # Roots\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    p, z = derivativefilter.roots( )\n",
    "    \n",
    "    v = numpy.exp( 1j * math.pi * numpy.linspace( 0, 2.0 * math.pi, length ) )\n",
    "    \n",
    "    axis[ 0, 1 ].plot( [ -1.0, 1.0 ], [ 0.0, 0.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 0, 1 ].plot( [ 0.0, 0.0 ], [ -1.0, 1.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 0, 1 ].plot( v.real, v.imag, color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    plot.append( axis[ 0, 1 ].plot( p.real, p.imag, linestyle = 'None', marker = '+', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 0, 1 ].plot( z.real, z.imag, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.2, 0.2, 0.8 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    axis[ 0, 1 ].legend( plot, ( r'$\\vec{p_{n}}$', r'$\\vec{z_{n}}$' ), loc = 'upper right' )\n",
    "        \n",
    "    label( axis[ 0, 1 ], r'$Roots$', r'$real$', r'$imag$' )\n",
    "    \n",
    "    # Response\n",
    "    \n",
    "    h, f = derivativefilter.response( )\n",
    "\n",
    "    h = 20.0 * numpy.log10( numpy.maximum( abs( h ), numpy.finfo( float ).eps ) )\n",
    "\n",
    "    axis[ 1, 0 ].plot( f, -3.0 * numpy.ones( len( h ) ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 1, 0 ].plot( f, h, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 1, 0 ].plot( numpy.linspace( incident[ 0 ], incident[ 1 ], length ), numpy.zeros( length ), color = [ 0.0, 0.0, 0.0 ], linewidth = 8.0 )\n",
    "        \n",
    "    label( axis[ 1, 0 ], r'$Response$', r'$f$', r'$H_{f}\\ dB$' )\n",
    "    \n",
    "    # Filter\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    length = 1024\n",
    "        \n",
    "    x = ComplexExponentialFilter( phase ).filter( numpy.linspace( incident[ 0 ], incident[ 1 ], length ) ).real\n",
    " \n",
    "    q = numpy.random.rand( len( x ) ) - 0.5\n",
    "        \n",
    "    x += q * noise / q.std( )\n",
    "\n",
    "    y = derivativefilter.filter( x )\n",
    "        \n",
    "    n = numpy.linspace( 0, length - 1, length )\n",
    "    \n",
    "    plot.append( axis[ 1, 1 ].plot( n, x, color = [ 0.0, 0.0, 0.0 ], linewidth = 1.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 1, 1 ].plot( n, y, color = [ 0.2, 0.2, 0.8 ], linewidth = 1.0 )[ 0 ] )\n",
    "\n",
    "    axis[ 1, 1 ].legend( plot, ( r'$x_{n}$', r'$y_{n}$' ), loc = 'upper right' )\n",
    "\n",
    "    label( axis[ 1, 1 ], r'$Filter$', r'$n$' )\n",
    "\n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Integral\\;Filter.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & y_{n} = \\sum_{i = 1}^{N} a_{i} y_{n-i} + \\sum_{i = 0}^{N} b_{i} x_{n-i} = \\sum_{i = 1}^{N} (\\ a_{i} b_{0} + b_{i}\\ ) s_{i,n} + b_{0} x_{n}\\qquad a_{0} = 0 \\\\\\\\\n",
       "                                     & s_{1,n+1} = \\sum_{i = 1}^{N} a_{i} s_{i,n} + x_{n}\\qquad\\quad s_{i,n+1} = s_{i-1,n} \\\\\\\\\n",
       "                                     & H_{z} = \\frac{\\sum_{i = 0}^{N} b_{i} z^{-i}}{{1 - \\sum_{i = 1}^{N} a_{i} z^{-i}}} \\\\\\\\\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\\\\\\\\\scriptsize{\\begin{align}\n",
       "                                                   & a_{1,0} = \\lgroup\\matrix{ 0 & 1 }\\rgroup && b_{1,0} = \\lgroup\\matrix{ 1 }\\rgroup \\\\\\\\\n",
       "                                                   & a_{1,1} = \\lgroup\\matrix{ 0 & 1 }\\rgroup && b_{1,1} = \\lgroup\\matrix{ 1 & 1 }\\rgroup(\\ \\frac{1}{2}\\ ) \\\\\\\\\n",
       "                                                   & a_{1,2} = \\lgroup\\matrix{ 0 & 1 }\\rgroup && b_{1,2} = \\lgroup\\matrix{ 1 & 4 & 1 }\\rgroup(\\ \\frac{1}{6}\\ ) \\\\\\\\\n",
       "                                                   & a_{1,3} = \\lgroup\\matrix{ 0 & 1 }\\rgroup && b_{1,3} = \\lgroup\\matrix{ 1 & 3 & 3 & 1 }\\rgroup(\\ \\frac{1}{8}\\ ) \\\\\\\\\n",
       "                                                   & a_{1,4} = \\lgroup\\matrix{ 0 & 1 }\\rgroup && b_{1,4} = \\lgroup\\matrix{ 7 & 32 & 12 & 32 & 7 }\\rgroup(\\ \\frac{1}{90}\\ )\n",
       "                                                   \\end{align}}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Integral\\;Filter.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & y_{n} = \\sum_{i = 1}^{N} a_{i} y_{n-i} + \\sum_{i = 0}^{N} b_{i} x_{n-i} = \\sum_{i = 1}^{N} (\\ a_{i} b_{0} + b_{i}\\ ) s_{i,n} + b_{0} x_{n}\\qquad a_{0} = 0 \\\\\\\\\n",
    "                                     & s_{1,n+1} = \\sum_{i = 1}^{N} a_{i} s_{i,n} + x_{n}\\qquad\\quad s_{i,n+1} = s_{i-1,n} \\\\\\\\\n",
    "                                     & H_{z} = \\frac{\\sum_{i = 0}^{N} b_{i} z^{-i}}{{1 - \\sum_{i = 1}^{N} a_{i} z^{-i}}} \\\\\\\\\n",
    "                                     \\end{align}\"\"\" ) )\n",
    "\n",
    "display( IPython.display.Math( r\"\"\"\\\\\\\\\\scriptsize{\\begin{align}\n",
    "                                                   & a_{1,0} = \\lgroup\\matrix{ 0 & 1 }\\rgroup && b_{1,0} = \\lgroup\\matrix{ 1 }\\rgroup \\\\\\\\\n",
    "                                                   & a_{1,1} = \\lgroup\\matrix{ 0 & 1 }\\rgroup && b_{1,1} = \\lgroup\\matrix{ 1 & 1 }\\rgroup(\\ \\frac{1}{2}\\ ) \\\\\\\\\n",
    "                                                   & a_{1,2} = \\lgroup\\matrix{ 0 & 1 }\\rgroup && b_{1,2} = \\lgroup\\matrix{ 1 & 4 & 1 }\\rgroup(\\ \\frac{1}{6}\\ ) \\\\\\\\\n",
    "                                                   & a_{1,3} = \\lgroup\\matrix{ 0 & 1 }\\rgroup && b_{1,3} = \\lgroup\\matrix{ 1 & 3 & 3 & 1 }\\rgroup(\\ \\frac{1}{8}\\ ) \\\\\\\\\n",
    "                                                   & a_{1,4} = \\lgroup\\matrix{ 0 & 1 }\\rgroup && b_{1,4} = \\lgroup\\matrix{ 7 & 32 & 12 & 32 & 7 }\\rgroup(\\ \\frac{1}{90}\\ )\n",
    "                                                   \\end{align}}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "36cb540ad95343cc9f65443e5a5d49fb",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatRangeSlider(value=(-0.05, 0.1), description='Incident', layout=Layout(width='420px'…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( incident = ipywidgets.FloatRangeSlider( description = 'Incident', value = [ -0.05, 0.1 ], min = -1.0, max = 0.99, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               noise = ipywidgets.FloatSlider( description = 'Noise', value = 0.0, min = 0.0, max = 0.5, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               order = ipywidgets.IntSlider( description = 'Order', value = 1, min = 0, max = 4, step = 1, layout = { 'width' : '420px' } ) ) :\n",
    "    \n",
    "    \"\"\" Integral Filter.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            incident : float - incident signal frequency [ epoch, terminus ] relative to Nyquist in [ -1.0, 1.0 ).\n",
    "\n",
    "            noise : float - incident signal deviation.\n",
    "            \n",
    "            order : int.\n",
    "    \"\"\"\n",
    "    \n",
    "    integralfilter = IntegralFilter.Factory.instance( IntegralFilter, order )\n",
    "    \n",
    "    widget = [ ipywidgets.Dropdown( description = r'$\\vec{a_{n}}$', value = str( integralfilter.a[ 0 ] ), options = [ str( x ) for x in integralfilter.a ], layout = { 'width' : '340px' } ),\n",
    "               ipywidgets.Dropdown( description = r'$\\vec{b_{n}}$', value = str( integralfilter.b[ 0 ] ), options = [ str( x ) for x in integralfilter.b ], layout = { 'width' : '340px' } ) ]\n",
    "    \n",
    "    display( ipywidgets.VBox( children = widget, layout = ipywidgets.Layout( display = 'flex', flex_flow = 'row' ) ) )\n",
    "    \n",
    "    axis = matplotlib.pyplot.subplots( 2, 2, sharex = False, sharey = False, figsize = ( 18, 18 ) )[ 1 ]\n",
    "    \n",
    "    # Coefficients\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    phase, length = numpy.random.rand( 1 )[ 0 ] - 0.5, 1024\n",
    "\n",
    "    n = numpy.linspace( 0.0, max( order, 1 ), max( order, 1 ) + 1 )\n",
    "        \n",
    "    axis[ 0, 0 ].plot( n, numpy.zeros( order + 1 ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "        \n",
    "    axis[ 0, 0 ].bar( n, integralfilter.a, color = [ 0.8, 0.2, 0.2 ], width = 0.006 * ( order + 1 ) )\n",
    "\n",
    "    axis[ 0, 0 ].bar( n, integralfilter.b, color = [ 0.2, 0.2, 0.8 ], width = 0.006 * ( order + 1 ) )\n",
    "    \n",
    "    plot.append( axis[ 0, 0 ].plot( n, integralfilter.a, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 0, 0 ].plot( n, integralfilter.b, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.2, 0.2, 0.8 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "    \n",
    "    axis[ 0, 0 ].legend( plot, ( r'$\\vec{a_{n}}$', r'$\\vec{b_{n}}$' ), loc = 'upper right' )\n",
    "\n",
    "    label( axis[ 0, 0 ], r'$Coefficients$', r'$n$' )\n",
    "\n",
    "    # Roots\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    p, z = integralfilter.roots( )\n",
    "    \n",
    "    v = numpy.exp( 1j * math.pi * numpy.linspace( 0, 2.0 * math.pi, length ) )\n",
    "    \n",
    "    axis[ 0, 1 ].plot( [ -1.0, 1.0 ], [ 0.0, 0.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 0, 1 ].plot( [ 0.0, 0.0 ], [ -1.0, 1.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 0, 1 ].plot( v.real, v.imag, color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    plot.append( axis[ 0, 1 ].plot( p.real, p.imag, linestyle = 'None', marker = '+', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 0, 1 ].plot( z.real, z.imag, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.2, 0.2, 0.8 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    axis[ 0, 1 ].legend( plot, ( r'$\\vec{p_{n}}$', r'$\\vec{z_{n}}$' ), loc = 'upper right' )\n",
    "        \n",
    "    label( axis[ 0, 1 ], r'$Roots$', r'$real$', r'$imag$' )\n",
    "        \n",
    "    # Response\n",
    "    \n",
    "    h, f = integralfilter.response( )\n",
    "    \n",
    "    h = 20.0 * numpy.log10( numpy.maximum( abs( h ), numpy.finfo( float ).eps ) )\n",
    "\n",
    "    axis[ 1, 0 ].plot( f, -3.0 * numpy.ones( len( h ) ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 1, 0 ].plot( f, h, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 1, 0 ].plot( numpy.linspace( incident[ 0 ], incident[ 1 ], length ), numpy.zeros( length ), color = [ 0.0, 0.0, 0.0 ], linewidth = 8.0 )\n",
    "    \n",
    "    label( axis[ 1, 0 ], r'$Response$', r'$f$', r'$H_{f}\\ dB$' )\n",
    "    \n",
    "    # Filter\n",
    "\n",
    "    plot = [ ]\n",
    "    \n",
    "    length = 1024\n",
    "        \n",
    "    x = ComplexExponentialFilter( phase ).filter( numpy.linspace( incident[ 0 ], incident[ 1 ], length ) ).real\n",
    "     \n",
    "    q = numpy.random.rand( len( x ) ) - 0.5\n",
    "        \n",
    "    x += q * noise / q.std( )\n",
    "\n",
    "    y = integralfilter.filter( x )\n",
    "        \n",
    "    n = numpy.linspace( 0, length - 1, length )\n",
    "    \n",
    "    plot.append( axis[ 1, 1 ].plot( n, x, color = [ 0.0, 0.0, 0.0 ], linewidth = 1.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 1, 1 ].plot( n, y, color = [ 0.2, 0.2, 0.8 ], linewidth = 1.0 )[ 0 ] )\n",
    "\n",
    "    axis[ 1, 1 ].legend( plot, ( r'$x_{n}$', r'$y_{n}$' ), loc = 'upper right' )\n",
    "\n",
    "    label( axis[ 1, 1 ], r'$Filter$', r'$n$' )\n",
    "\n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Polynomial\\;Rate\\;Filter.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Polynomial\\;Rate\\;Filter.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     \\end{align}\"\"\" ) )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "713b3d3ef3c3430290c3787ff74bd1c1",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatRangeSlider(value=(0.0, 0.1), description='Incident', layout=Layout(width='420px'),…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( incident = ipywidgets.FloatRangeSlider( description = 'Incident', value = [ 0.0, 0.1 ], min = -1.0, max = 0.99, step = 0.01, readout_format = '0.2f', layout = { 'width' : '420px' } ),\n",
    "               noise = ipywidgets.FloatSlider( description = 'Noise', value = 0.0, min = 0.0, max = 0.5, step = 0.01, layout = { 'width' : '420px' } ),               \n",
    "               rate = ipywidgets.FloatSlider( description = 'Rate', value = 1.0, min = 0.01, max = 256.0, step = 0.01, layout = { 'width' : '420px' } ) ) :\n",
    "\n",
    "    \"\"\" Polynomial Rate Filter.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            incident : float - incident signal frequency [ epoch, terminus ] relative to Nyquist in [ -1.0, 1.0 ).\n",
    "\n",
    "            noise : float - noise deviation of incident signal.\n",
    "            \n",
    "            rate : float - ratio of effective frequency in [ 1.0, inf ).\n",
    "    \"\"\"\n",
    "    \n",
    "    axis = matplotlib.pyplot.subplots( 1, 2, sharex = False, sharey = False, figsize = ( 36, 9 ) )[ 1 ]\n",
    "\n",
    "    # Filter\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    ratefilter = PolynomialRateFilter( rate )\n",
    "    \n",
    "    frequency, phase, length = 0.85, numpy.random.rand( 1 )[ 0 ] - 0.5, 1024\n",
    "    \n",
    "    x = ComplexExponentialFilter( phase ).filter( numpy.linspace( incident[ 0 ], incident[ 1 ], length ) ).real\n",
    "\n",
    "    q = numpy.random.rand( len( x ) ) - 0.5\n",
    "        \n",
    "    x += q * noise / q.std( )\n",
    "    \n",
    "    y = ratefilter.filter( x )\n",
    "\n",
    "    plot.append( axis[ 0 ].plot( numpy.linspace( 0, len( x ) - 1, len( x ) ), x, color = [ 0.0, 0.0, 0.0 ], linewidth = 1.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 0 ].plot( numpy.linspace( 0, len( y ) - 1, len( y ) ), y, color = [ 0.2, 0.2, 0.8 ], linewidth = 1.0 )[ 0 ] )\n",
    "    \n",
    "    axis[ 0 ].legend( plot, ( r'$x_{n}$', r'$y_{n}$' ), loc = 'upper right' )\n",
    "\n",
    "    label( axis[ 0 ], r'$Filter$', r'$n$' )\n",
    "\n",
    "    axis[ 1 ].set_visible( False )\n",
    "    \n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Polyphase\\;Rate\\;Filter.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & b_{k,i} = b^{M}[\\ k (\\ N\\ +\\ 1\\ )\\ +\\ i\\ ] \\qquad\\qquad\\qquad\\qquad\\qquad\\qquad k\\ :\\ [\\ 0,\\ K\\sim 256\\ )\\qquad\\ i\\ :\\ [\\ 0,\\ N\\sim 15 \\ ] \\\\\\\\\n",
       "                                     & y_{n} = \\sum_{i = 0}^{N} b_{k_{n},i}\\ x_{n-i} = \\sum_{i = 1}^{N} b_{k_{n},i}\\ s_{i,n} + b_{k_{n},0}\\ x_{n} \\\\\\\\\n",
       "                                     & s_{1,n+1} = x_{n}\\qquad\\ s_{i,n+1} = s_{i-1,n} \\\\\\\\                                    \n",
       "                                     & \\phi_{n+1,Rate} = \\phi_{n,Rate}\\ +\\ \\frac{K}{\\scriptsize{Rate}} \\\\\\\\\n",
       "                                     & \\phi_{n+1,Rate}\\ \\geq\\ K\\qquad\\longrightarrow\\qquad \\phi_{n+1,Rate} = \\phi_{n+1,Rate}\\ -\\ K \\\\\\\\\n",
       "                                     & k_{n+1} = \\mod( \\left\\lfloor{\\ k_{n}\\ +\\ \\phi_{n+1,Rate}}\\right\\rfloor,\\ M\\ )\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Polyphase\\;Rate\\;Filter.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & b_{k,i} = b^{M}[\\ k (\\ N\\ +\\ 1\\ )\\ +\\ i\\ ] \\qquad\\qquad\\qquad\\qquad\\qquad\\qquad k\\ :\\ [\\ 0,\\ K\\sim 256\\ )\\qquad\\ i\\ :\\ [\\ 0,\\ N\\sim 15 \\ ] \\\\\\\\\n",
    "                                     & y_{n} = \\sum_{i = 0}^{N} b_{k_{n},i}\\ x_{n-i} = \\sum_{i = 1}^{N} b_{k_{n},i}\\ s_{i,n} + b_{k_{n},0}\\ x_{n} \\\\\\\\\n",
    "                                     & s_{1,n+1} = x_{n}\\qquad\\ s_{i,n+1} = s_{i-1,n} \\\\\\\\                                    \n",
    "                                     & \\phi_{n+1,Rate} = \\phi_{n,Rate}\\ +\\ \\frac{K}{\\scriptsize{Rate}} \\\\\\\\\n",
    "                                     & \\phi_{n+1,Rate}\\ \\geq\\ K\\qquad\\longrightarrow\\qquad \\phi_{n+1,Rate} = \\phi_{n+1,Rate}\\ -\\ K \\\\\\\\\n",
    "                                     & k_{n+1} = \\mod( \\left\\lfloor{\\ k_{n}\\ +\\ \\phi_{n+1,Rate}}\\right\\rfloor,\\ M\\ )\n",
    "                                     \\end{align}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "895c365677b0419ea904f25894db9006",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatRangeSlider(value=(0.0, 0.1), description='Incident', layout=Layout(width='420px'),…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( incident = ipywidgets.FloatRangeSlider( description = 'Incident', value = [ 0.0, 0.1 ], min = -1.0, max = 0.99, step = 0.01, readout_format = '0.2f', layout = { 'width' : '420px' } ),\n",
    "               noise = ipywidgets.FloatSlider( description = 'Noise', value = 0.0, min = 0.0, max = 0.5, step = 0.01, layout = { 'width' : '420px' } ),               \n",
    "               rate = ipywidgets.FloatSlider( description = 'Rate', value = 1.0, min = 0.01, max = 256.0, step = 0.01, layout = { 'width' : '420px' } ) ) :\n",
    "\n",
    "    \"\"\" Polyphase Rate Filter.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            incident : float - incident signal frequency [ epoch, terminus ] relative to Nyquist in [ -1.0, 1.0 ).\n",
    "\n",
    "            noise : float - incident signal deviation.\n",
    "            \n",
    "            rate : float - ratio of effective frequency in ( 0.0, 256.0 ].\n",
    "    \"\"\"\n",
    "    \n",
    "    ratefilter = PolyphaseRateFilter( rate )\n",
    "    \n",
    "    widget = [ ipywidgets.Dropdown( description = 'Index', value = str( ratefilter.b.shape[ 0 ] / rate ), options = [ str( ratefilter.b.shape[ 0 ] / rate ) ], layout = { 'width' : '340px' } ),\n",
    "               ipywidgets.Dropdown( description = 'Order', value = str( ratefilter.b.shape[ 0 ] ), options = [ str( ratefilter.b.shape[ 0 ] ), str( ratefilter.b.shape[ 1 ] ) ], layout = { 'width' : '340px' } ) ]\n",
    "    \n",
    "    display( ipywidgets.VBox( children = widget, layout = ipywidgets.Layout( display = 'flex', flex_flow = 'row' ) ) )\n",
    "        \n",
    "    axis = matplotlib.pyplot.subplots( 2, 2, sharex = False, sharey = False, figsize = ( 18, 18 ) )[ 1 ]\n",
    "\n",
    "    # Coefficients\n",
    "    \n",
    "    frequency, phase, length = 0.85, numpy.random.rand( 1 )[ 0 ] - 0.5, 1024\n",
    "       \n",
    "    n = numpy.linspace( 0.0, ratefilter.b.shape[ 1 ] - 1, ratefilter.b.shape[ 1 ] )\n",
    "        \n",
    "    axis[ 0, 0 ].plot( n, numpy.zeros( ratefilter.b.shape[ 1 ] ), color = [ 0.0, 0.0, 0.0 ], linewidth = 0.5 )\n",
    "          \n",
    "    for ii in range( 0, ratefilter.b.shape[ 0 ], 4 ) :\n",
    "    \n",
    "        axis[ 0, 0 ].plot( n, ratefilter.b[ ii, : ], color = [ 0.2, 0.2, 0.8 ], linewidth = 0.25 )\n",
    "                \n",
    "    label( axis[ 0, 0 ], r'$Coefficients$', r'$n$', r'$\\vec{b_{n}}$' )\n",
    "    \n",
    "    # Filter\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    x = ComplexExponentialFilter( phase ).filter( numpy.linspace( incident[ 0 ], incident[ 1 ], length ) ).real\n",
    "\n",
    "    q = numpy.random.rand( len( x ) ) - 0.5\n",
    "        \n",
    "    x += q * noise / q.std( )\n",
    "    \n",
    "    y = ratefilter.filter( x )\n",
    "        \n",
    "    plot.append( axis[ 0, 1 ].plot( numpy.linspace( 0, len( x ) - 1, len( x ) ), x, color = [ 0.0, 0.0, 0.0 ], linewidth = 1.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 0, 1 ].plot( numpy.linspace( 0, len( y ) - 1, len( y ) ), y, color = [ 0.2, 0.2, 0.8 ], linewidth = 1.0 )[ 0 ] )\n",
    "    \n",
    "    axis[ 0, 1 ].legend( plot, ( r'$x_{n}$', r'$y_{n}$' ), loc = 'upper right' )\n",
    "\n",
    "    label( axis[ 0, 1 ], r'$Filter$', r'$n$' )\n",
    "\n",
    "    for ii in range( 0, ratefilter.b.shape[ 0 ], 2 ) :\n",
    "    \n",
    "        firfilter = FirFilter( ratefilter.b[ ii, : ] );\n",
    "        \n",
    "        h, f = firfilter.response( )\n",
    "\n",
    "        h = 20.0 * numpy.log10( numpy.maximum( abs( h ), numpy.finfo( float ).eps ) )\n",
    "\n",
    "        ii, jj, = int( numpy.round( len( h ) // 2 * ( 1.0 - frequency ) ) ), int( numpy.round( len( h ) // 2 * ( 1.0 + frequency ) ) )\n",
    "    \n",
    "        axis[ 1, 0 ].plot( f, h, color = [ 0.2, 0.2, 0.8 ], linewidth = 0.25 )\n",
    "    \n",
    "        d, f = firfilter.delay( )\n",
    "\n",
    "        d = numpy.maximum( numpy.minimum( d, ratefilter.b.shape[ 1 ] // 2 + 0.6 ), ratefilter.b.shape[ 1 ] // 2 - 0.6 )\n",
    "\n",
    "        axis[ 1, 1 ].plot( f, d, 'b', linewidth = 0.25 )        \n",
    "        \n",
    "    axis[ 1, 0 ].plot( f, -3.0 * numpy.ones( len( h ) ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 1, 0 ].plot( -frequency, h[ ii ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = 'None', markersize = 8.0 )\n",
    "\n",
    "    axis[ 1, 0 ].plot( frequency, h[ jj ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = 'None', markersize = 8.0 )\n",
    "    \n",
    "    axis[ 1, 0 ].plot( numpy.linspace( incident[ 0 ], incident[ 1 ], length ), numpy.zeros( length ), color = [ 0.0, 0.0, 0.0 ], linewidth = 8.0 )\n",
    "        \n",
    "    label( axis[ 1, 0 ], r'$Response$', r'$f$', r'$H_{f}\\ dB$' )\n",
    "    \n",
    "    label( axis[ 1, 1 ], r'$Delay$', r'$f$', r'$\\tau_{f}\\ n$' )\n",
    "            \n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Complex\\;Transform.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & \\gamma = \\left\\lgroup\\matrix{ 1 & \\frac{-1}{2} & \\frac{-1}{2}\\cr 0 & \\frac{3^{0.5}}{2} & \\frac{-3^{0.5}}{2}\\cr 1 & 1 & 1 }\\right\\rgroup && \\alpha = \\lgroup\\matrix{\\frac{1}{3}}\\rgroup^{0.5}\\ e^{\\ -j\\ \\frac{\\pi}{6}\\ } \\\\\\\\\n",
       "                                     & \\scriptsize{Three-Phase\\longrightarrow\\ Complex} \\\\\\\\\n",
       "                                     & y_{n} = \\lgroup\\matrix{ x^{T}_{n}\\ \\gamma\\ }\\rgroup \\lgroup\\matrix{ 1 & j & 0 }\\rgroup^{T} \\\\\\\\\n",
       "                                     & \\overline{\\scriptsize{Neutral}}\\ \\qquad\\longrightarrow\\qquad y_{n} = y_{n}\\ \\alpha \\\\\\\\\n",
       "                                     & \\scriptsize{Complex\\longrightarrow\\ Three-Phase} \\\\\\\\                                     \n",
       "                                     & \\overline{\\scriptsize{Neutral}}\\ \\qquad\\longrightarrow\\qquad x_{n} = \\frac{x_{n}}{\\alpha} \\\\\\\\\n",
       "                                     & y_{n} = \\lgroup\\matrix{\\ \\lgroup\\matrix{ \\gamma^{T}\\gamma }\\rgroup^{-1}\\ \\gamma^{T}\\lgroup\\matrix{ real(\\ x_{n}\\ ) & imag(\\ x_{n}\\ ) & 0 }\\rgroup^{T}}\\rgroup^{T} \\\\\\\\\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Complex\\;Transform.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & \\gamma = \\left\\lgroup\\matrix{ 1 & \\frac{-1}{2} & \\frac{-1}{2}\\cr 0 & \\frac{3^{0.5}}{2} & \\frac{-3^{0.5}}{2}\\cr 1 & 1 & 1 }\\right\\rgroup && \\alpha = \\lgroup\\matrix{\\frac{1}{3}}\\rgroup^{0.5}\\ e^{\\ -j\\ \\frac{\\pi}{6}\\ } \\\\\\\\\n",
    "                                     & \\scriptsize{Three-Phase\\longrightarrow\\ Complex} \\\\\\\\\n",
    "                                     & y_{n} = \\lgroup\\matrix{ x^{T}_{n}\\ \\gamma\\ }\\rgroup \\lgroup\\matrix{ 1 & j & 0 }\\rgroup^{T} \\\\\\\\\n",
    "                                     & \\overline{\\scriptsize{Neutral}}\\ \\qquad\\longrightarrow\\qquad y_{n} = y_{n}\\ \\alpha \\\\\\\\\n",
    "                                     & \\scriptsize{Complex\\longrightarrow\\ Three-Phase} \\\\\\\\                                     \n",
    "                                     & \\overline{\\scriptsize{Neutral}}\\ \\qquad\\longrightarrow\\qquad x_{n} = \\frac{x_{n}}{\\alpha} \\\\\\\\\n",
    "                                     & y_{n} = \\lgroup\\matrix{\\ \\lgroup\\matrix{ \\gamma^{T}\\gamma }\\rgroup^{-1}\\ \\gamma^{T}\\lgroup\\matrix{ real(\\ x_{n}\\ ) & imag(\\ x_{n}\\ ) & 0 }\\rgroup^{T}}\\rgroup^{T} \\\\\\\\\n",
    "                                     \\end{align}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c6a737d113b447b39a83123241926e12",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatRangeSlider(value=(-0.05, 0.05), description='Incident', layout=Layout(width='420px…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( incident = ipywidgets.FloatRangeSlider( description = 'Incident', value = [ -0.05, 0.05 ], min = -1.0, max = 0.99, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               noise = ipywidgets.FloatSlider( description = 'Noise', value = 0.0, min = 0.0, max = 0.5, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               neutral = ipywidgets.IntSlider( description = 'Neutral', value = True, min = False, max = True, layout = { 'width' : '420px' } ),\n",
    "               inverse = ipywidgets.IntSlider( description = 'Inverse', value = False, min = False, max = True, layout = { 'width' : '420px' } ) ) :\n",
    "\n",
    "    \"\"\" Complex Transform.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            incident : float - incident signal frequency [ epoch, terminus ] relative to Nyquist in [ -1.0, 1.0 ).\n",
    "\n",
    "            noise : float - incident signal deviation.\n",
    "            \n",
    "            neutral : bool.\n",
    "            \n",
    "            inverse : bool.\n",
    "    \"\"\"\n",
    "    \n",
    "    axis = matplotlib.pyplot.subplots( 1, 2, sharex = False, sharey = False, figsize = ( 18, 9 ) )[ 1 ]\n",
    "\n",
    "    # Incident, Transform\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    phase, length = numpy.random.rand( 1 )[ 0 ] - 0.5, 1024\n",
    "    \n",
    "    x = ComplexExponentialFilter( phase ).filter( numpy.linspace( incident[ 0 ], incident[ 1 ], length ) )\n",
    " \n",
    "    q = numpy.random.rand( len( x ) ) - 0.5 + 1j * ( numpy.random.rand( len( x ) ) - 0.5 )\n",
    "    \n",
    "    x += q * noise / q.std( )\n",
    "    \n",
    "    n = numpy.linspace( 0.0, length - 1, length )\n",
    "     \n",
    "    v = ComplexTransform.transform( x, neutral )\n",
    "\n",
    "    epoch, terminus, ii, jj = r'$Incident$', r'$Transform$', 0, 1\n",
    "    \n",
    "    if ( inverse ) :\n",
    "        \n",
    "        x = ComplexTransform.transform( v, neutral )\n",
    "    \n",
    "        epoch, terminus, ii, jj = r'$Transform$', r'$Incident$', 1, 0\n",
    "    \n",
    "    plot.append( axis[ ii ].plot( n, v[ 0, : ], color = [ 0.0, 0.0, 0.0 ], linewidth = 1.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ ii ].plot( n, v[ 1, : ], color = [ 0.2, 0.2, 0.8 ], linewidth = 1.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ ii ].plot( n, v[ 2, : ], color = [ 0.8, 0.2, 0.2 ], linewidth = 1.0 )[ 0 ] )\n",
    "    \n",
    "    axis[ ii ].legend( plot, ( r'$x_{0,n}$', r'$x_{1,n}$', r'$x_{2,n}$' ), loc = 'upper right' )\n",
    "\n",
    "    label( axis[ ii ], epoch, r'$n$' )\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    v = numpy.exp( 1j * math.pi * numpy.linspace( 0, 2.0 * math.pi, length ) )\n",
    "    \n",
    "    axis[ jj ].plot( [ -1.0, 1.0 ], [ 0.0, 0.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ jj ].plot( [ 0.0, 0.0 ], [ -1.0, 1.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ jj ].plot( v.real, v.imag, color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ jj ].plot( x.real, x.imag, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )\n",
    "      \n",
    "    plot.append( axis[ jj ].plot( x[ 0 ].real, x[ 0 ].imag, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ jj ].plot( x[ -1 ].real, x[ -1 ].imag, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.0, 0.0, 0.0 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    axis[ jj ].legend( plot, ( r'$x_{0}$', r'$x_{N-1}$' ), loc = 'upper right' )\n",
    "    \n",
    "    label( axis[ jj ], terminus, r'$real$', r'$imag$' )\n",
    "    \n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Complex\\;Bandpass\\;Filter.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & x_{n} = e^{\\ j\\ \\pi\\ \\phi_{n}} \\\\\\\\\n",
       "                                     & \\phi_{n+1} = \\phi_{n} + f_{n} \\\\\\\\\n",
       "                                     & y_{n} = b_{n} x_{n} \\\\\\\\\n",
       "                                     & e_{n} = d_{n} - y_{n} \\\\\\\\\n",
       "                                     & b_{n+1} = b_{n} + \\mu e_{n} x_{n}^{*}\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Complex\\;Bandpass\\;Filter.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & x_{n} = e^{\\ j\\ \\pi\\ \\phi_{n}} \\\\\\\\\n",
    "                                     & \\phi_{n+1} = \\phi_{n} + f_{n} \\\\\\\\\n",
    "                                     & y_{n} = b_{n} x_{n} \\\\\\\\\n",
    "                                     & e_{n} = d_{n} - y_{n} \\\\\\\\\n",
    "                                     & b_{n+1} = b_{n} + \\mu e_{n} x_{n}^{*}\n",
    "                                     \\end{align}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "fcb6315a482f466c8cba4295c7adc6fd",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatRangeSlider(value=(0.1, 0.1), description='Incident', layout=Layout(width='420px'),…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( incident = ipywidgets.FloatRangeSlider( description = 'Incident', value = [ 0.1, 0.1 ], min = -1.0, max = 0.99, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               noise = ipywidgets.FloatSlider( description = 'Noise', value = 0.0, min = 0.0, max = 0.5, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               frequency = ipywidgets.FloatSlider( description = 'Frequency', value = 0.1, min = -1.0, max = 0.999, step = 0.001, readout_format = '0.3f', layout = { 'width' : '420px' } ),\n",
    "               rate = ipywidgets.FloatSlider( description = 'Rate', value = 0.01, min = 0.0001, max = 1.0, step = 0.0001, readout_format = '0.4f', layout = { 'width' : '420px' } ) ) :\n",
    "\n",
    "    \"\"\" Complex Bandpass Filter.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            incident : float - incident signal frequency [ epoch, terminus ] relative to Nyquist in [ -1.0, 1.0 ).\n",
    "\n",
    "            noise : float - incident signal deviation.\n",
    "\n",
    "            frequency : float - relative to Nyquist in [ -1.0, 1.0 ).\n",
    "\n",
    "            rate : float.\n",
    "    \"\"\"\n",
    "    \n",
    "    axis = matplotlib.pyplot.subplots( 2, 2, sharex = False, sharey = False, figsize = ( 18, 18 ) )[ 1 ]\n",
    "\n",
    "    # Coefficients\n",
    "    \n",
    "    complexbandpassfilter = ComplexBandPassFilter( frequency, rate )\n",
    "        \n",
    "    phase, count, length = numpy.random.rand( 1 )[ 0 ] - 0.5, 128, 1024\n",
    "    \n",
    "    x = ComplexExponentialFilter( phase ).filter( numpy.linspace( incident[ 0 ], incident[ 1 ], length ) )\n",
    "      \n",
    "    q = numpy.random.rand( len( x ) ) - 0.5 + 1j * ( numpy.random.rand( len( x ) ) - 0.5 )\n",
    "        \n",
    "    x += q * noise / q.std( )\n",
    "        \n",
    "    y, e, b = complexbandpassfilter.filter( x )\n",
    "    \n",
    "    n = numpy.linspace( 0.0, length - 1, length )\n",
    "            \n",
    "    axis[ 0, 0 ].plot( n, numpy.zeros( length ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 0, 0 ].plot( n, b.real, color = [ 0.2, 0.2, 0.8 ], linewidth = 1.0 )\n",
    "\n",
    "    axis[ 0, 0 ].plot( n, b.imag, color = [ 0.2, 0.2, 0.8 ], linewidth = 1.0 )\n",
    "    \n",
    "    axis[ 0, 0 ].plot( n, abs( b ), color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )\n",
    "\n",
    "    label( axis[ 0, 0 ], r'$Coefficients$', r'$n$', r'$b_{n}$' )\n",
    "\n",
    "    # Coefficients\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    v = numpy.exp( 1j * math.pi * numpy.linspace( 0, 2.0 * math.pi, length ) )\n",
    "    \n",
    "    axis[ 0, 1 ].plot( [ -1.0, 1.0 ], [ 0.0, 0.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 0, 1 ].plot( [ 0.0, 0.0 ], [ -1.0, 1.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 0, 1 ].plot( v.real, v.imag, color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 0, 1 ].plot( b.real, b.imag, linestyle = 'None', marker = 'o', markeredgecolor = 'None', markeredgewidth = 2.0, markerfacecolor = [ 0.2, 0.2, 0.8 ], markersize = 4.0 )\n",
    "    \n",
    "    plot.append( axis[ 0, 1 ].plot( b[ 0 ].real, b[ 0 ].imag, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.2, 0.2, 0.8 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 0, 1 ].plot( b[ -1 ].real, b[ -1 ].imag, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.0, 0.0, 0.0 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "                \n",
    "    axis[ 0, 1 ].legend( plot, ( r'$b_{0}$', r'$b_{N-1}$' ), loc = 'upper right' )    \n",
    "    \n",
    "    label( axis[ 0, 1 ], r'$Coefficients$', r'$real$', r'$imag$' )\n",
    "    \n",
    "    # Response\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    h, f = numpy.zeros( count ), numpy.linspace( max( incident[ 0 ] - 0.05, -1.0 ), min( incident[ 1 ] + 0.05, 1.0 - 2.0 / count ), count )\n",
    "    \n",
    "    for ii in range( 0, len( f ) ) :\n",
    "    \n",
    "        u = ComplexExponentialFilter( phase ).filter( numpy.ones( length ) * f[ ii ] )\n",
    "\n",
    "        complexbandpassfilter.reset( 0.0 )\n",
    "        \n",
    "        v = complexbandpassfilter.filter( u )[ 0 ]\n",
    "        \n",
    "        h[ ii ] = min( numpy.mean( abs( v[ -32 : -1 ] ) ), 1.0 )\n",
    "        \n",
    "    h, k = 20.0 * numpy.log10( numpy.maximum( abs( h ), numpy.finfo( float ).eps ) ), 20.0 * numpy.log10( numpy.maximum( abs( 1.0 - h ), numpy.finfo( float ).eps ) )\n",
    "        \n",
    "    axis[ 1, 0 ].plot( f, -3.0 * numpy.ones( len( h ) ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    plot.append( axis[ 1, 0 ].plot( f, h, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 1, 0 ].plot( f, k, color = [ 0.8, 0.2, 0.2 ], linewidth = 2.0 )[ 0 ] )\n",
    "\n",
    "    axis[ 1, 0 ].plot( numpy.linspace( incident[ 0 ], incident[ 1 ], length ), numpy.zeros( length ), color = [ 0.0, 0.0, 0.0 ], linewidth = 8.0 )    \n",
    "        \n",
    "    axis[ 1, 0 ].legend( plot, ( r'$y_{f}$', r'$e_{f}$' ), loc = 'upper right' )\n",
    "    \n",
    "    label( axis[ 1, 0 ], r'$Response$', r'$f$', r'$H_{f}\\ dB$' )\n",
    "    \n",
    "    # Filter\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    axis[ 1, 1 ].plot( n, x.real, color = [ 0.0, 0.0, 0.0 ], linewidth = 1.0 )\n",
    "\n",
    "    axis[ 1, 1 ].plot( n, y.real, color = [ 0.2, 0.2, 0.8 ], linewidth = 1.0 )\n",
    "    \n",
    "    axis[ 1, 1 ].plot( n, e.real, color = [ 0.8, 0.2, 0.2 ], linewidth = 1.0 )\n",
    "\n",
    "    plot.append( axis[ 1, 1 ].plot( n, abs( x ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 1, 1 ].plot( n, abs( y ), color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )[ 0 ] )\n",
    "    \n",
    "    plot.append( axis[ 1, 1 ].plot( n, abs( e ), color = [ 0.8, 0.2, 0.2 ], linewidth = 2.0 )[ 0 ] )\n",
    "        \n",
    "    axis[ 1, 1 ].legend( plot, ( r'$H_{x,f}$', r'$H_{y,f}$', r'$H_{e,f}$' ), loc = 'upper right' )\n",
    "\n",
    "    label( axis[ 1, 1 ], r'$Filter$', r'$n$' )\n",
    "\n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Complex\\;Frequency\\;Filter.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & f_{n} = \\frac{\\tan^{-1}(\\ b_{n}\\ ) }{\\pi} \\\\\\\\\n",
       "                                     & x_{n} = \\frac{d_{n}}{|\\ d_{n}\\ |} \\\\\\\\\n",
       "                                     & y_{n} = b_{n} x_{n-1} \\\\\\\\\n",
       "                                     & e_{n} = d_{n} - y_{n} \\\\\\\\\n",
       "                                     & b_{0} = e^{\\ j\\ \\pi\\ f_{0}} \\\\\\\\\n",
       "                                     & b_{n} = b_{n} + \\mu e_{n} x_{n}^{*} \\\\\\\\\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Complex\\;Frequency\\;Filter.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & f_{n} = \\frac{\\tan^{-1}(\\ b_{n}\\ ) }{\\pi} \\\\\\\\\n",
    "                                     & x_{n} = \\frac{d_{n}}{|\\ d_{n}\\ |} \\\\\\\\\n",
    "                                     & y_{n} = b_{n} x_{n-1} \\\\\\\\\n",
    "                                     & e_{n} = d_{n} - y_{n} \\\\\\\\\n",
    "                                     & b_{0} = e^{\\ j\\ \\pi\\ f_{0}} \\\\\\\\\n",
    "                                     & b_{n} = b_{n} + \\mu e_{n} x_{n}^{*} \\\\\\\\\n",
    "                                     \\end{align}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "629654a1302b4282bbba0afa0e348404",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatRangeSlider(value=(-0.25, 0.75), description='Incident', layout=Layout(width='420px…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( incident = ipywidgets.FloatRangeSlider( description = 'Incident', value = [ -0.25, 0.75 ], min = -1.0, max = 0.99, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               noise = ipywidgets.FloatSlider( description = 'Noise', value = 0.0, min = 0.0, max = 0.5, step = 0.01, layout = { 'width' : '420px' } ),               \n",
    "               frequency = ipywidgets.FloatSlider( description = 'Frequency', value = 0.0, min = -1.0, max = 0.999, step = 0.001, readout_format = '0.3f', layout = { 'width' : '420px' } ),\n",
    "               rate = ipywidgets.FloatSlider( description = 'Rate', value = 0.25, min = 0.001, max = 1.0, step = 0.001, readout_format = '0.3f', layout = { 'width' : '420px' } ) ) :\n",
    "\n",
    "    \"\"\" Complex Frequency Filter.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            incident : float - incident signal frequency [ epoch, terminus ] relative to Nyquist in [ -1.0, 1.0 ).\n",
    "\n",
    "            noise : float - incident signal deviation.\n",
    "\n",
    "            frequency : float - relative to Nyquist in [ -1.0, 1.0 ).\n",
    "\n",
    "            rate : float.\n",
    "    \"\"\"\n",
    "   \n",
    "    axis = matplotlib.pyplot.subplots( 1, 2, sharex = False, sharey = False, figsize = ( 18, 9 ) )[ 1 ]\n",
    "\n",
    "    # Coefficients\n",
    " \n",
    "    plot = [ ]\n",
    "    \n",
    "    complexfrequencyfilter = ComplexFrequencyFilter( frequency, rate )\n",
    "        \n",
    "    phase, length = numpy.random.rand( 1 )[ 0 ] - 0.5, 1024\n",
    "    \n",
    "    f = numpy.linspace( incident[ 0 ], incident[ 1 ], length )\n",
    "    \n",
    "    x = ComplexExponentialFilter( phase ).filter( f )\n",
    "\n",
    "    q = numpy.random.rand( len( x ) ) - 0.5 + 1j * ( numpy.random.rand( len( x ) ) - 0.5 )\n",
    "        \n",
    "    x += q * noise / q.std( )\n",
    "    \n",
    "    y, e, b = complexfrequencyfilter.filter( x )\n",
    "    \n",
    "    n = numpy.linspace( 0.0, length - 1, length )\n",
    "       \n",
    "    v = numpy.exp( 1j * math.pi * numpy.linspace( 0, 2.0 * math.pi, length ) )\n",
    "    \n",
    "    axis[ 0 ].plot( [ -1.0, 1.0 ], [ 0.0, 0.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 0 ].plot( [ 0.0, 0.0 ], [ -1.0, 1.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 0 ].plot( v.real, v.imag, color = [ 0.0, 0.0, 0.0 ], linewidth = 0.5 )\n",
    "    \n",
    "    axis[ 0 ].plot( b.real, b.imag, linestyle = 'None', marker = 'o', markeredgecolor = 'None', markeredgewidth = 2.0, markerfacecolor = [ 0.2, 0.2, 0.8 ], markersize = 4.0 )\n",
    "      \n",
    "    plot.append( axis[ 0 ].plot( b[ 0 ].real, b[ 0 ].imag, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.0, 0.0, 0.0 ], markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 0 ].plot( b[ -1 ].real, b[ -1 ].imag, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.0, 0.0, 0.0 ], markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    axis[ 0 ].legend( plot, ( r'$b_0$', r'$b_{N-1}$' ), loc = 'upper right' )\n",
    "    \n",
    "    label( axis[ 0 ], r'$Coefficients$', r'$real$', r'$imag$' )\n",
    "    \n",
    "    # Filter\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    axis[ 1 ].plot( n, numpy.maximum( numpy.minimum( e.real, 1.0 ), -1.0 ), color = [ 0.8, 0.2, 0.2 ], linewidth = 1.0 )\n",
    "    \n",
    "    plot.append( axis[ 1 ].plot( n, f, color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )[ 0 ] )\n",
    "    \n",
    "    plot.append( axis[ 1 ].plot( n, y, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )[ 0 ] )\n",
    " \n",
    "    plot.append( axis[ 1 ].plot( n, abs( e ), color = [ 0.8, 0.2, 0.2 ], linewidth = 2.0 )[ 0 ] )\n",
    "        \n",
    "    axis[ 1 ].legend( plot, ( r'$f_{x,n}$', r'$y_n$', r'$e_n$' ), loc = 'upper right' )\n",
    "\n",
    "    label( axis[ 1 ], r'$Filter$', r'$n$', r'$f_n$' )\n",
    "\n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Fourier\\;Transform,\\;Power\\;Spectrum\\;Transform,\\;Window\\;Filter.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & y_{k} = \\frac{1}{N}\\ \\sum_{n = 0}^{N-1} b_{n} x_{n} e^{\\frac{\\ -j\\ \\pi\\ k \\ n}{N}} && v_{i,k} = \\frac{1}{N}\\ \\sum_{n = 0}^{N-1} b_{n} x_{n+i\\ I} e^{ \\frac{\\ -j\\ \\pi\\ k \\ n}{N} } && y^{P}_{k} = \\frac{1}{C}\\ \\sum_{i = 0}^{C-1} v_{i,k} v^{*}_{i,k} \\\\\\\\\n",
       "                                     & x_{n} = \\frac{N}{b_{n}}\\ \\sum_{k = 0}^{N-1} y_{k} e^{\\frac{\\ j\\ \\pi\\ k \\ n}{N}}  && n, k \\in [\\ 0,\\ N\\ )\\\\\\\\\n",
       "                                     & f_{k} = -1\\ + \\ 2\\ \\frac{k}{N}\\\\\\\\\n",
       "                                     & N = \\frac{2}{R}\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Fourier\\;Transform,\\;Power\\;Spectrum\\;Transform,\\;Window\\;Filter.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & y_{k} = \\frac{1}{N}\\ \\sum_{n = 0}^{N-1} b_{n} x_{n} e^{\\frac{\\ -j\\ \\pi\\ k \\ n}{N}} && v_{i,k} = \\frac{1}{N}\\ \\sum_{n = 0}^{N-1} b_{n} x_{n+i\\ I} e^{ \\frac{\\ -j\\ \\pi\\ k \\ n}{N} } && y^{P}_{k} = \\frac{1}{C}\\ \\sum_{i = 0}^{C-1} v_{i,k} v^{*}_{i,k} \\\\\\\\\n",
    "                                     & x_{n} = \\frac{N}{b_{n}}\\ \\sum_{k = 0}^{N-1} y_{k} e^{\\frac{\\ j\\ \\pi\\ k \\ n}{N}}  && n, k \\in [\\ 0,\\ N\\ )\\\\\\\\\n",
    "                                     & f_{k} = -1\\ + \\ 2\\ \\frac{k}{N}\\\\\\\\\n",
    "                                     & N = \\frac{2}{R}\n",
    "                                     \\end{align}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "8b85047195f94bb5855ff262abbc9749",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatRangeSlider(value=(0.1, 0.1), description='Incident', layout=Layout(width='420px'),…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( incident = ipywidgets.FloatRangeSlider( description = 'Incident', value = [ 0.1, 0.1 ], min = -1.0, max = 0.99, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               noise = ipywidgets.FloatSlider( description = 'Noise', value = 0.01, min = 0.0, max = 0.5, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               classification = ipywidgets.Dropdown( description = 'Classification', value = 'Hann', options = [ 'Blackman', 'Hamming', 'Hann', 'Kaiser' ], layout = { 'width' : '340px' } ),\n",
    "               order = ipywidgets.IntSlider( description = 'Order', value = 1023, min = 1, max = 4096, step = 1, layout = { 'width' : '420px' } ),\n",
    "               normal = ipywidgets.IntSlider( description = 'Normal', value = True, min = False, max = True, layout = { 'width' : '420px' } ),              \n",
    "               index = ipywidgets.IntSlider( description = 'Index', value = 64, min = 1, max = 4096, step = 1, layout = { 'width' : '420px' } ) ) :\n",
    "\n",
    "    \"\"\" Fourier Transform, Power Spectrum Transform, Window Filter.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            incident : float - incident signal frequency [ epoch, terminus ] relative to Nyquist in [ -1.0, 1.0 ).\n",
    "\n",
    "            noise : float - incident signal deviation.\n",
    "\n",
    "            classification : str - in ( 'Blackman', 'Hamming', 'Hann', 'Kaiser' ).\n",
    "\n",
    "            normal : bool.\n",
    "\n",
    "            index : int.\n",
    "    \"\"\"\n",
    "    \n",
    "    index = int( min( index, order + 1 ) )\n",
    "    \n",
    "    windowfilter = WindowFilter.Factory.instance( WindowFilter, classification, order, normal )\n",
    "\n",
    "    indexfilter = WindowFilter.Factory.instance( WindowFilter, classification, order // 2, normal )\n",
    "\n",
    "    widget = [ ipywidgets.Dropdown( description = r'$\\vec{b_{n}}$', value = str( windowfilter.b[ 0 ] ), options = [ str( x ) for x in windowfilter.b ], layout = { 'width' : '340px' } ) ]\n",
    "    \n",
    "    display( ipywidgets.VBox( children = widget, layout = ipywidgets.Layout( display = 'flex', flex_flow = 'row' ) ) )\n",
    "\n",
    "    axis = matplotlib.pyplot.subplots( 1, 2, sharex = False, sharey = False, figsize = ( 18, 9 ) )[ 1 ]\n",
    "\n",
    "    # Filter\n",
    "\n",
    "    plot = [ ]\n",
    "    \n",
    "    phase, length = numpy.random.rand( 1 )[ 0 ] - 0.5, order + 1\n",
    "        \n",
    "    x = ComplexExponentialFilter( phase ).filter( numpy.linspace( incident[ 0 ], incident[ 1 ], length ) )\n",
    " \n",
    "    q = numpy.random.rand( len( x ) ) - 0.5 + 1j * ( numpy.random.rand( len( x ) ) - 0.5 )\n",
    "    \n",
    "    x += q * noise / q.std( )\n",
    "    \n",
    "    n = numpy.linspace( 0.0, length - 1, length )\n",
    "\n",
    "    h, f = FourierTransform.transform( x, windowfilter.b, False )\n",
    "    \n",
    "    k, g = PowerSpectrumTransform.transform( x, indexfilter.b, index )\n",
    "\n",
    "    h, k = 20.0 * numpy.log10( numpy.maximum( abs( h ), numpy.finfo( float ).eps ) ), 20.0 * numpy.log10( numpy.maximum( abs( k ), numpy.finfo( float ).eps ) )\n",
    "    \n",
    "    axis[ 0 ].plot( n, numpy.zeros( order + 1 ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    plot.append( axis[ 0 ].plot( n, windowfilter.b, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )[ 0 ] ) \n",
    "\n",
    "    plot.append( axis[ 0 ].plot( n, ( windowfilter.b * x ).real, color = [ 0.2, 0.2, 0.8 ], linewidth = 1.0 )[ 0 ] ) \n",
    "    \n",
    "    axis[ 0 ].plot( n, ( windowfilter.b * x ).imag, color = [ 0.2, 0.2, 0.8 ], linewidth = 1.0 ) \n",
    "    \n",
    "    axis[ 0 ].legend( plot, ( r'$\\vec{b_{n}}$', r'$x_{n}$' ), loc = 'upper right' )\n",
    "    \n",
    "    label( axis[ 0 ], r'$Filter$', r'$n$' )\n",
    "\n",
    "    # Transform\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    axis[ 1 ].plot( f, -3.0 * numpy.ones( len( h ) ), 'k' )\n",
    "    \n",
    "    plot.append( axis[ 1 ].plot( f, h, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 1 ].plot( g, k, color = [ 0.8, 0.2, 0.2 ], linewidth = 2.0 )[ 0 ] )\n",
    "    \n",
    "    axis[ 1 ].plot( numpy.linspace( incident[ 0 ], incident[ 1 ], length ), numpy.zeros( length ), color = [ 0.0, 0.0, 0.0 ], linewidth = 8.0 )    \n",
    "        \n",
    "    axis[ 1 ].legend( plot, ( r'$H^{F}_{x,f}$', r'$H^{P}_{x,f}$' ), loc = 'upper right' )\n",
    "    \n",
    "    label( axis[ 1 ], r'$Transform$', r'$f$', r'$H_{f}\\ dB$' )\n",
    "    \n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Goertzel\\;Filter,\\;Window\\;Filter.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & y_{n} = \\sum_{i = 1}^{N} a_{i} y_{n-i} + \\sum_{i = 0}^{N} b_{i} x_{n-i} = \\sum_{i = 1}^{N} (\\ a_{i} b_{0} + b_{i}\\ ) s_{i,n} + b_{0} x_{n}\\qquad a_{0} = 0 \\\\\\\\\n",
       "                                     & s_{1,n+1} = \\sum_{i = 1}^{N} a_{i} s_{i,n} + x_{n}\\qquad\\quad s_{i,n+1} = s_{i-1,n} \\\\\\\\\n",
       "                                     & H_{z} = \\frac{\\sum_{i = 0}^{N} b_{i} z^{-i}}{{1 - \\sum_{i = 1}^{N} a_{i} z^{-i}}} \\\\\\\\\n",
       "                                     & N = \\frac{2}{R} \\\\\\\\\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\\\\\\\\\scriptsize{\\begin{align}\n",
       "                                                   & a = \\lgroup\\matrix{ 0 & 2\\ \\cos(\\ \\pi\\ f\\ ) & -1 }\\rgroup && b = \\lgroup\\matrix{ 1 & -e^{\\ j\\ \\pi\\ f\\ } & 0 }\\rgroup \\\\\\\\\n",
       "                                                   \\end{align}}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Goertzel\\;Filter,\\;Window\\;Filter.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & y_{n} = \\sum_{i = 1}^{N} a_{i} y_{n-i} + \\sum_{i = 0}^{N} b_{i} x_{n-i} = \\sum_{i = 1}^{N} (\\ a_{i} b_{0} + b_{i}\\ ) s_{i,n} + b_{0} x_{n}\\qquad a_{0} = 0 \\\\\\\\\n",
    "                                     & s_{1,n+1} = \\sum_{i = 1}^{N} a_{i} s_{i,n} + x_{n}\\qquad\\quad s_{i,n+1} = s_{i-1,n} \\\\\\\\\n",
    "                                     & H_{z} = \\frac{\\sum_{i = 0}^{N} b_{i} z^{-i}}{{1 - \\sum_{i = 1}^{N} a_{i} z^{-i}}} \\\\\\\\\n",
    "                                     & N = \\frac{2}{R} \\\\\\\\\n",
    "                                     \\end{align}\"\"\" ) )\n",
    "\n",
    "display( IPython.display.Math( r\"\"\"\\\\\\\\\\scriptsize{\\begin{align}\n",
    "                                                   & a = \\lgroup\\matrix{ 0 & 2\\ \\cos(\\ \\pi\\ f\\ ) & -1 }\\rgroup && b = \\lgroup\\matrix{ 1 & -e^{\\ j\\ \\pi\\ f\\ } & 0 }\\rgroup \\\\\\\\\n",
    "                                                   \\end{align}}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d2efb2f551fc44b280b6a948a4fe98a1",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatRangeSlider(value=(-0.1, 0.15), description='Incident', layout=Layout(width='420px'…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( incident = ipywidgets.FloatRangeSlider( description = 'Incident', value = [ -0.1, 0.15 ], min = -1.0, max = 0.99, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               noise = ipywidgets.FloatSlider( description = 'Noise', value = 0.0, min = 0.0, max = 0.5, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               classification = ipywidgets.Dropdown( description = 'Classification', value = 'Hann', options = [ 'Blackman', 'Hamming', 'Hann', 'Kaiser' ], layout = { 'width' : '340px' } ),\n",
    "               order = ipywidgets.IntSlider( description = 'Order', value = 1023, min = 1, max = 4096, step = 1, layout = { 'width' : '420px' } ),\n",
    "               normal = ipywidgets.IntSlider( description = 'Normal', value = True, min = False, max = True, layout = { 'width' : '420px' } ),\n",
    "               frequency = ipywidgets.FloatSlider( description = 'Frequency', value = 0.1, min = -1.0, max = 0.999, step = 0.001, readout_format = '0.3f', layout = { 'width' : '420px' } ) ) :\n",
    "\n",
    "    \"\"\" Goertzel Filter, Window Filter.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            incident : float - incident signal frequency [ epoch, terminus ] relative to Nyquist in [ -1.0, 1.0 ).\n",
    "\n",
    "            noise : float - incident signal deviation.\n",
    "\n",
    "            order : int.\n",
    "            \n",
    "            normal : bool.\n",
    "            \n",
    "            frequency : float - relative to Nyquist in [ -1.0, 1.0 ).\n",
    "    \"\"\"\n",
    "    \n",
    "    windowfilter = WindowFilter.Factory.instance( WindowFilter, classification, order, normal )\n",
    "\n",
    "    goertzelfilter = GoertzelFilter( windowfilter.b, frequency )\n",
    "    \n",
    "    widget = [ ipywidgets.Dropdown( description = r'$\\vec{a_{n}}$', value = str( goertzelfilter.a[ 0 ] ), options = [ str( x ) for x in goertzelfilter.a ], layout = { 'width' : '340px' } ),\n",
    "               ipywidgets.Dropdown( description = r'$\\vec{b_{n}}$', value = str( goertzelfilter.b[ 0 ] ), options = [ str( x ) for x in goertzelfilter.b ], layout = { 'width' : '340px' } ) ]\n",
    "    \n",
    "    display( ipywidgets.VBox( children = widget, layout = ipywidgets.Layout( display = 'flex', flex_flow = 'row' ) ) )\n",
    "\n",
    "    axis = matplotlib.pyplot.subplots( 1, 2, sharex = False, sharey = False, figsize = ( 18, 9 ) )[ 1 ]\n",
    "\n",
    "    # Incident\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    phase, length = numpy.random.rand( 1 )[ 0 ] - 0.5, ( order + 1 ) * 32\n",
    "    \n",
    "    f = numpy.linspace( incident[ 0 ], incident[ 1 ], length )\n",
    "    \n",
    "    x = ComplexExponentialFilter( phase ).filter( f )\n",
    " \n",
    "    q = numpy.random.rand( len( x ) ) - 0.5 + 1j * ( numpy.random.rand( len( x ) ) - 0.5 )\n",
    "    \n",
    "    x += q * noise / q.std( )\n",
    "    \n",
    "    h = goertzelfilter.filter( x )\n",
    "    \n",
    "    h = 20.0 * numpy.log10( numpy.maximum( abs( h ), numpy.finfo( float ).eps ) )\n",
    "    \n",
    "    n = numpy.linspace( 0.0, len( h ) - 1, len( h ) )\n",
    "     \n",
    "    v = numpy.exp( 1j * math.pi * numpy.linspace( 0, 2.0 * math.pi, length ) )\n",
    "    \n",
    "    axis[ 0 ].plot( [ -1.0, 1.0 ], [ 0.0, 0.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 0 ].plot( [ 0.0, 0.0 ], [ -1.0, 1.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 0 ].plot( v.real, v.imag, color = [ 0.0, 0.0, 0.0 ], linewidth = 1.0 )\n",
    "    \n",
    "    axis[ 0 ].plot( x.real, x.imag, color = [ 0.2, 0.2, 0.8 ], linewidth = 1.0 )\n",
    "      \n",
    "    plot.append( axis[ 0 ].plot( x[ 0 ].real, x[ 0 ].imag, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 0 ].plot( x[ -1 ].real, x[ -1 ].imag, linestyle = 'None', marker = 'o', markeredgecolor = [ 0.0, 0.0, 0.0 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "            \n",
    "    axis[ 0 ].legend( plot, ( r'$x_{0}$', r'$x_{N-1}$' ), loc = 'upper right' )\n",
    "    \n",
    "    label( axis[ 0 ], r'$Incident$', r'$real$', r'$imag$' )\n",
    "\n",
    "    # Filter\n",
    "    \n",
    "    axis[ 1 ].plot( n, h, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )\n",
    "\n",
    "    label( axis[ 1 ], r'$Filter$', r'$n$', r'$H_{f,n}\\ dB$' )\n",
    "    \n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Diversity\\;Model.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & d_{u,v} = \\left\\{\\begin{array} & \\qquad\\max(\\ |\\ \\vec{x_{u}} - \\vec{x_{v}}\\ |\\ ) && Chebyshev\\qquad\\cr\\cr\\cr \\qquad\\lgroup\\matrix{\\sum_{i=0}^{N}(\\ \\vec{x_{u,i}} - \\vec{x_{v,i}}\\ )^2}\\rgroup^{0.5} && Euclidean\\qquad\\cr\\cr\\cr\\qquad\\prod_{i=0}^{N}{(\\ |\\ \\vec{x_{u,i}} - \\vec{x_{v,i}}\\ |\\ )}^{\\frac{1}{N}} && Geometric\\qquad\\cr\\cr\\cr\\qquad\\sum_{i=0}^{N}{\\ (\\ |\\ \\vec{x_{u}} - \\vec{x_{v}}\\ |\\ )\\ } && Manhattan\\qquad \\end{array}\\right. \\\\\\\\\n",
       "                                     & d_{k} = \\min(\\ d_{u,v}\\ ) & u, v \\in [\\ 0,\\ M\\ ),\\ u \\neq v \\\\\\\\\n",
       "                                     & d_{k} \\geq d_{n}\\qquad \\longrightarrow\\qquad d_{n} = d_{k}\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Diversity\\;Model.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & d_{u,v} = \\left\\{\\begin{array} & \\qquad\\max(\\ |\\ \\vec{x_{u}} - \\vec{x_{v}}\\ |\\ ) && Chebyshev\\qquad\\cr\\cr\\cr \\qquad\\lgroup\\matrix{\\sum_{i=0}^{N}(\\ \\vec{x_{u,i}} - \\vec{x_{v,i}}\\ )^2}\\rgroup^{0.5} && Euclidean\\qquad\\cr\\cr\\cr\\qquad\\prod_{i=0}^{N}{(\\ |\\ \\vec{x_{u,i}} - \\vec{x_{v,i}}\\ |\\ )}^{\\frac{1}{N}} && Geometric\\qquad\\cr\\cr\\cr\\qquad\\sum_{i=0}^{N}{\\ (\\ |\\ \\vec{x_{u}} - \\vec{x_{v}}\\ |\\ )\\ } && Manhattan\\qquad \\end{array}\\right. \\\\\\\\\n",
    "                                     & d_{k} = \\min(\\ d_{u,v}\\ ) & u, v \\in [\\ 0,\\ M\\ ),\\ u \\neq v \\\\\\\\\n",
    "                                     & d_{k} \\geq d_{n}\\qquad \\longrightarrow\\qquad d_{n} = d_{k}\n",
    "                                     \\end{align}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2e6914ea541f476bbe7dfbc8ff61bcc0",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=0.25, description='Noise', layout=Layout(width='420px'), max=0.5, step…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( noise = ipywidgets.FloatSlider( description = 'Noise', value = 0.25, min = 0.0, max = 0.5, step = 0.01, layout = { 'width' : '420px' } ),\n",
    "               classification = ipywidgets.Dropdown( description = 'Classification', value = 'Euclidean', options = [ 'Chebyshev', 'Euclidean', 'Geometric', 'Manhattan' ], layout = { 'width' : '340px' } ),\n",
    "               order = ipywidgets.IntSlider( description = 'Order', value = 4, min = 2, max = 64, step = 1, layout = { 'width' : '420px' } ) ) :\n",
    "\n",
    "    \"\"\" Diversity Model.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            noise : float - incident signal deviation.\n",
    "\n",
    "            classification : str - in ( 'Chebyshev', 'Euclidean', 'Geometric', 'Manhattan' ).\n",
    "\n",
    "            order : int.\n",
    "    \"\"\"\n",
    "\n",
    "    axis = matplotlib.pyplot.subplots( 1, 2, sharex = False, sharey = False, figsize = ( 18, 9 ) )[ 1 ]\n",
    "\n",
    "    # Diversity\n",
    "    \n",
    "    diversitymodel = DiversityModel.Factory.instance( DiversityModel, classification, order )\n",
    "    \n",
    "    length = 1024\n",
    "\n",
    "    n = numpy.linspace( 0.0, length - 1, length )\n",
    "\n",
    "    x = numpy.concatenate( ( [ numpy.polyval( numpy.random.rand( 2 ), n ) ], [ numpy.polyval( numpy.random.rand( 3 ), n ) + numpy.random.rand( 1 )[ 0 ] - 0.5 ] ) )\n",
    "    \n",
    "    x = ( x.T / x.std( 1 ) ).T\n",
    "    \n",
    "    q = numpy.random.rand( x.shape[ 0 ], x.shape[ 1 ] ) - 0.5\n",
    "    \n",
    "    x += ( q.T * noise / q.std( 1 ) ).T\n",
    "    \n",
    "    d = diversitymodel.model( x )\n",
    "\n",
    "    p = numpy.polyfit( diversitymodel.s[ 0, : ], diversitymodel.s[ 1, : ], 2 )\n",
    "    \n",
    "    y = numpy.polyval( p, x[ 0, : ] )\n",
    "        \n",
    "    axis[ 0 ].plot( n, d, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )\n",
    "    \n",
    "    label( axis[ 0 ], r'$Diversity$', r'$n$', r'$d_{n}$' )\n",
    "    \n",
    "    # Model\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    ii = numpy.argsort( x[ 0, : ] )\n",
    "        \n",
    "    plot.append( axis[ 1 ].plot( x[ 0, ii ], x[ 1, ii ], linestyle = 'None', marker = 'o', markeredgecolor = 'None', markeredgewidth = 2.0, markerfacecolor = [ 0.2, 0.2, 0.8 ], markersize = 4.0 )[ 0 ] )\n",
    "\n",
    "    plot.append( axis[ 1 ].plot( x[ 0, ii ], y[ ii ], linestyle = 'None', marker = 'o', markeredgecolor = 'None', markeredgewidth = 2.0, markerfacecolor = [ 0.8, 0.2, 0.2 ], markersize = 4.0 )[ 0 ] )\n",
    "    \n",
    "    plot.append( axis[ 1 ].plot( diversitymodel.s[ 0, : ], diversitymodel.s[ 1, : ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = 'None', markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    axis[ 1 ].legend( plot, ( r'$x_{n}$', r'$y_{2,n}$', r'$s_{N-1}$' ), loc = 'upper right' )\n",
    "    \n",
    "    label( axis[ 1 ], r'$Model$', r'$x_{0,n}$', r'$x_{1,n}$' )\n",
    "    \n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Principal\\;Component\\;Model.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & \\vec{\\mu_{i}} = \\lgroup\\matrix{\\ \\frac{\\sum_{n=0}^{N}\\vec{x_{i,n}}}{N}}\\rgroup \\\\\\\\\n",
       "                                     & \\vec{\\sigma_{i}} = \\lgroup\\matrix{\\ \\frac{\\sum_{n=0}^{N}(\\ \\vec{x_{i,n}} - \\vec{\\mu_{i}}\\ )^{2}}{N}}\\rgroup^{0.5} \\\\\\\\\n",
       "                                     & \\Lambda_{n} = eig\\lgroup\\matrix{\\ cov\\lgroup\\matrix{\\ \\lgroup\\matrix{\\frac{\\ X_{n}^{T} - \\vec{\\mu}\\ }{\\vec{\\sigma}}\\ }\\rgroup\\ }^{T}\\rgroup\\ }\\rgroup^{T} \\\\\\\\\n",
       "                                     & Y_{n} = \\Lambda_{n} \\ \\lgroup\\matrix{\\frac{\\ X_{n}^{T} - \\vec{\\mu}\\ }{\\vec{\\sigma}}\\ }\\rgroup^{T} \\\\\\\\\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Principal\\;Component\\;Model.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & \\vec{\\mu_{i}} = \\lgroup\\matrix{\\ \\frac{\\sum_{n=0}^{N}\\vec{x_{i,n}}}{N}}\\rgroup \\\\\\\\\n",
    "                                     & \\vec{\\sigma_{i}} = \\lgroup\\matrix{\\ \\frac{\\sum_{n=0}^{N}(\\ \\vec{x_{i,n}} - \\vec{\\mu_{i}}\\ )^{2}}{N}}\\rgroup^{0.5} \\\\\\\\\n",
    "                                     & \\Lambda_{n} = eig\\lgroup\\matrix{\\ cov\\lgroup\\matrix{\\ \\lgroup\\matrix{\\frac{\\ X_{n}^{T} - \\vec{\\mu}\\ }{\\vec{\\sigma}}\\ }\\rgroup\\ }^{T}\\rgroup\\ }\\rgroup^{T} \\\\\\\\\n",
    "                                     & Y_{n} = \\Lambda_{n} \\ \\lgroup\\matrix{\\frac{\\ X_{n}^{T} - \\vec{\\mu}\\ }{\\vec{\\sigma}}\\ }\\rgroup^{T} \\\\\\\\\n",
    "                                     \\end{align}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "e2e94f96652c4d78a94a534b73cbac77",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(FloatSlider(value=0.05, description='Noise', layout=Layout(width='420px'), max=0.5, step…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( noise = ipywidgets.FloatSlider( description = 'Noise', value = 0.05, min = 0.0, max = 0.5, step = 0.01, layout = { 'width' : '420px' } ) ) :\n",
    "\n",
    "    \"\"\" Principal Component Model.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            noise : float - incident signal deviation.\n",
    "    \"\"\"\n",
    "        \n",
    "    length, valid = 1024, False\n",
    "    \n",
    "    while ( not valid ) :\n",
    "        \n",
    "        principalcomponentmodel = PrincipalComponentModel( )\n",
    "    \n",
    "        x = numpy.random.rand( 3, length ) - 0.5\n",
    "                 \n",
    "        for ii in range( 0, 2 ) :\n",
    "\n",
    "            jj = [ int( numpy.random.rand( ) * length * 0.5 ) ]\n",
    "            \n",
    "            jj += [ jj[ 0 ] + int( numpy.random.rand( ) * ( length - jj[ 0 ] - 1 ) ) + 1 ]\n",
    "\n",
    "            jj = range( jj[ 0 ], jj[ 1 ] )\n",
    "        \n",
    "            x[ 0, jj ] += ( numpy.random.rand( ) - 0.5 ) * numpy.linspace( 0, len( jj ) - 1, len( jj ) ) * 10.0\n",
    "            \n",
    "            x[ 2, jj ] += ( numpy.random.rand( ) - 0.5 ) * x[ 0, jj ] + ( numpy.random.rand( ) - 0.5 ) * 10.0\n",
    "\n",
    "        x = ( x.T / x.std( 1 ) ).T\n",
    "        \n",
    "        q = numpy.random.rand( x.shape[ 0 ], x.shape[ 1 ] ) - 0.5\n",
    "\n",
    "        x += ( q.T * noise / q.std( 1 ) ).T\n",
    "\n",
    "        x = ( x.T * ( numpy.random.rand( 3 ) + 1.0 ) + numpy.random.rand( 3 ) ).T\n",
    "    \n",
    "        y = principalcomponentmodel.model( x )\n",
    "        \n",
    "        valid = ( ( numpy.argsort( principalcomponentmodel.e ) == numpy.array( [ 1, 2, 0 ] ) ) ).all( )\n",
    "                \n",
    "    widget = [ ipywidgets.Dropdown( description = r'$\\vec{\\mu_{n}}$', value = str( principalcomponentmodel.u[ 0 ] ), options = [ str( x ) for x in principalcomponentmodel.u ], layout = { 'width' : '340px' } ),\n",
    "               ipywidgets.Dropdown( description = r'$\\vec{\\lambda_{n}}$', value = str( principalcomponentmodel.e[ 0 ] ), options = [ str( x ) for x in principalcomponentmodel.e ], layout = { 'width' : '340px' } ) ]\n",
    "\n",
    "    display( ipywidgets.VBox( children = widget, layout = ipywidgets.Layout( display = 'flex', flex_flow = 'row' ) ) )\n",
    "    \n",
    "    widget = [ ipywidgets.Dropdown( description = r'$\\vec{\\sigma_{n}}$', value = str( principalcomponentmodel.s[ 0 ] ), options = [ str( x ) for x in principalcomponentmodel.s ], layout = { 'width' : '340px' } ), \n",
    "               ipywidgets.Dropdown( description = r'$\\Lambda_{n}$', value = '  '.join( [ f'{x:1.5f}' for x in principalcomponentmodel.v[ 0, : ] ] ), options = [ '  '.join( [ f'{x:1.5f}' for x in principalcomponentmodel.v[ ii, : ] ] ) for ii in range( 0, 3 ) ], layout = { 'width' : '340px' } ) ]\n",
    "\n",
    "    display( ipywidgets.VBox( children = widget, layout = ipywidgets.Layout( display = 'flex', flex_flow = 'row' ) ) )\n",
    "\n",
    "    axis = matplotlib.pyplot.subplots( 1, 2, sharex = False, sharey = False, figsize = ( 18, 9 ) )[ 1 ]\n",
    "    \n",
    "    # Incident\n",
    "    \n",
    "    axis[ 0 ].plot( [ min( x[ 0, : ] ), max( x[ 0, : ] ) ], [ principalcomponentmodel.u[ 2 ], principalcomponentmodel.u[ 2 ] ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 0 ].plot( [ principalcomponentmodel.u[ 0 ], principalcomponentmodel.u[ 0 ] ], [ min( x[ 2, : ] ), max( x[ 2, : ] ) ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 0 ].plot( x[ 0, : ], x[ 2, : ], linestyle = 'None', marker = 'o', markeredgecolor = 'None', markeredgewidth = 2.0, markerfacecolor = [ 0.2, 0.2, 0.8 ], markersize = 4.0 )\n",
    "\n",
    "    axis[ 0 ].plot( [ principalcomponentmodel.u[ 0 ], principalcomponentmodel.u[ 0 ] + principalcomponentmodel.v[ 0, 0 ] ], [ principalcomponentmodel.u[ 2 ], principalcomponentmodel.u[ 2 ] + principalcomponentmodel.v[ 0, 2 ] ], color = [ 0.8, 0.2, 0.2 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 0 ].plot( principalcomponentmodel.u[ 0 ], principalcomponentmodel.u[ 2 ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )\n",
    "    \n",
    "    axis[ 0 ].plot( principalcomponentmodel.u[ 0 ] + principalcomponentmodel.v[ 0, 0 ], principalcomponentmodel.u[ 2 ] + principalcomponentmodel.v[ 0, 2 ], linestyle = 'None', marker = 's', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )\n",
    "    \n",
    "    label( axis[ 0 ], r'$Incident$', r'$x_{0,n}$', r'$x_{2,n}$' )\n",
    "\n",
    "    # Model\n",
    "    \n",
    "    axis[ 1 ].plot( [ 0.0, 0.0 ], [ min( y[ 1, : ] ) * 2.0, max( y[ 1, : ] ) * 2.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 1 ].plot( [ min( y[ 0, : ] ), max( y[ 0, : ] ) ], [ 0.0, 0.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "\n",
    "    axis[ 1 ].plot( [ 0.0, 0.0 ], [ min( y[ 1, : ] ) * 2.0, max( y[ 1, : ] ) * 2.0 ], color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 1 ].plot( y[ 0, : ], y[ 1, : ], linestyle = 'None', marker = 'o', markeredgecolor = 'None', markeredgewidth = 2.0, markerfacecolor = [ 0.8, 0.2, 0.2 ], markersize = 4.0 )\n",
    "    \n",
    "    label( axis[ 1 ], r'$Model$', r'$y_{0,i}$', r'$y_{1,n}$' )\n",
    "    \n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle \\underline{Wavelet\\;Transform.} \\\\\\\\\n",
       "                                   \\\\\\begin{align}\n",
       "                                     & y_{i,0:\\frac{C}{2}-1} = \\downarrow(\\ filter_{b_{A,L}}(\\ x_{i,0:C-1}\\ ),\\ 2\\ ) & y_{i,\\frac{C}{2}:C-1} = \\downarrow(\\ filter_{b_{A,H}}(\\ x_{i,0:C-1}\\ ),\\ 2\\ ) && i \\in [\\ 0,\\ R\\ ) \\\\\\\\\n",
       "                                     & y_{0:\\frac{R}{2}-1,j} = \\downarrow(\\ filter_{b_{A,L}}(\\ x_{0:R-1,j}\\ ),\\ 2\\ ) & y_{\\frac{R}{2}:R-1,j} = \\downarrow(\\ filter_{b_{A,H}}(\\ x_{0:R-1,j}\\ ),\\ 2\\ ) && j \\in [\\ 0,\\ C\\ ) \\\\\\\\\n",
       "                                     & x_{0:R-1,j} = filter_{b_{S,L}}(\\ 2\\ \\uparrow(\\ y_{0:\\frac{R}{2}-1,j},\\ 2\\ )\\ ) + filter_{b_{S,H}}(\\ 2\\ \\uparrow(\\ y_{\\frac{R}{2}:R-1,j},\\ 2\\ )\\ ) &&& j \\in [\\ 0,\\ C\\ ) \\\\\\\\\n",
       "                                     & x_{i,0:C-1} = filter_{b_{S,L}}(\\ 2\\ \\uparrow(\\ y_{i,0:\\frac{C}{2}-1},\\ 2\\ )\\ ) + filter_{b_{S,H}}(\\ 2\\ \\uparrow(\\ y_{i,\\frac{C}{2}:C-1},\\ 2\\ )\\ ) &&& i \\in [\\ 0,\\ R\\ )\n",
       "                                     \\end{align}$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display( IPython.display.Math( r\"\"\"\\underline{Wavelet\\;Transform.} \\\\\\\\\n",
    "                                   \\\\\\begin{align}\n",
    "                                     & y_{i,0:\\frac{C}{2}-1} = \\downarrow(\\ filter_{b_{A,L}}(\\ x_{i,0:C-1}\\ ),\\ 2\\ ) & y_{i,\\frac{C}{2}:C-1} = \\downarrow(\\ filter_{b_{A,H}}(\\ x_{i,0:C-1}\\ ),\\ 2\\ ) && i \\in [\\ 0,\\ R\\ ) \\\\\\\\\n",
    "                                     & y_{0:\\frac{R}{2}-1,j} = \\downarrow(\\ filter_{b_{A,L}}(\\ x_{0:R-1,j}\\ ),\\ 2\\ ) & y_{\\frac{R}{2}:R-1,j} = \\downarrow(\\ filter_{b_{A,H}}(\\ x_{0:R-1,j}\\ ),\\ 2\\ ) && j \\in [\\ 0,\\ C\\ ) \\\\\\\\\n",
    "                                     & x_{0:R-1,j} = filter_{b_{S,L}}(\\ 2\\ \\uparrow(\\ y_{0:\\frac{R}{2}-1,j},\\ 2\\ )\\ ) + filter_{b_{S,H}}(\\ 2\\ \\uparrow(\\ y_{\\frac{R}{2}:R-1,j},\\ 2\\ )\\ ) &&& j \\in [\\ 0,\\ C\\ ) \\\\\\\\\n",
    "                                     & x_{i,0:C-1} = filter_{b_{S,L}}(\\ 2\\ \\uparrow(\\ y_{i,0:\\frac{C}{2}-1},\\ 2\\ )\\ ) + filter_{b_{S,H}}(\\ 2\\ \\uparrow(\\ y_{i,\\frac{C}{2}:C-1},\\ 2\\ )\\ ) &&& i \\in [\\ 0,\\ R\\ )\n",
    "                                     \\end{align}\"\"\" ) )\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "9026fea402d74902a5d37145bb65699e",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Dropdown(description='Incident', index=1, layout=Layout(width='340px'), options=('Burnin…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "@ipywidgets.interact( )\n",
    "def interface( incident = ipywidgets.Dropdown( description = 'Incident', value = 'Drac Isere', options = [ 'Burning Eye', 'Drac Isere', 'Kali', 'Lionfish', 'Porsche', 'Riley' ], layout = { 'width' : '340px' } ),\n",
    "               classification = ipywidgets.Dropdown( description = 'Classification', value = 'Haar', options = [ 'Coiflet', 'Daubechies', 'Haar', 'Symmlet' ], layout = { 'width' : '340px' } ),\n",
    "               order = ipywidgets.IntSlider( description = 'Order', value = 1, min = 1, max = 29, step = 1, layout = { 'width' : '420px' } ),\n",
    "               count = ipywidgets.IntSlider( description = 'Count', value = 2, min = 1, max = 4, step = 1, layout = { 'width' : '420px' } ),\n",
    "               inverse = ipywidgets.IntSlider( description = 'Inverse', value = False, min = False, max = True, layout = { 'width' : '420px' } ) ) :\n",
    "\n",
    "    \"\"\" Wavelet Transform.\n",
    "    \n",
    "        Arguments :\n",
    "        \n",
    "            incident : str - incident image in ( 'Burning Eye', Drac Isere', 'Kali', 'Lionfish', Porsche', 'Riley' ).\n",
    "\n",
    "            classification : str - in ( 'Coiflet', 'Daubechies', 'Haar', 'Symmlet' ).\n",
    " \n",
    "            order : int.\n",
    "\n",
    "            count : int.\n",
    "\n",
    "            inverse : bool.\n",
    "    \"\"\"\n",
    "    \n",
    "    _order = { 'Coiflet' : numpy.array( [ 5, 11, 17, 23, 29 ] ),\n",
    "               'Daubechies' : numpy.array( [ 3, 5, 7, 9, 11, 13, 15, 17, 19 ] ),\n",
    "               'Haar' : numpy.array( [ 1 ] ),\n",
    "               'Symmlet' : numpy.array( [ 7, 9, 11, 13, 15, 17, 19 ] ) }\n",
    "    \n",
    "    if ( order not in _order[ classification ] ) :\n",
    "    \n",
    "        Log.write( 'ERROR', f'Classification = {classification} Order = {str( _order[ classification ] ).replace( \"[\", \"[ \" ).replace( \"]\", \" ]\" )}' )\n",
    "        \n",
    "        return\n",
    "        \n",
    "    wavelettransform = WaveletTransform.Factory.instance( WaveletTransform, classification, order )\n",
    "\n",
    "    b = wavelettransform.b[ inverse ]\n",
    "\n",
    "    widget = [ ipywidgets.Dropdown( description = r'$\\vec{b_{L,n}}$', value = str( b[ 0 ][ 0 ] ), options = [ str( x ) for x in b[ 0 ] ], layout = { 'width' : '340px' } ),\n",
    "               ipywidgets.Dropdown( description = r'$\\vec{b_{H,n}}$', value = str( b[ 1 ][ 0 ] ), options = [ str( x ) for x in b[ 1 ] ], layout = { 'width' : '340px' } ) ]\n",
    "    \n",
    "    display( ipywidgets.VBox( children = widget, layout = ipywidgets.Layout( display = 'flex', flex_flow = 'row' ) ) )\n",
    "    \n",
    "    axis = matplotlib.pyplot.subplots( 2, 2, sharex = False, sharey = False, figsize = ( 18, 18 ) )[ 1 ]\n",
    "\n",
    "    # Coefficients\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    x = Image.open( incident + '.png' ).convert( 'F' )\n",
    "        \n",
    "    cols, rows = x.size\n",
    "    \n",
    "    if ( ( rows % ( 2 ** count ) ) or ( cols % ( 2 ** count ) ) ) :\n",
    "\n",
    "        Log.write( 'ERROR', f'Rows = {rows} Columns = {cols} Count = {count}' )\n",
    "        \n",
    "        return\n",
    "    \n",
    "    x = list( x.getdata( ) )\n",
    "    \n",
    "    x = numpy.array( [ x[ ii : ii + cols ] for ii in range( 0, rows * cols, cols ) ], 'float' )\n",
    "    \n",
    "    y = wavelettransform.transform( x, count, False )    \n",
    "\n",
    "    if ( inverse ) :\n",
    "        \n",
    "        x, y = y, wavelettransform.transform( y, count, True )\n",
    "        \n",
    "        u, v = y, x\n",
    "        \n",
    "    else :\n",
    "        \n",
    "        u, v = x, y\n",
    "\n",
    "    u[ :, : ] = ( u - u.min( ) ) * 255.0 / ( u.max( ) - u.min( ) )\n",
    "\n",
    "    cols, rows = x.shape[ 1 ] // ( 2 ** count ), x.shape[ 0 ] // ( 2 ** count )\n",
    "\n",
    "    q, v[ :, : ] = v[ : rows, : cols ], ( v - v[ rows :, cols : ].min( ) ) * 255.0 / ( v[ rows :, cols : ].max( ) - v[ rows :, cols : ].min( ) )\n",
    "    \n",
    "    v[ : rows, : cols ] = ( q - q.min( ) ) * 255.0 / ( q.max( ) - q.min( ) )\n",
    "    \n",
    "    n = numpy.linspace( 0, order, order + 1 )\n",
    "    \n",
    "    color = matplotlib.pyplot.get_cmap( 'gray' )\n",
    "        \n",
    "    axis[ 0, 0 ].plot( n, numpy.zeros( order + 1 ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 0, 0 ].bar( n, b[ 0 ], color = [ 0.2, 0.2, 0.8 ], width = 0.006 * ( order + 1 ) )\n",
    "\n",
    "    plot.append( axis[ 0, 0 ].plot( n, b[ 0 ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.2, 0.2, 0.8 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "\n",
    "    axis[ 0, 0 ].bar( n, b[ 1 ], 0.005 * ( order + 1 ), color = [ 0.8, 0.2, 0.2 ] )\n",
    "\n",
    "    plot.append( axis[ 0, 0 ].plot( n, b[ 1 ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = [ 1.0, 1.0, 1.0 ], markersize = 8.0 )[ 0 ] )\n",
    "    \n",
    "    axis[ 0, 0 ].legend( plot, ( r'$\\vec{b_{L,n}}$', r'$\\vec{b_{H,n}}$' ), loc = 'upper right' )    \n",
    "    \n",
    "    label( axis[ 0, 0 ], r'$Coefficients$', r'$n$' )\n",
    "    \n",
    "    # Response\n",
    "    \n",
    "    plot = [ ]\n",
    "    \n",
    "    h, f = FirFilter( b[ 0 ] ).response( )\n",
    "    \n",
    "    g, f = FirFilter( b[ 1 ] ).response( )    \n",
    "\n",
    "    h = 20.0 * numpy.log10( numpy.maximum( abs( h ), numpy.finfo( float ).eps ) )\n",
    "    \n",
    "    g = 20.0 * numpy.log10( numpy.maximum( abs( g ), numpy.finfo( float ).eps ) )    \n",
    "\n",
    "    axis[ 0, 1 ].plot( f, -3.0 * numpy.ones( len( h ) ), color = [ 0.0, 0.0, 0.0 ], linewidth = 2.0 )\n",
    "    \n",
    "    axis[ 0, 1 ].plot( [ -0.5, 0.5 ], [ -3.0, -3.0 ], linestyle = 'None', marker = 'o', markeredgecolor = [ 0.8, 0.2, 0.2 ], markeredgewidth = 2.0, markerfacecolor = 'None', markersize = 8.0 )\n",
    "    \n",
    "    plot.append( axis[ 0, 1 ].plot( f, h, color = [ 0.2, 0.2, 0.8 ], linewidth = 2.0 )[ 0 ] )\n",
    "    \n",
    "    plot.append( axis[ 0, 1 ].plot( f, g, color = [ 0.8, 0.2, 0.2 ], linewidth = 2.0 )[ 0 ] )\n",
    "    \n",
    "    axis[ 0, 1 ].legend( plot, ( r'$H_{L,f}$', r'$H_{H,f}$' ), loc = 'upper right' )\n",
    "    \n",
    "    label( axis[ 0, 1 ], r'$Response$', r'$f$', r'$H_f\\ dB$' )\n",
    "    \n",
    "    # Incident\n",
    "    \n",
    "    axis[ 1, 0 ].imshow( x, cmap = color )\n",
    "    \n",
    "    label( axis[ 1, 0 ], r'$Incident$', r'$col$', r'$row$', False )\n",
    "\n",
    "    # Transform\n",
    "    \n",
    "    axis[ 1, 1 ].imshow( y, cmap = color )\n",
    "\n",
    "    label( axis[ 1, 1 ], r'$Transform$', r'$col$', r'$row$', False )\n",
    "\n",
    "    matplotlib.pyplot.show( )\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "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.8.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}