{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "# Simulate noise\n", "\n", "Objects from `thztools`: `NoiseModel`, `NoiseModel.noise_amp`, `NoiseModel.noise_sim`, `timebase`, `wave`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from matplotlib import pyplot as plt\n", "import numpy as np\n", "\n", "import thztools as thz" ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "## Set the simulation parameters" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "n = 256 # Number of samples\n", "dt = 0.05 # Sampling time [ps]\n", "\n", "sigma_alpha = 1e-4 # Additive noise amplitude [signal units]\n", "sigma_beta = 1e-2 # Multiplicative noise amplitude [dimensionless]\n", "sigma_tau = 1e-3 # Time base noise amplitude [ps]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simulate a waveform\n", "\n", "Use `wave` to simulate a terahertz time-domain waveform `mu` with a timebase given by `timebase`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "t = thz.timebase(n, dt=dt)\n", "mu = thz.wave(n, dt=dt)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simulate noise\n", "\n", "Create an instance `noise_model` of the `NoiseModel` class and use the `noise_sim` method to use the model to generate time-domain noise `delta` for the waveform `mu`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "noise_model = thz.NoiseModel(sigma_alpha, sigma_beta, sigma_tau, dt=dt)\n", "\n", "delta = noise_model.noise_sim(mu, seed=0)\n", "sigma_mu = noise_model.noise_amp(mu)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Show the noise\n", "\n", "Show the simulated noise `delta` together with statistical bounds given by the noise amplitude `sigma_mu`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "_, ax = plt.subplots()\n", "\n", "ax.plot(t, delta)\n", "ax.plot(t, sigma_mu, 'k:')\n", "ax.plot(t, -sigma_mu, 'k:')\n", "\n", "ax.set_xlabel('Time (ps)')\n", "ax.set_ylabel(r'Amplitude (units of $\\mu_{p})$')\n", "\n", "ax.set_xticks(np.arange(0, 11, 5))\n", "ax.set_xlim(0, 10)\n", "\n", "plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.16" } }, "nbformat": 4, "nbformat_minor": 1 }