{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n======================================================\nFriedman's Instantaneous Frequency Density Calculation\n======================================================\n\nThis example uses Friedman's method to calculate the instantaneous frequency\ndensity of a hybrid signal. The method consists of computing the histograms of\nfrequency displacements of the spectrogram of the signal.\n\nFigure 4.38 from the tutorial.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nimport matplotlib.pyplot as plt\nfrom tftb.generators import fmlin, fmsin, fmconst\nfrom tftb.processing.reassigned import pseudo_wigner_ville\nfrom tftb.processing.postprocessing import friedman_density\n\nsig1, if1 = fmsin(60, 0.16, 0.35, 50, 1, 0.35, 1)\nsig2, if2 = fmlin(60, 0.3, 0.1)\nsig3, if3 = fmconst(60, 0.4)\nsig = np.hstack((sig1, np.zeros((8,)), sig2 + sig3))\n\nt = np.arange(1, 128, step=2)\ntfr, rtfr, hat = pseudo_wigner_ville(sig, timestamps=t)\ntifd = friedman_density(tfr, hat, t)\nf = np.linspace(0, 0.5, tifd.shape[0])\n\nplt.contour(t, f, tifd, 4)\nplt.grid(True)\nplt.title(\"Friedman's instantaenous frequency density\")\nplt.xlabel('Time')\nplt.ylabel('Frequency')\nplt.show()"
      ]
    }
  ],
  "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.7.3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}