{
  "nbformat_minor": 0,
  "cells": [
    {
      "execution_count": null,
      "outputs": [],
      "cell_type": "code",
      "source": [
        "%matplotlib inline"
      ],
      "metadata": {
        "collapsed": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "\n#   Process a single channel of the cochlea\n\n\nThis example show how to run a signal through a specific channel of the cochlea\n\n\n"
      ],
      "metadata": {}
    },
    {
      "execution_count": null,
      "outputs": [],
      "cell_type": "code",
      "source": [
        "import os\nimport numpy as np\nfrom scipy.io import wavfile\nimport seaborn as sns\nfrom simplecochlea import Cochlea, generate_signals\nsns.set_context('paper')"
      ],
      "metadata": {
        "collapsed": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Create the cochlea\n\n"
      ],
      "metadata": {}
    },
    {
      "execution_count": null,
      "outputs": [],
      "cell_type": "code",
      "source": [
        "fs, fmin, fmax, freq_scale, n_channels = 44100, 200, 8000, 'erbscale', 100\ncomp_factor, comp_gain = 0.3, 1.5\ntau, v_thresh, v_spike = np.linspace(0.001, 0.0004, n_channels), 0, 0.5\n# Adaptive threshold parameters\ntau_j, alpha_j = np.array([0.010, 0.200]), np.array([0.010, 0.000002])\nomega = np.linspace(0.15, 0.2, n_channels)\n\ncochlea_adaptive_thresh = Cochlea(n_channels, fs, fmin, fmax, freq_scale, comp_factor=comp_factor, comp_gain=comp_gain,\n                                  lif_tau=tau, lif_v_thresh=v_thresh, lif_v_spike=v_spike, tau_j=tau_j, alpha_j=alpha_j,\n                                  omega=omega)"
      ],
      "metadata": {
        "collapsed": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Generate a sinusoidal signal\n\n"
      ],
      "metadata": {}
    },
    {
      "execution_count": null,
      "outputs": [],
      "cell_type": "code",
      "source": [
        "x_sin = generate_signals.generate_sinus(fs, 1800, t_offset=0, t_max=0.25, amplitude=1)"
      ],
      "metadata": {
        "collapsed": false
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "Pass the input signal through one channel of the cochlea\nThe `plot_channel_evolution` method allows to visualize the differents steps\n of the cochlea processing\n\n"
      ],
      "metadata": {}
    },
    {
      "execution_count": null,
      "outputs": [],
      "cell_type": "code",
      "source": [
        "cochlea_adaptive_thresh.plot_channel_evolution(x_sin, 30)"
      ],
      "metadata": {
        "collapsed": false
      }
    }
  ],
  "nbformat": 4,
  "metadata": {
    "language_info": {
      "codemirror_mode": {
        "version": 3,
        "name": "ipython"
      },
      "mimetype": "text/x-python",
      "pygments_lexer": "ipython3",
      "nbconvert_exporter": "python",
      "version": "3.5.2",
      "name": "python",
      "file_extension": ".py"
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3",
      "language": "python"
    }
  }
}