2021-11-23 15:22:20 +01:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Fourier Transforms"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"\n",
"import numpy as np\n",
"import scipy.fft as ft\n",
"import matplotlib.pyplot as plt\n",
2021-11-30 15:06:04 +01:00
"import matplotlib.gridspec as gridspec\n",
2021-11-23 15:22:20 +01:00
"rng = np.random.default_rng()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The Fourier transform (FT) of a quantity $t$ is defined as\n",
"\n",
"$$\n",
2021-11-25 18:49:42 +01:00
"\\hat{f}(\\omega) = F(f(t)) = \\frac{1}{\\sqrt{2\\pi}} \\int_{-\\infty}^{\\infty} \\mathrm{d}t\\, f(t)\\, \\exp{ \\left(-i \\omega t \\right)}\n",
2021-11-23 15:22:20 +01:00
".\n",
"$$\n",
"\n",
"In signal processing, taking the integral from $t = -\\infty$ to $t = \\infty$ is not practical. Together with a finite sample space $t$, the integral can be turned into a (discrete) sum, giving a Discrete Fourier Transform (DFT)\n",
"\n",
"$$\n",
2021-11-25 18:49:42 +01:00
"F(t) = \\frac{1}{\\sqrt{2\\pi}} \\sum_{k=0}^{N-1} f(t_k)\\, \\exp{ \\left(-i \\omega t_k \\right)}\n",
2021-11-23 15:22:20 +01:00
"\\label{eq:DFT} \\tag{1}\n",
",\n",
"$$\n",
"where the sum iterates over each sample $t_k$ up to the end ($k=N-1$) of the signal."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Interdependence $\\Delta t$, $T$, $\\Delta f$, $f_{min}$, $f_{max}$"
]
},
{
2021-11-25 18:49:42 +01:00
"cell_type": "markdown",
2021-11-23 15:22:20 +01:00
"metadata": {},
2021-11-25 18:49:42 +01:00
"source": [
"The highest frequency $f_\\mathrm{max}$ (also known as the Nyquist frequency) that can be (reliably) measured within a signal is dependent only on the sampling rate ($1/\\Delta t$) of the signal with\n",
"$$\n",
" f_\\mathrm{max} = \\frac{1}{2} f_\\mathrm{sampling} = \\frac{1}{2} \\frac{1}{\\Delta t}\n",
" .\n",
"$$\n",
"Higher frequencies will fall in between two adjacent samples, causing them to go unnoticed in the data. Note that because of folding, such frequencies can actually appear as aliases.\n",
"\n",
"Likewise, the lowest frequency depends on the length of the signal $T$, such that over the whole signal one oscillation can be found\n",
"$$\n",
" f_\\mathrm{min} \\sim \\frac{1}{T}\n",
" .\n",
"$$\n",
"Even lower frequencies will no longer be detected as a frequency. Instead, they will introduce a bias for the $0 Hz$ component in the spectrum."
]
2021-11-23 15:22:20 +01:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# FTs of ideal signals"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
2021-11-30 15:06:04 +01:00
"def ft_spectrum( signal, sample_rate, fft=None, freq=None, mask_bias=False):\n",
2021-11-23 15:22:20 +01:00
" \"\"\"Return a FT of $signal$, with corresponding frequencies\"\"\"\n",
" n_samples = len(signal)\n",
2021-11-30 15:06:04 +01:00
" real_signal = np.all(np.isreal(signal))\n",
2021-11-23 15:22:20 +01:00
" \n",
2021-11-25 18:49:42 +01:00
" if fft is None:\n",
" if real_signal:\n",
" fft = ft.rfft\n",
" freq = ft.rfftfreq\n",
" else:\n",
" fft = ft.fft\n",
" freq = ft.fftfreq\n",
"\n",
" if freq is None:\n",
2021-11-23 15:22:20 +01:00
" freq = ft.fftfreq\n",
" \n",
2021-11-25 18:49:42 +01:00
" spectrum = fft(signal) / sample_rate\n",
2021-11-23 15:22:20 +01:00
" freqs = freq(n_samples, 1/sample_rate)\n",
" \n",
2021-11-25 18:49:42 +01:00
" if not mask_bias:\n",
2021-11-23 15:22:20 +01:00
" return spectrum, freqs\n",
" else:\n",
" return spectrum[1:], freqs[1:]\n",
"\n",
" \n",
2021-11-30 15:06:04 +01:00
"def plot_spectrum( ax, spectrum, freqs, plot_complex=False, plot_power=False, plot_amplitude=None):\n",
2021-11-23 15:22:20 +01:00
" \"\"\" Plot a signal's spectrum on an Axis object\"\"\"\n",
2021-11-30 15:06:04 +01:00
" plot_amplitude = plot_amplitude or (not plot_power and not plot_complex)\n",
2021-11-25 18:49:42 +01:00
" alpha = 1\n",
2021-11-30 15:06:04 +01:00
" \n",
2021-11-23 15:22:20 +01:00
" ax.set_title(\"Spectrum\")\n",
" ax.set_xlabel(\"f (Hz)\")\n",
2021-11-30 15:06:04 +01:00
" ylabel = \"\"\n",
" if plot_amplitude:\n",
" ylabel = \"Amplitude\"\n",
" if plot_power:\n",
" if ylabel:\n",
" ylabel += \"|\"\n",
" ylabel += \"Power\"\n",
" ax.set_ylabel(ylabel)\n",
"\n",
2021-11-25 18:49:42 +01:00
" if plot_complex:\n",
" alpha = 0.5\n",
2021-11-30 15:06:04 +01:00
" ax.plot(freqs, np.real(spectrum), '.-', label='Real', alpha=alpha)\n",
" ax.plot(freqs, np.imag(spectrum), '.-', label='Imag', alpha=alpha)\n",
2021-11-25 18:49:42 +01:00
" ax.legend()\n",
2021-11-30 15:06:04 +01:00
"\n",
" if plot_power:\n",
" ax.plot(freqs, np.abs(spectrum)**2, '.-', label='Power', alpha=alpha)\n",
2021-11-25 18:49:42 +01:00
" \n",
2021-11-30 15:06:04 +01:00
" if plot_amplitude:\n",
" ax.plot(freqs, np.abs(spectrum), '.-', label='Abs', alpha=alpha)\n",
2021-11-25 18:49:42 +01:00
"\n",
2021-11-23 15:22:20 +01:00
" return ax\n",
2021-11-30 15:06:04 +01:00
"\n",
"\n",
"def plot_phase( ax, spectrum, freqs):\n",
" ax.set_ylabel(\"Phase\")\n",
" ax.set_xlabel(\"f (Hz)\")\n",
"\n",
" ax.plot(freqs, np.angle(spectrum), '.-')\n",
" ax.set_ylim(-1*np.pi, np.pi)\n",
2021-11-23 15:22:20 +01:00
" \n",
2021-11-30 15:06:04 +01:00
" return ax\n",
2021-11-23 15:22:20 +01:00
"\n",
2021-11-30 15:06:04 +01:00
"\n",
"def plot_combined_spectrum(spectrum, freqs, \n",
" spectrum_kwargs={}, fig=None, gs=None):\n",
" \"\"\"Plot both the frequencies and phase in one figure.\"\"\"\n",
2021-11-23 15:22:20 +01:00
" \n",
2021-11-30 15:06:04 +01:00
" # configure plotting layout\n",
" if fig is None:\n",
" fig = plt.figure(figsize=(8, 16))\n",
"\n",
" if gs is None:\n",
" gs = gridspec.GridSpec(2, 1, figure=fig, height_ratios=[2,1])\n",
"\n",
" ax1 = fig.add_subplot(gs[:-1, -1])\n",
" ax2 = fig.add_subplot(gs[-1, -1], sharex=ax1)\n",
"\n",
" axes = np.array([ax1, ax2])\n",
" \n",
" # plot the spectrum \n",
" plot_spectrum(ax1, spectrum, freqs, **spectrum_kwargs)\n",
" \n",
" # plot the phase\n",
" plot_phase(ax2, spectrum, freqs)\n",
" \n",
" return fig, axes\n",
2021-11-23 15:22:20 +01:00
" \n",
"\n",
2021-11-30 15:06:04 +01:00
"def plot_signal( ax, signal, sample_rate = 1):\n",
" ax.set_title(\"Signal\")\n",
" ax.set_xlabel(\"t (s)\")\n",
" ax.set_ylabel(\"A(t)\")\n",
"\n",
" ax.plot(np.arange(len(signal)) / sample_rate, signal)\n",
2021-11-23 15:22:20 +01:00
" \n",
2021-11-30 15:06:04 +01:00
" return ax\n",
2021-11-23 15:22:20 +01:00
"\n",
2021-11-30 15:06:04 +01:00
"\n",
"def plot_signal_and_spectrum( signal, sample_rate, title=None,\n",
" ft_kwargs = {}, spectrum_kwargs = {}):\n",
" \"\"\"Plot a signal and its spectrum in one go.\"\"\"\n",
" fig = plt.figure(figsize=(16, 4))\n",
" \n",
" if title:\n",
" fig.suptitle(title)\n",
"\n",
" # setup plot layout\n",
" gs0 = gridspec.GridSpec(1, 2, figure=fig)\n",
" gs00 = gs0[0].subgridspec(1, 1)\n",
" gs01 = gs0[1].subgridspec(2, 1)\n",
" \n",
" # plot the signal\n",
" ax1 = fig.add_subplot(gs00[0, 0])\n",
" plot_signal(ax1, signal)\n",
" \n",
" # plot spectrum\n",
" signal_fft, freqs = ft_spectrum(signal, sample_rate, **ft_kwargs)\n",
" _, (ax2, ax3) = plot_combined_spectrum(signal_fft, freqs, spectrum_kwargs = spectrum_kwargs, fig=fig, gs=gs01)\n",
"\n",
" # return the axes\n",
" axes = np.array([ax1, ax2, ax3])\n",
" \n",
" return (fig, axes)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
2021-11-23 15:22:20 +01:00
"sample_rate = 1/1e-3 # s\n",
"n_samples = 2**10\n",
"t = np.arange(n_samples) / sample_rate"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2021-11-25 18:49:42 +01:00
"### FTs: constant signal\n",
"\n",
"A constant signal (also termed offset or bias) results in only a single component in the Fourier transform, at the zero frequency.\n",
"\n",
"Since often such a component is included in a signal (for example when a signal is not on average zero), it can help to mask out the zero frequency when plotting the spectrum.\n",
"Doing this for a constant signal, we get a totally flat spectrum."
2021-11-23 15:22:20 +01:00
]
},
{
"cell_type": "code",
2021-11-30 15:06:04 +01:00
"execution_count": 4,
2021-11-23 15:22:20 +01:00
"metadata": {},
"outputs": [
{
"data": {
2021-11-30 15:06:04 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7wAAAEjCAYAAAAR7A2IAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO3dedxdZX3v/c+XJIDIECCRKYQERZE6AEYEjYWKVXDCoQ6IRYaW8qhH26PHg62PejzHp7Z1PloVBCcsanHCihVqUQuKkggyozFhCAkkzIgyhPyeP/aK3t7eY+5h3fe6P+/Xa7+y11rXXvu7Fztc+e1rrWulqpAkSZIkqWu2aDuAJEmSJEkTwYJXkiRJktRJFrySJEmSpE6y4JUkSZIkdZIFryRJkiSpkyx4JUmSJEmdZMErS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EkkOSPJuiRXDrI9ST6SZEWSy5McONw+b73nAV592sUWvZKk1ljwSpIkgM8ARwyx/Uhgn+ZxEvDxkez0wQ0buXjl7WMOJ0nS5rDglSRJVNUPgDuGaHIU8LnquRiYm2S3YfcL7L/n3HFKKUnS6FjwSpKkkdgDuKnP8upm3e9JclKSZUmWbbPFRgBWrPvV5CSUJKkfC15JkjQSGWBd/cGKqlOraklVLXn0bjuy/55z+fRFq9i48Q+aSpI04Sx4JUnSSKwG9uyzvABYM9yLTly6mOtv/zX/ee26CQsmSdJgLHglSdJInAMc28zWfDBwd1WtHe5FRz5hV3bfYWtOv3DVxCeUJKkfC15JkkSSs4AfAY9LsjrJiUlOTnJy0+RcYCWwAjgNeN1I9jt71hYc+/RF/Gjl7Vy15u4JyS5J0mBmtx1AkiS1r6q
2021-11-25 18:49:42 +01:00
"text/plain": [
2021-11-30 15:06:04 +01:00
"<Figure size 1152x288 with 3 Axes>"
2021-11-25 18:49:42 +01:00
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"data": {
2021-11-30 15:06:04 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7wAAAEjCAYAAAAR7A2IAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO3deZwlVX338c8XhkUj+yACAwwILrhEsANoXFAUQVGMiqJEgRiRqI9LNAaXiCHxiTHukaAIKCqKiKhjHAOEAMY8YpgBRGFAx1FkYJABhsWFZeD3/FHVcml6nV7u7duf9+t1X32rzqmq362umdO/e06dSlUhSZIkSVK/Wa/bAUiSJEmSNB1MeCVJkiRJfcmEV5IkSZLUl0x4JUmSJEl9yYRXkiRJktSXTHglSZIkSX3JhFeSpCGSHJbknBk4zr5JVo5R5ytJXjzdsQw55gVJ/nIK9rMwSSW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pJrzS7PJT4N4kpyY5MMkWw1VKMp/m2ZjvArYCrgaeOqTa3u36+TTPFz2541mfNwIHAZsCRwIfS7LnVH8YSZJ61Fjt7d7ACpo29FjgrCRbtmWnAmuBXYE9gP2BwS+cDwHeT/M8602BFwE3V9WrgV8BL6yqh1XVhzqO9UzgscDzxhn7C4Ev0jzn+lKaZ2OvB2wPHAd8Zpz7kfqCCa80i1TV7cDTgAI+C6xOsijJNkOqPh+4oqrOaoc/fRK4YUida6rqs1V1L03jvC2wTXuc71TVz6txIXAOzVAuSZL63jja2xuBj1fVPVX1VZovkF/Qlh8IvLWqfts++/ljwKHtdn8JfKiqLm7b2OVVdc0Y4by/3dd4Z4b/76o6u23/vwZsDXywqu4
2021-11-23 15:22:20 +01:00
"text/plain": [
2021-11-30 15:06:04 +01:00
"<Figure size 1152x288 with 3 Axes>"
2021-11-23 15:22:20 +01:00
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2021-11-25 18:49:42 +01:00
"signal_constant = np.ones(n_samples)\n",
"\n",
2021-11-30 15:06:04 +01:00
"fig, axes = plot_signal_and_spectrum(signal_constant, sample_rate, \"Constant signal\")\n",
"axes.flat[1].set_xlim(0,10);\n",
2021-11-23 15:22:20 +01:00
"\n",
2021-11-30 15:06:04 +01:00
"fig, axes = plot_signal_and_spectrum(signal_constant, sample_rate, \"Constant signal (masked zero)\", ft_kwargs={'mask_bias':True})\n",
"axes.flat[1].set_xlim(0,10);\n"
2021-11-23 15:22:20 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2021-11-25 18:49:42 +01:00
"### FTs: noise (normal distributed)\n",
"\n",
"A FT of normal distributed noise will not have easily identifiable peaks in the spectrum.\n",
2021-11-30 15:06:04 +01:00
"Instead, the spectrum is on average a bit flat, with only low power in any individual peak."
2021-11-25 18:49:42 +01:00
]
},
{
"cell_type": "code",
2021-11-30 15:06:04 +01:00
"execution_count": 5,
2021-11-25 18:49:42 +01:00
"metadata": {},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vE9EUImIiuo6ItgF4yStkR7fUEtHPiOgRIvqrVf4qIjqRiH5IRHuJaDsRiYeWMOAQ4SoIlcUGAAki+gsRXUhEDV4rEdFoAI8C+CGAUQDWA3iPa7VzreWjAfwGwD1ERNZve2HOtTkMwBcB3EJEZxX6YARBEAShgsn0zj0XQCvM9+hPATxORCOt3/4CIA7gBABnwpx7Wg0eXwZzbuPPw3zPfhpABzNfA2AbgE8x8xBm/o22rw8AeBeAjwes+6cA3A+gAcBbABbA7NcfC3N+7bsCliMI/QYRroJQQTDzYQDvA8AA5gLYR0RPEdFY16r/AmANMz9uuRT9AcBu1zptzDyXmRMwX7DjAYy19vMsM29mk1cBPA/TPUoQBEEQjgoCvHP3AriVmWPM/BDMweBPWr9fCOBbzHyEmfcCuAXAldZ2swH8hpmXWe/ZTczclqE6P7PK6glY/deZeYHVB3gEwBgAv2bmGIAHAUwhohEByxKEfoEIV0GoMJh5LTNfy8wTAZwCYAKAW12rTQCwXduGAbgzAe/Wfu+2Pg4BAGtkudlKRHEQphAeXdgjEQRBEITKJsM7d4f1flW0Wb83AqgGsIuIDlrv0bsAHGOtNwnA5iyrsj3zKg72aJ97AOy3BqrVd8B65wvCQEGEqyBUMMy8DsCfYb5MdXYBmKi+WC7AExEAIqoF8BiAmwCMZeYRAJ4DQGk3FARBEIQBjMc791gtxAYw41N3whSZfQBGM/MI628YM59srbcdwPF+uwmw/AiAevXFip0dk82xCMJARISrIFQQRDSDiL5DRBOt75MAXAWg2bXqswBOJaLPEFEVgH8HMC7gbmoA1ALYByBuJW2SJA6CIAjCUUWAd+4xAL5BRNVW3Oq7ADzHzLtghtjcTETDiCh
2021-11-25 18:49:42 +01:00
"text/plain": [
2021-11-30 15:06:04 +01:00
"<Figure size 1152x288 with 3 Axes>"
2021-11-25 18:49:42 +01:00
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"signal_normal_noise = rng.normal(size=n_samples)\n",
"\n",
"plot_signal_and_spectrum(signal_normal_noise, sample_rate, \"Noise (normal distributed)\");"
2021-11-23 15:22:20 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### FTs: sine wave"
]
},
{
"cell_type": "code",
2021-11-30 15:06:04 +01:00
"execution_count": 6,
2021-11-23 15:22:20 +01:00
"metadata": {},
"outputs": [
{
"data": {
2021-11-30 15:06:04 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA74AAAEjCAYAAAAVGd21AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOx9eZxdRZX/93QSQFkkEBbZsij7EjYRfuIAjmJYBHGZAR0RR2XUQRzXwXFD1FEZHJSRQdlEAcMmICAEGCFsEkICISQhgezp7Pu+dL97fn/ce9+rOrXcezvd/Ui/8/18ku73qurU91TVvX3P/dZCzAyFQqFQKBQKhUKhUCj6KtqaTUChUCgUCoVCoVAoFIqehAa+CoVCoVAoFAqFQqHo09DAV6FQKBQKhUKhUCgUfRoa+CoUCoVCoVAoFAqFok9DA1+FQqFQKBQKhUKhUPRpaOCrUCgUCoVCoVAoFIo+DQ18FQqFQqFQKBQKhULRp6GBr0KhUCgUCoVCoVAo+jQ08FUoFApFIYhoMhGd2k22ZhPR+7tQ7mAiepmI1hLRpd3BpdVARHsQ0eNEtJKIbmo2H4VCoVAoegsa+CoUCoUCAEBEJxPR34hoNRGtIKLniOhdAMDMhzPz6CZT/BaA0cy8MzNf02QubzqUfKHwbQBvMPNAZv7sVtS1GxHdR0TriWgOEX2iq/mLbJVIv4SIxhHRZiK6RaTNJqItRDRIfD+BiJiIhoi87xf5LiKiZ0s2i0KhUCjexNDAV6FQKBQgol0APATgfwDsBmBfAD8EsLmZvAQGA5jsSyCi/r3MZVvF+wHc3Q12rgWwBcBeAD4J4DoiOryL+YtsFaUvA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zv12
2021-11-23 15:22:20 +01:00
"text/plain": [
2021-11-30 15:06:04 +01:00
"<Figure size 1152x288 with 3 Axes>"
2021-11-23 15:22:20 +01:00
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2021-11-25 18:49:42 +01:00
"f = 1e2 # Hz\n",
"if f > sample_rate/2:\n",
" print(\"Sampling a frequency above the sample_rate/2 gives problems\")\n",
2021-11-23 15:22:20 +01:00
"\n",
2021-11-25 18:49:42 +01:00
"signal_sine = np.sin( 2*np.pi*f*t )\n",
"if False:\n",
" # aliased peak\n",
" signal_sine += 1/2*np.sin( 2*np.pi* (1.1* sample_rate/2) *t)\n",
"\n",
2021-11-30 15:06:04 +01:00
"fig, axes = plot_signal_and_spectrum(signal_sine, sample_rate, \"Single frequency at $f = {:g}$MHz\".format(f/10**6))\n",
"axes.flat[1].axvline(sample_rate/2, color='r', label='Nyquist Frequency');\n",
"axes.flat[1].legend();"
2021-11-23 15:22:20 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A sine wave will give very clear peaks at the frequency of the sine wave."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### FTs: step function"
]
},
{
"cell_type": "code",
2021-11-30 15:06:04 +01:00
"execution_count": 7,
2021-11-23 15:22:20 +01:00
"metadata": {},
"outputs": [
{
"data": {
2021-11-30 15:06:04 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7sAAAEjCAYAAADzMBbxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOzdd3yV9fn/8deVAWETIGySMEWGgiDgwD1wYbXVuqrWqtXWrp/ja5el2tpdW7V1W7Wi1l20WLWgiANkKChDCCNsQtgbkly/P+478RCygJzc5yTv5+NxHjnn3J9zn+u+75Nzn+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GhLMPfkseWKDQ+fbwf8HngsZvqQAuBcoCXwTeCe0qlGREREGojqzrnDCUaXbwf8AnjZgunVAJ4kGDG8F8E0WGcApRecLwLGAFcSnGdHA+vd/RsEI8efF04z9vuY9zqRYGqxM2sY+3kEU3dlEoym/ibBb/suBCOqP1TD9YjUW0p2RRKMu28hmEbDgUeAdWY2zsw6lCt6NjDH3V8OmzvdC6wpVybf3R8Jp2d5EugEdAjf5z/uvsgDkwimjBkZvy0TERFJLDU45xYAf3H3ve7+L4ILyOeEy88Cfuju2929ALgHuCR83bXA7919WniezXP3/GrCGROuq9I5tMuZ7O5vhr8BXgCyCKbd2kswX3huOF+1SIOlZFckAbn7PHe/2t27AgOAzsBfyhXrDCyPeY0TzDEaa03M8h3h3eYA4RXsKeFgHJsIkud2tbslIiIiia2ac+7KcnNM54fLcwjms14dzuO9iaAmtX1Yrhuw6ABDWV59kX2sjbm/EygML26XPob
2021-11-23 15:22:20 +01:00
"text/plain": [
2021-11-30 15:06:04 +01:00
"<Figure size 1152x288 with 3 Axes>"
2021-11-23 15:22:20 +01:00
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"data": {
2021-11-30 15:06:04 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7sAAAEjCAYAAADzMBbxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOzdd3gc5dX38e9RccNFsuWCi9yNcW8YE0yA0GyKTWihBwIYCCQkD4EQHh5CSPImIYXQQg0lxKFDMMSEYnqxcTe4y0W23GS5yHK3pPP+MSOzltWt1a5Wv8917aXdnXtmzuysdvbs3czdEREREREREUkkSbEOQERERERERKS2KdkVERERERGRhKNkV0RERERERBKOkl0RERERERFJOEp2RUREREREJOEo2RUREREREZGEo2RXREREREREEo6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Kng7Md/dXw+ZO9wPrS5XJdvfHw+lZngEOB9qH+/mPuy/zwEcEU8YcF70jExERiS9VuObmAn91933u/gLBD8hnhMvHAj9x9x3ungvcC1wYrnc1cI+7Tw+vs1nunl1JOHeF29pVSbkSn7j72+F3gJeAtgTTbu0jmC+8WzhftUiDpWRXJA65+0J3v8LdOwMDgI7AX0sV6wisjljHCeYYjbQ+YvnO8G5zgPAX7KnhYBxbCZLnjNo9EhERkfhWyTV3Tak5prPD5V0J5r5eF87jvZWgJrVdWK4LsKyaoayuvMgBNkTc3wXkhT9ulzyG8Jov0lAp2RWJc+6+CHia4AIcaR3QueRB2Dy5M1VgZo2BV4A/Ae3dPQ2YDFiFK4qIiCSwMq65nSK6/0DQ33YtQWK6B8hw97Tw1tLd+4flVgM
2021-11-23 15:22:20 +01:00
"text/plain": [
2021-11-30 15:06:04 +01:00
"<Figure size 1152x288 with 3 Axes>"
2021-11-23 15:22:20 +01:00
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2021-11-25 18:49:42 +01:00
"t_0 = t[n_samples//4]\n",
2021-11-23 15:22:20 +01:00
"signal_step = np.heaviside(t - t_0, 1)\n",
2021-11-30 15:06:04 +01:00
"fig, axes = plot_signal_and_spectrum(signal_step, sample_rate, \"Step function $t_0 = {:g}ns$\".format(t_0 * 10**9), ft_kwargs={'mask_bias':True});\n",
"axes.flat[1].set_xlim(0, 20);\n",
2021-11-23 15:22:20 +01:00
"\n",
"t_0 = t[n_samples//2]\n",
"signal_step = np.heaviside(t - t_0, 1)\n",
2021-11-30 15:06:04 +01:00
"fig, axes = plot_signal_and_spectrum(signal_step, sample_rate, \"Step function $t_0 = {:g}ns$\".format(t_0 * 10**9), ft_kwargs={'mask_bias':True});\n",
"axes.flat[1].set_xlim(0, 20);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### FTs: delta function\n",
"\n",
"All frequencies are accounted for, but the phase alternates"
]
},
{
"cell_type": "code",
"execution_count": 8,
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1xn35S0s6TbSO7l/WA6M/r5koZKCkmnSpoO/EvSPhmzutfX92mLsKSLJf1d0l/S+l+XtKWkH0uaI2mGJPcEszbPya5Z4XkHWCPpVkmHSOreWCFJvYC7gR8DPYG3gd0bFNs1Xd4L+A1wU8Y9MucAhwGbkNx25or6+2mamZm1Ec1dc3cFppJcRy8C7pFUf7/sW0lui7UFyf2eDwTqf3A+DriYZFK6TUhucTY/Ir5Jcnu0w9N7af8mY197k9wT+6AsYz+c5P7U3YGXgcdIvtsPILlt2HVZ1mNWspzsmhWYiFhMcq/IAG4A5kp6QFLfBkUPBd6IiHvS7k5XAR82KFMTETek9yC9FegH9E3383BEvBeJccDjJF23zMzM2oQsrrlzgN9FxKqIuJPkB+Qvp+sPAc6JiKURMQe4AhiTbnca8JuIeCm9zk6JiJpmwrk4rWtZluGPj4jH0u8Afwd6k9xbehVwBzBUUrcs6zIrSU52zQpQREyOiJPT2ZC3BfoDv2tQrD8wI2ObAGY2KPNhxvpP0qcbA6S/YE9IJ+NYSJI892rZIzEzMytszVxzP4jP3rqkJl0/BGgHzJa0ML2OXgf0ScsNAt5bx1BmNF/kMz7KeL4MmJf+uF3/GtJrvllb5WTXrMBFxFvALSQX4EyzgU9vDZR2T87qVkGSOgD/AH4L9I2IbsBYQGvd0MzMrIQ1cs0dkDH8B5LxtrNIEtMVQK+I6JY+NomIkWm5GcDmTe0mi+VLgU71L9KxwL3X5VjMzMmuWcGRtLWk8yQNTF8PAk4AJjQo+jCwnaSjJFUAZwGbZrmb9kAHYC6wOp24yhNZmJlZm5LFNbcP8H1J7dJxuNsAYyNiNsnwn8skbSKpTNLmkvZOt7sR+JGkUUpsIWlIuu4jYFgzob0DdJT0ZUntgAt
"text/plain": [
"<Figure size 1152x288 with 3 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"index_t0 = n_samples//8\n",
"t_0 = t[index_t0]\n",
"signal_step = np.zeros(n_samples)\n",
"signal_step[index_t0] = 1\n",
"\n",
"fig, axes = plot_signal_and_spectrum(signal_step, sample_rate, \"Delta function $t_0 = {:g}ns$\".format(t_0 * 10**9), ft_kwargs={'mask_bias':True});\n",
"axes.flat[1].set_xlim(0, 20);"
2021-11-23 15:22:20 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Peculiarities $F^{-1}( F(A(t)) ) \\sim A(t)$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2021-11-25 18:49:42 +01:00
"# DFT\n",
"\n",
"A naive implementation of a DFT is simple to setup by implementing Eq. (1)\n",
"\n",
"$$\n",
"\\hat{f}(\\omega) = F(t) = \\frac{1}{\\sqrt{2\\pi}} \\sum_{k=0}^{N-1} f(t_k)\\, \\exp{ \\left(-i \\omega t_k \\right)}\n",
".\n",
"$$"
]
},
{
"cell_type": "code",
2021-11-30 15:06:04 +01:00
"execution_count": 9,
2021-11-25 18:49:42 +01:00
"metadata": {},
"outputs": [],
"source": [
"def naive_DFT( signal ):\n",
" \"\"\"\n",
" Calculate DFT in a naive way, returns a complex DFT.\n",
" \"\"\"\n",
"\n",
" N = np.size(signal)\n",
"\n",
" x_k = 2*np.pi/N*np.arange(N)\n",
" ft = np.zeros(N, dtype=np.complex128)\n",
" for j in range(N):\n",
" ft[j] = np.dot(signal, np.exp(- 1j * j * x_k ))\n",
"\n",
" return ft"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### DFT: Cooley and Tukey (or Divide and Conquer)"
2021-11-23 15:22:20 +01:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2021-11-25 18:49:42 +01:00
"A smarter DFT (Cooley and Tukey) can be implemented by splitting the sum in Eq. (1) into two parts: $k$ even and $k$ odd.\n",
2021-11-23 15:22:20 +01:00
"\n",
2021-11-25 18:49:42 +01:00
"With a uniform sample space $t$, the label $t_k$ can be rewritten to $t_k = k \\Delta t = $.\n",
2021-11-23 15:22:20 +01:00
"\n",
"This gives\n",
"$$\n",
2021-11-25 18:49:42 +01:00
"F(t) = \n",
" \\frac{1}{\\sqrt{2\\pi}} \\sum_{k=0}^{N/2-1} f(t_{2k})\\, \\exp{ \\left(-i \\omega \\, t_{2k} \\right)}\n",
2021-11-23 15:22:20 +01:00
" +\n",
2021-11-25 18:49:42 +01:00
" \\frac{1}{\\sqrt{2\\pi}} \\sum_{k=0}^{N/2-1} f(t_{2k+1})\\, \\exp{ \\left(-i \\omega \\, t_{2k+1} \\right)}\n",
2021-11-23 15:22:20 +01:00
" \\\\\n",
" =\n",
" \\frac{1}{\\sqrt{2\\pi}} \\sum_{k=0}^{N/2-1} f(t_{2k})\\, \\exp{ \\left(-i \\omega \\, 2k \\Delta t \\right)}\n",
" +\n",
2021-11-25 18:49:42 +01:00
" \\frac{1}{\\sqrt{2\\pi}} \\sum_{k=0}^{N/2-1} f(t_{2k+1})\\, \\exp{ \\left(-i \\omega \\, 2k \\Delta t \\right)}\\exp{ \\left(-i \\omega \\, \\Delta t \\right)}\n",
2021-11-23 15:22:20 +01:00
" \\\\\n",
" =\n",
" \\frac{1}{\\sqrt{2\\pi}} \\sum_{k=0}^{N/2-1} f(t_{2k})\\, \\exp{ \\left(-i \\omega \\, 2k \\Delta t \\right)}\n",
" +\n",
2021-11-25 18:49:42 +01:00
" \\frac{\\exp{ \\left(-i \\omega \\, \\Delta t \\right)} }{\\sqrt{2\\pi}} \\sum_{k=0}^{N/2-1} f(t_{2k+1})\\, \\exp{ \\left(-i \\omega \\, 2k \\Delta t \\right)}\n",
" \\\\\n",
" =\n",
" F(t_{even}) + F(t_{odd}) \\exp{ \\left(-i \\omega \\, \\Delta t \\right)}\n",
2021-11-23 15:22:20 +01:00
"$$"
]
},
{
"cell_type": "code",
2021-11-30 15:06:04 +01:00
"execution_count": 10,
2021-11-23 15:22:20 +01:00
"metadata": {},
"outputs": [],
"source": [
2021-11-25 18:49:42 +01:00
"def cooley_tukey_DFT( signal ):\n",
" \"\"\"\n",
" Calculate a DFT according to the Cooley and Tukey algorithm (radix-2)\n",
" also known as Divide and Conquer.\n",
" \n",
" It divides the terms into 2 streams with odd and even index.\n",
" \"\"\"\n",
" radix = 2\n",
"\n",
2021-11-23 15:22:20 +01:00
" N = np.size(signal)\n",
2021-11-25 18:49:42 +01:00
" \n",
" if N <= radix:\n",
" return naive_DFT(signal)\n",
" \n",
" if N % radix > 0:\n",
" raise ValueError(\"Provide a signal with N%{radix} == 0 values.\".format(radix=radix))\n",
" \n",
" # divide and conquer\n",
" DFT_even = cooley_tukey_DFT(signal[::radix])\n",
" DFT_odd = cooley_tukey_DFT(signal[1::radix])\n",
" \n",
" phase_terms = np.exp( -2j * np.pi * np.arange(0, N) / N )\n",
" \n",
" return np.tile(DFT_even, 2) + np.tile(DFT_odd,2) * phase_terms\n"
]
},
{
"cell_type": "code",
2021-11-30 15:06:04 +01:00
"execution_count": 11,
2021-11-25 18:49:42 +01:00
"metadata": {},
"outputs": [
{
"data": {
2021-11-30 15:06:04 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA74AAAEjCAYAAAAVGd21AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOy9ebxfVXU2/qyESSYJMzKjiBNOoOJb+zorOKC1g6BVsVpfbamt2vpqa9VS+zq0/rRWqwIiziiKCsggVUFAAyTMhASSQEgIkDmEJCS596zfH+ec79l77bX2OefekO+9uev5fCDfc/bea6+19j7n7nWePRAzw+FwOBwOh8PhcDgcju0V04atgMPhcDgcDofD4XA4HI8lPPB1OBwOh8PhcDgcDsd2DQ98HQ6Hw+FwOBwOh8OxXcMDX4fD4XA4HA6Hw+FwbNfwwNfhcDgcDofD4XA4HNs1PPB1OBwOh8PhcDgcDsd2DQ98HQ6Hw+FwOBw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XA4tnt0+Hu7DMAXmXkLM/8Q5Yfk11bpJwH4O2Zez8zLAHwBwClVuXcD+Bwz31D9jZ3PzIta1PlkJWtjR/WvZubLq7//5wPYD8BnmHkLgPMAHEFEe3WU5XBMGnjg63BsZ2DmO5n5NGY+BMAzADwBwBdFticAWByUYZRni4Z4MEjfUP3cHQCqr9szq8081qAMpPfdupY4HA6HwzFx0fL39n6OzwxdVKUfDmBHAA9UZ26vQcmw7l/lOxTAgp6qLG7PEuGh4PdGACuqj9z1NeB7Dzi2Q3jg63Bsx2DmuQDORfkHOcQDAA6pL6opzIegA4hoZwA/AfAfAA5g5r0AXAK
2021-11-25 18:49:42 +01:00
"text/plain": [
2021-11-30 15:06:04 +01:00
"<Figure size 1152x288 with 3 Axes>"
2021-11-25 18:49:42 +01:00
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"f = 1e2 # Hz\n",
"if f > sample_rate/2:\n",
" print(\"Sampling a frequency above the sample_rate/2 gives problems\")\n",
2021-11-23 15:22:20 +01:00
"\n",
2021-11-25 18:49:42 +01:00
"signal_sine = np.sin( 2*np.pi*f*t )\n",
2021-11-23 15:22:20 +01:00
"\n",
2021-11-30 15:06:04 +01:00
"fig, axes = plot_signal_and_spectrum(signal_sine, sample_rate, \"Single frequency at $f = {:g}$MHz\".format(f/10**6), ft_kwargs={'fft': cooley_tukey_DFT})\n",
"axes.flat[1].axvline(sample_rate/2, color='r', label='Nyquist Frequency');"
2021-11-23 15:22:20 +01:00
]
}
],
"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.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}