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-30 17:14:50 +01:00
"import matplotlib.ticker as tck\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",
2021-11-30 15:35:09 +01:00
"Higher frequencies will fall in between two adjacent samples. This means that these frequencies are then 'measured\\` with differing phases in such a way that they are 'folded' around the Nyquist frequency and appear as aliased frequencies below it.\n",
2021-11-25 18:49:42 +01:00
"\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:35:09 +01:00
" real_signal = np.isrealobj(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",
2021-11-30 15:35:09 +01:00
" if plot_amplitude or plot_complex:\n",
2021-11-30 15:06:04 +01:00
" 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",
"\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-30 15:35:09 +01:00
" ax.legend()\n",
"\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",
2021-11-30 17:14:50 +01:00
"n_samples = int(1e4)\n",
2021-11-23 15:22:20 +01:00
"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+XJIDIECCRKYQERZE6AEYEjYWKVXDCoQ6IRYaW8qhH26PHg62PejzHp7Z1P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KG5pIEmSJE17ntIsSZIkSeokR3glSZIkSZ00u+0A42XevHm1aNGitmNIkjpi+fLlt1WV97ccA/tmSdJ42py+uTMF76JFi1i2bFnbMSRJHZHkhrYzTHf2zZKk8bQ5fbOnNEuSJEmSOsmCV5IkTYh1997P8hvubDuGJGkGs+CVJEkkOSPJuiRXDrI9ST6SZEWSy5McONw+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/FHVcml6n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2SX7TPBx3c9sgky5LckWRFktfP/EeVJKlrxmpv/yfJv7Zt7FVJ9hvcMMlmSU5OsirJdUn+sX3e9WD56zra2CuT7Jnki8COwLfbR3S9M8nCJJXktUl+BfxXkn2TrOwMtLNnOMn7k3wtyZfa/f84yaOSvCvJjUmuTeJoMM0pJrzS7PJT4N4kpyY5MMkWw1VKMp/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-30 17:14:50 +01:00
"signal_constant = np.ones(int(n_samples))\n",
2021-11-25 18:49:42 +01:00
"\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": {},
"outputs": [
{
"data": {
2021-11-30 15:06:04 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA64AAAEjCAYAAAAyt1xdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOydeZwcVbn3f0/3bJmsk4UsJJkQCInsMCBBRXGXK4oXZI0oXoLb9arX7VWvoqLe61UQVLhAAqJgwo7sGkDWkEyWgYQkZJ9kksmeSSeZySy91PP+UXWqT1VXdVfvPZPn+/lM0l1ddepU1amq8zvPcoiZIQiCIAiCIAiCIAiVSqjcFRAEQRAEQRAEQRCEdIhwFQRBEARBEARBECoaEa6CIAiCIAiCIAhCRSPCVRAEQRAEQRAEQahoRLgKgiAIgiAIgiAIFY0IV0EQBEEQBEEQBKGiEeEqCIIglAwi+jsRfaEI5X6ZiG4tdLnFgIiYiE4IuO7PiOiv1ufJRNRFROEC1eNOIvqJ9fkCImovRLk51uXPRPRL6/NpRLSoXHURBEEQKhMRroIgCEJgiGgrEe0hosHastlE9EqQ7Zn5Qmb+S4HrVAPgxwB+W8hyKw1m3sbMQ5g5kW49IrqWiBYGKO8rzPyLQtQtGzGeCWZ+G8BBIvpUIcoTBEEQBgYiXAVBEIRsqQLwzXJXQuNiAOuYeUehCyaiqkKXWQkUympbROYB+HK5KyEIgiBUDiJcBUEQhGz5LYDvEtEIrx+J6D1EtIyIDln/v0f77RUimm19PoGIXrXW209ED2nrzSCiF4joABGtJ6LL09TnQg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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/BaA0cy8MzNf02QubzqUfKHwbQBv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VUgD6UHd64lCoVAoFG9eFPy9nc/2maFzsvTBAAYAWJidub0KqcK6Z5ZvfwAzKlKZV5zFwmLj940AlmUvufPPgO49oOiD0MBXoejDYOapAG5B+gfZxEIA++UfsinM+6EEiGh7AH8CcBWAvZh5VwAPA6BoQYVCoVAo+ig8f2/3NZYHAen63AVIg9TNAAYx867Zv12
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",
2021-11-30 15:35:09 +01:00
"\n",
2021-11-25 18:49:42 +01:00
"if False:\n",
" # aliased peak\n",
2021-11-30 15:35:09 +01:00
" f_alias = (1.1* sample_rate/2)\n",
" signal_sine += 1/2*np.sin( 2*np.pi* f_alias *t)\n",
2021-11-25 18:49:42 +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))\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."
]
},
2021-11-30 17:14:50 +01:00
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA80AAAHgCAYAAACfG480AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpY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cZ8Lf/6nl99MDRnn3NdyXc1ctZi4j4t39at5fiz69c3NU0NLHvVA1uCw4Do2LDCQ8N6rT9bXER/OPc0V3OweVysWnTJhYvXkxJSQlr165l27ZtBAUF8fjjj7N69WoeeeSRdv0ee+wxFi5cyNtvv82qVatYtmwZeXl5TJo0CYCsrCxqamra9Vu+fDl33fXF3xdlZWUMHTrUcx0fH8/27dvb9LlSm+TkZKZOncqTTz5JVlYW06dP5+WXXyYiIqLLv4PepKJZRETED7mtm/zyfGYMndHmvnW7qdq2m5ChYZyf/T36v/Em1Rs3M+Bvv2gTFBDEuMHjyCvXw8BERLyhuqEZt2353m1brq9UNHdVfX09TqeTo0ePMmHCBLKzs3nllVcoKCggMzPT0yY6Orpd37KyMo4fP86CBQt46qmnSE9PZ9iwYTQ2NnrabN26tUt5WGvb3TPGXFWbvXv3kpaWBsC+fftISUnp0ti+oKJZRETEDx08f5Cqi1XtlmY3bP4dTVWWoHumgsNBxNSxnPm/RTQd2kVQ8jhPu8zYTF4ufJnKhkr6h/bv7fRFRPxWV2aEC46dZ+Frn9DU7CYo0MGL89OZkDCg22O37mmuqqpizpw55ObmYoz
"text/plain": [
"<Figure size 1152x576 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"with_spectrum = True\n",
"phase_offsets = np.linspace(0, 2*np.pi, 8, endpoint=False) # rad\n",
"f = 1e2 # Hz\n",
"\n",
"if f > sample_rate/2:\n",
" print(\"Sampling a frequency above the sample_rate/2 gives problems\")\n",
"\n",
"if with_spectrum:\n",
" fig, axes = plt.subplots(2,1, sharex=True, figsize=(16,8))\n",
"else:\n",
" fig, ax = plt.subplots(figsize=(16,4))\n",
" axes = np.array([None, ax])\n",
" \n",
"if with_spectrum:\n",
" axes[0].set_ylabel(\"Amplitude\")\n",
" axes[0].axvline(f, alpha=0.3, label='f = {:g}Hz'.format(f))\n",
"\n",
"axes[1].axvline(f, alpha=0.3, label='f = {:g}Hz'.format(f))\n",
"axes[1].set_ylabel(\"Phase\")\n",
"axes[1].set_xlabel(\"f\")\n",
"axes[1].set_xlim( f-2, f+2)\n",
"axes[1].set_ylim( -1 - 0.2, 1+ 0.2)\n",
"axes[1].grid()\n",
"axes[1].yaxis.set_major_formatter(tck.FormatStrFormatter('%g $\\pi$'))\n",
"axes[1].yaxis.set_major_locator(tck.MultipleLocator(base=0.5))\n",
"\n",
"for phase in phase_offsets:\n",
" signal = np.sin( 2*np.pi*f*t + phase )\n",
" \n",
" ft_signal, freqs = ft_spectrum(signal, sample_rate)\n",
" \n",
" if with_spectrum:\n",
" axes[0].plot(freqs, np.real(ft_signal), '.-', label='Re $\\\\varphi = {}\\\\pi$'.format(phase/np.pi))\n",
" \n",
" axes[1].plot(freqs, np.angle(ft_signal)/np.pi, '.-', label='$\\\\varphi = {}\\\\pi$'.format(phase/np.pi))\n",
"\n",
"# trigger legends\n",
"if with_spectrum:\n",
" axes[0].legend(loc='center right');\n",
"axes[1].legend(loc='center right');\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For a sine wave, the phase of the spectrum at it's frequency is $\\theta( \\varphi = 0 ) = - \\dfrac{\\pi}{2}$."
]
},
2021-11-23 15:22:20 +01:00
{
"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/ja5el2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JmNsbMXjCzp8P1f2Zmfczsx2ZWYGbLzUwtwaTBU7IrkngWAMVm9qSZnRVOCbIfM2sHvAj8GGhLMPfkseWKDQ+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 17:38:49 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7sAAAEjCAYAAADzMBbxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOzdeZhcZZn///ddVb0k6U56S0KSzk7CFtZECAMqiCKgiOioLKODI2Z0XMb56SjOV4VxGZdxmXEGkSAMjIOAIiAIiAuLgCSQZgmEEAiddNJJSNJLlu70Xvfvj3OqunrvpLu6qiuf13X11fXUOafOc+rUdp/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qc034WC3DrP7j7v5Q+BvgV8BUgum5OgjmAp9nZiXDfCyRnKRgVyQLuft6d7/C3SuBJcBM4D96rTYT2JqyjRPMH5rqjZTlB8KbRQDhFexV4WAcewiC54rRPRIREZHsNsR37rZec1HXhMvnEsxrvSOco3sPQSZ1WrjebOD1g6zK1qFX6WFnyu0WoC68uJ0oQ/idL3K4UrArkuXc/RXgZoIv4FQ7gMpEIWyeXMkwmFkB8Gvg+8B0dy8BHgBs0A1FRERyWD/fubNSuv9A0N92O0Fg2gZUuHtJ+DfZ3Y8L19sKLBxoN8O4vxmYmCiEfYGnHsyxiIiCXZGsY2ZHm9nnzawyLM8GLgVW9Vr1fuB4M3uvmcWATwFHDHM3+UABsBvoDAeu0kAWIiJyWBnGd+404LNmlhf2wz0GeMDddxB0//mBmU02s4iZLTSzt4bb/Qz4gpkttcCRZjY3XLYTWDBE1V4FCs3sXWa
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": [
2021-11-30 17:38:49 +01:00
"### FTs: delta peak\n",
2021-11-30 15:06:04 +01:00
"\n",
2021-11-30 17:38:49 +01:00
"All frequencies are accounted for with the same amplitude, but the phase will change depending on the position of the delta peak within the signal.\n",
"\n",
"Still, the individual phases are linearly related to their corresponding frequencies."
2021-11-30 15:06:04 +01:00
]
},
{
"cell_type": "code",
2021-11-30 17:38:49 +01:00
"execution_count": 9,
2021-11-30 15:06:04 +01:00
"metadata": {},
"outputs": [
{
"data": {
2021-11-30 17:38:49 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7sAAAEjCAYAAADzMBbxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOy9d7glV3Xm/VsVzrmpb2d1UOhuBYyFQEIRZVkiCAy2GQfAHtv4g/HYYwZnPMz4GzMe+xuPPwfMIMZjG8wYjMFg7BEmB4uckcEgBEig1JK6FTp333sqrPmjdlXtqtp1zu3WbXVgv8/T0r1nnUrr7Dp3v+t91y5RVTw8PDw8PDw8PDw8PDw8TiYEx/oEPDw8PDw8PDw8PDw8PDyWG57senh4eHh4eHh4eHh4eJx08GTXw8PDw8PDw8PDw8PD46SDJ7seHh4eHh4eHh4eHh4eJx082fXw8PDw8PDw8PDw8PA46eDJroeHh4eHh4eHh4eHh8dJB092PTw8PDw8PDw8PDw8PE46eLLr4eHh4eHh4eHh4eHhcdLBk10PDw+P7zKIyF0i8vRl2tf3iMitIrJPRF6+HPs8jGN/TUSuezyPeTzgWH9+y3n8Y42T6Vo8PDw8PLrwZNfDw8PjBIOZoB8yBGW3iHxKRH5ORA77O30ZJvuvAG5R1RWq+prHsJ+xcJ2nqj5JVW85Wsc8nHNpxV8mIl8QkUUReWPPezaLyH2t184RkQURefNSj7UMGPv5eTLo4eHh4XEiw5NdDw8Pjx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Dw8PL6rsIS/uacALxeR2PThfi/wHlV9gKL95w9FZF5EAhE5S0SuNdv9BfBrInKRFDhbRLaY2A7gzAmn9k1gSkS+X0R
"text/plain": [
"<Figure size 1152x288 with 3 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7sAAAEjCAYAAADzMBbxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOy9eZgkR3Xo+ztZVb2vMz3TPfu0pBFoQfuKJBAakISEkDBiNxgMhudrDDwbc8GXe5F5xsZ8Fy+A2THYAiyQECCBEBiDkIT2DbQh0DKSZp+emd63qsrz/sjMqszIzMqqnmrNQvy+b6b61Mkl4mRkVpw4JyJFVbFYLBaLxWKxWCwWi+VQwtnfBbBYLBaLxWKxWCwWi6XZWGfXYrFYLBaLxWKxWCyHHNbZtVgsFovFYrFYLBbLIYd1di0Wi8VisVgsFovFcshhnV2LxWKxWCwWi8VisRxyWGfXYrFYLBaLxWKxWCyHHNbZtVgsFovFYrFYLBbLIYd1di0Wi8VisVgsFovFcshhnV2LxWL5PUNENonIS5t0rOeJyP0iMiEi72nGMRs498Micu5zec4Dgf19/Zp5/v3NoVQXi8ViscSxzq7FYrEcZPgd9BnfQRkVkdtE5P8RkYaf6U3o7H8AuElVu1X1U/twnJoklVNVj1HVmxbrnI2UxdC/W0TuEZE5EflayjYrRWSziLSKyFdE5Gn/et4vIi+v91xNoOb1s86gxWKxWA5mrLNrsVgsByeXqGo3sA74OPA/ga/sh3KsAx7eD+c9kNkK/C3wbzW2uQi4EcgDzwIvBnqB/w18W0TWL24RK9jrZ7FYLJZDFuvsWiwWy0GMqo6p6nXA64A/EpFjoRI5/I6I7BKRp5JSVEXkSmAtcL2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CRK4Wka/7x39QRI4UkQ+JyE4ReVZEbCaY5fce6+xaLAcevwXKIvLvIvJyEelP2khEBoBrgA8BS4HHgBcam53ufz8AfAL4iogE76rcCbwC6MFbxfefROSkZlfGYrFYLJYDmKzf3NPxVvAeAD4CXOu/wgrg34ES3gryJwLnA8GA82uAK4C34P3OvhLYrapvxltt/hJV7VLVT4TO9WK815BdUGfZLwGuBPqB+4Ef4/XtVwEfxXt/tcXye411di2WAwxVHQfOxnvP5JeAXSJynYgMGpteBDysqtf66U6fwnuFR5inVfVL/is1/h1YAQz65/mhqj6hHr/Aey3HOYtXM4vFYrFYDizq+M3dCfyzqhZV9Vt4A8gX+/qXA+9T1SlV3Qn8E/B6f793AJ9Q1bv939nHVfXpjOJc4R+r3nn9t6jqj/0+wNXAMuDjqlrEe5/2ehHpq/NYFsshiXV2LZYDEFV9VFXfqqqrgWOBlcA/G5utxHvHarCP4r2XNMz2kH7a/7MLwB/BvsNfjGMUz3keaG5NLBaLxWI5sMn4zd2i0fd0Pu3r1wEFYJv/HupRvEjqcn+7NcATDRbl2exNIuwI/T0DjPiD24EM/m++xfL7inV2LZYDHFX9DfA1vB/gMNuA1YHgpyevpg5EpBX4DvB/gUFV7QNuAKTmjhaLxWKxHMIk/OauCk3/AW++7VY8x3QOGFDVPv9fj6oe42/3LHB42mnq+H4K6AgEfy7wskbqYrFYrLNrsRxwiMjzReQvRWS1L68B3gDcYWz6Q+AFInKZiOSBPwOG6jxNC9AK7AJK/sJVdiELi8VisfxeUcdv7nLgPSJS8OfhHgXcoKrb8Kb/fFJEekTEEZHDReTF/n5fBt4vIieLxxEiss7X7QAOyyjab4E2EblYRArAh/F+ty0WSwNYZ9diOfCYwFsQ404RmcL7wX0I+MvwRqo6ArwGb+Gp3cDRwD3U8boEVZ0A3oP3moW9wBuB65pXBYvFYrFYDgqyfnPvBDYAI8DHgMtVdbe
"text/plain": [
"<Figure size 1152x288 with 3 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "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RXgnl8z8OTXQ+PUw/fBjIR+TMReZ6IrO86SEQ2AX8LvAHYCNwKXN047Ar7+SbgTcA7RaR4L+Vu4AXAGszOvr8nIpeu9mA8PDw8PDxOYUz6m3sFZrfuTcCvAu+zr6sC+DMgxewq/0TguUCRcH4Z8Ebg1Zi/sy8C9qnqqzA70L9QVedU9U3Ota4BHk31mrFJeCHwF8B64F+BD2Pm9tuAX8O8q9rD43sanux6eJxiUNXDwFMx75R8B7BHRN4vIpsbhz4f+Lqqvs+WO70Z87oOF3er6jvs6zP+DNgKbLbX+QdVvV0NPoF5BcfTTtzIPDw8PDw8Ti2s4G/ubuD3VTVR1b/GJJC/39qfB/ycqi6o6m7g94CX23Y/AbxJVf/Z/p29TVXvntCdN9pzrXQN/6dU9cN2DvA3wBnAb6lqgnlv9nYRWbfCc3l4nJbwZNfD4xSEqn5TVW9Q1bOBi4GzgN9vHHYW5r2rRRvFvKvUxQOO/Zj9cQ7AZrBvsZtxHMSQ502rOxIPDw8PD49TGxP+5u7U+ns677b284AYuN++c/ogRkk90x53DnD7cXbl3smH1LDL+XkR2GuT28XvYP/me3h8r8KTXQ+PUxyq+i3gTzF/gF3cD5xd/GLLk89mBRCRIfB3wG8Dm1V1HfAhQMY29PDw8PDwOI3R8Td3m7P8B8x62/swxHQZ2KSq6+y/Nar6WHvcvcAj+i6zgs8XgJniF7sW+IzjGYuHh4cnux4epxxE5FEi8vMicrb9/RzgFcAtjUP/AXiciLxERCLgZ4AtK7zMABgCe4DUblzlN7Lw8PDw8Piewgr+5p4JvE5EYrsO99HAh1T1fszyn98RkTUiEojII0TkGtvuj4HXi8hlYnChiJxnbbu
2021-11-30 15:06:04 +01:00
"text/plain": [
"<Figure size 1152x288 with 3 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"\n",
2021-11-30 17:38:49 +01:00
"for n in [4, 2, -4]:\n",
" index_t0 = n_samples//n\n",
"\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, ft_kwargs={'mask_bias':True}, spectrum_kwargs={'plot_complex':True, 'plot_amplitude':True});\n",
" fig.suptitle(\"Delta function at ${}/{}$th of the sample\".format(np.sign(n), np.abs(n)))\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+FwOBwOh8OxXc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XFehPK8z7MALCeiC4noAJH1NQDuYOYLqmlRXwLwoMiziJnPqo5i+RaAgwAcUNXzi+poEGbmqwD8EuUUL4fD4XA4tnt0+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
}