{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Spectrum of a Noisy Transient Signal\n\nThis example shows how to generate a noisy transient signal with the following\ncharacteristics:\n\n    * One-sided exponential amplitude modulation (See `amexpos`)\n    * Constant frequency modulation (See `fmconst`)\n    * -5 dB complex gaussian noise (See `noisecg` and `sigmerge`)\n\nAnd how to plot its energy spectrum.\n\nFigure 1.10 of 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 amexpos, fmconst, sigmerge, noisecg\n\n# Generate a noisy transient signal.\ntranssig = amexpos(64, kind='unilateral') * fmconst(64)[0]\nsignal = np.hstack((np.zeros((100,)), transsig, np.zeros((92,))))\nsignal = sigmerge(signal, noisecg(256), -5)\nfig, ax = plt.subplots(2, 1)\nax1, ax2 = ax\nax1.plot(np.real(signal))\nax1.grid()\nax1.set_title('Noisy Transient Signal')\nax1.set_xlabel('Time')\nax1.set_xlim((0, 256))\nax1.set_ylim((np.real(signal).max(), np.real(signal.min())))\n\n# Energy spectrum of the signal\ndsp = np.fft.fftshift(np.abs(np.fft.fft(signal)) ** 2)\nax2.plot(np.arange(-128, 128, dtype=float) / 256, dsp)\nax2.set_title('Energy spectrum of noisy transient signal')\nax2.set_xlabel('Normalized frequency')\nax2.grid()\nax2.set_xlim(-0.5, 0.5)\n\nplt.subplots_adjust(hspace=0.5)\n\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
}