{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Energy Spectral Density of a Chirp\n\nConstruct a chirp and plot its [energy spectral density](https://en.wikipedia.org/wiki/Spectral_density#Energy_spectral_density).\n\nFigure 1.2 from the tutorial.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from tftb.generators import fmlin\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nn_points = 128\nfmin, fmax = 0.0, 0.5\nsignal, _ = fmlin(n_points, fmin, fmax)\n\n# Plot the energy spectrum of the chirp\n\ndsp1 = np.fft.fftshift(np.abs(np.fft.fft(signal)) ** 2)\nplt.plot(np.arange(-64, 64, dtype=float) / 128.0, dsp1)\nplt.xlim(-0.5, 0.5)\nplt.title('Spectrum')\nplt.ylabel('Squared modulus')\nplt.xlabel('Normalized Frequency')\nplt.grid()\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.9"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}