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",
2021-11-30 18:03:17 +01:00
"execution_count": 14,
2021-11-30 15:06:04 +01:00
"metadata": {},
"outputs": [],
"source": [
2021-11-23 15:22:20 +01:00
"sample_rate = 1/1e-3 # s\n",
2021-11-30 18:03:17 +01:00
"n_samples = int(1e3)\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 18:03:17 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7wAAAEjCAYAAAAR7A2IAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO3de5xdZX33/c83kxOJhIQQEQhJiIJKEVRS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yYuTzG3uyX0PrXtw+w99liRJkrqWCa/UvZ5NaybIO2g9k+/3R/BIA0mSJGnCc0izJEmSJKkr2cMrSZIkSepKUzsdwFjZa6+9asmSJZ0OQ5LUJVavXn1HVfl8y1GwbZYkjaXH0jZ3TcK7ZMkSVq1a1ekwJEldIsnaTsfQKUnOBI4DNlTVIc26PYEvAUuAm4FXVtVdQx3HtlmSNJYeS9vskGZJktTf54Cj+607Bfh2VR0IfLtZliRpl2bCK0mSdlBV3wPu7Lf6eODzzfvPA7+/s+NsuO8hVq8dshNYkqS2MuGVJEnDsXdVrQdofj5+Zzvcfu+DvOozl5r0SpI6pmvu4ZUkSZ2XZAWwAmD6E57Elm3buXTNJg5fPK/DkUlSd9qyZQvr1q3jwQcf7HQoY2bmzJksXLiQadOmjfpYJrySJGk4bk+yT1WtT7IPsGGgQlV1OnA6wIx9DqypU6awfOn88YxTkiaVdevWsfvuu7NkyRKSdDqcUasqNm3axLp16zjggANGfTyHNEuSpOG4AHhd8/51wNeGs9M7XnSQvbuS1EYPPvgg8+fP74pkFyAJ8+fPH7MeaxNeSZK0gyRnAz8AnpxkXZLXA38P/G6SnwG/2yzv1BP2mNm+QCVJAF2T7PYay/N
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 18:03:17 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7wAAAEjCAYAAAAR7A2IAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOzdeXxddZ3/8dc7W5uUtmnTgtC9LCIiKK1QZlRQZhAQZRAXllFgxI7jguPIOOg42vLTn44by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+3o6QTJT2TfjP9HUn3Srog3XaepPskfU3SFknPpvOD5o49X9JTkrZLWiPpH0f+Us3MzDLT1+ft7yX9V/oZ+7SkE3IHSpos6RpJGyStk/SFdL7r3PYP5n3GPinpKEk/BGYDP0+n6PqUpLmSQtIHJD0P/FbS8ZLq8gPNrwxLWiLpJ5J+lJ7/MUmHSPq0pJckrZXk1mA2pjjhNSssfwLaJF0n6WRJU7rbSdI0krkxPw3UAM8Af9Vlt2PS9dNI5he9Jm+uz5eAU4FJwPnApZKOGuqLMTMzG6X6+rw9BlhD8hn6eeAWSVPTbdcBrcBBwOuAE4HcF87vBpaQzGc9CXgHUB8R7wOeB94eEftExFfynus44FXAW/sZ+9uBH5LMc/0QydzYJcAM4BLgyn6ex6woOOE1KyARsQ14AxDAVcBGSbdJ2q/LrqcAT0TELWnzp8uAF7rsUxsRV0VEG8mH8/7Afunz/DIi/hKJe4E7SZpymZkNmKRr0+rS40N0vl9LapD0iy7rJemLkv6UVtAuHIrns7GnH5+3LwHfjIiWiLiR5Avkt6XbTwb+OSJ2pHM/XwqcmR53AfCViHgg/YxdHRG1fYSzJD1Xf0e
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 18:03:17 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA64AAAEjCAYAAAAyt1xdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOydd5wU9fnHP88VOJB2FEGkW0DFClLUqFFj70YFTCImaswviWkmIUaxa2LXaBSwRgEVC4ooRaqUA+6QXo/jjjvaFe7gDriyu8/vj5nZm52d2Z3Znd3Zu3ver9fB7pTv95myM9/n+zRiZgiCIAiCIAiCIAhCqpLmtQCCIAiCIAiCIAiCEAlRXAVBEARBEARBEISURhRXQRAEQRAEQRAEIaURxVUQBEEQBEEQBEFIaURxFQRBEARBEARBEFIaUVwFQRAEQRAEQRCElEYUV0EQBCFpENG3RHRnAtr9NRG97Ha7iYCImIhOtLnto0T0ofq5DxHVEFG6S3K8SUQPq58vJqISN9qNUZb3iOhJ9fMZRLTMK1kEQRCE1EQUV0EQBME2RFRIRPuJ6BjdsruJaKGd/Zn5KmZ+32WZWgF4CMBzbrabajDzLmZux8z+SNsR0VgiWmKjvfuY+Qk3ZHOijEeDmdcBqCKi69xoTxAEQWgeiOIqCIIgOCUDwB+8FkLHDQC2MPNutxsmogy320wF3LLaJpDJAH7ttRCCIAhC6iCKqyAIguCU5wA8QESdzFYS0XlEtIqIDqr/n6dbt5CI7lY/n0hEi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J6JMNW71FADfMPNeKCE2LxBRByJKI6ITiOgidb+3ADxARENI4UQi6quu2w9gQBTRtgH
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 18:03:17 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA74AAAEjCAYAAAAVGd21AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOzdeXxU9b3/8dcnC4uyL+ICElBQESsiWrx6FbW1Lrgg1YJal1a5bbXWW5eqtWq9+qttrWutdde2FKiI1oW6ArYuYQmiIItiIBJR1rBvSebz++OcCZPJTDJZJpPl/Xw88sicc77nnM+czGTmc76buTsiIiIiIiIiLVVWpgMQERERERERSSclviIiIiIiItKiKfEVERERERGRFk2Jr4iIiIiIiLRoSnxFRERERESkRVPiKyIiIiIiIi2aEl8RERERERFp0ZT4ioiIiIiISIumxFdERGpkZp+Y2YgGOtZyM/tWHfY7yMw+NLPNZnZ1Q8TS2phZTzN708xKzOzJTMcjIiLSWJT4iogIAGZ2nJm9b2YbzWy9mb1nZkcBuPuh7j4jwyHeAMxw947u/mCGY2lyUryhcBPwmbt3dfcf1uNc3czsBTPbamZFZnZB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U8ndz80LLcCOCDZaVJYvxXYI7oQ9h3uWZvnItJSKfEVaUHM7GAzu9bMeofLfYCxQH5c0VeBw8zsHDPLAa4E9k7xNG2AtsAaoCwc9EoDYYiISKuRwuftXsDVZpYb9ts9BJgaTu32BvAHM+tkZllmdoCZnRDu9wRwnZkdaYEDzaxvuG0V0L+G0D4F2pnZGWaWC9xC8Jkt0uop8RVpWTYTDKgx08y2Enw
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",
2021-11-30 18:03:17 +01:00
"execution_count": 53,
2021-11-30 17:14:50 +01:00
"metadata": {},
"outputs": [
2021-11-30 18:03:17 +01:00
{
"name": "stderr",
"output_type": "stream",
"text": [
"/software/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:30: RuntimeWarning: invalid value encountered in double_scalars\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.0 0.0 nan\n",
"0.7853981633974483 0.7071067811865475 1.2337005501361697\n",
"1.5707963267948966 1.0 2.4674011002723395\n",
"2.356194490192345 0.7071067811865476 11.103304951225525\n",
"3.141592653589793 1.2246467991473532e-16 6.580790147320947e+32\n",
"3.9269908169872414 -0.7071067811865475 30.842513753404255\n",
"4.71238898038469 -1.0 22.206609902451056\n",
"5.497787143782138 -0.7071067811865477 60.45132695667229\n"
]
},
2021-11-30 17:14:50 +01:00
{
"data": {
2021-11-30 18:03:17 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA80AAAHgCAYAAACfG480AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOzdaVyTd77//9eVhCUkCAiCIiIqBBVUUFCxblVRqwhVSRftaF2mc6adOZ52Zs50Tud05j+nZ9pZzuOc2lrn8Zvu1W4X7kup1qVabVXc60JAXBAXXCkJa5LrfyOWal1qFUjAz/NOG7iSfEKr5J33dX2/iqZpCCGEEEIIIYQQ4no6bw8ghBBCCCGEEEL4KgnNQgghhBBCCCHETUhoFkIIIYQQQgghbkJCsxBCCCGEEEIIcRMSmoUQQgghhBBCiJuQ0CyEEEIIIYQQQtyEwdsDNKeIiAgtLi7O22MIIYQQTa6qzglAkP899ateCCHEPW7nzp3nNU1r15iPeU/9Jo2Li6OgoMDbYwghhBBNbufxiwD069zWy5MIIYQQzUdRlOON/ZhyerYQQgghhBBCCHETEpqFEEIIIYQQQoibkNAshBBCCCGEEELchIRmIYQQQgghhBDiJiQ0CyGEEEIIIYQQN3FPrZ4thBBC3CuKK77m8OU96I1DSYlM8fY4QgghRIslTbMQQgjRyq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VHV6EWqhy6eAijwcjYuLFYLVaSI5K58jtHNIGwwDCmJ01nWs9p7DizA9Wm8mHhhyw4tIB+Uf2wWqxkds7EX+/v7VGFEELcY3w
2021-11-30 17:14:50 +01:00
"text/plain": [
"<Figure size 1152x576 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2021-11-30 18:03:17 +01:00
"if True:\n",
" sample_rate = 1/1e-3 # s\n",
" n_samples = 1e\n",
" t = np.arange(n_samples) / sample_rate\n",
2021-11-30 17:14:50 +01:00
"\n",
2021-11-30 18:03:17 +01:00
"f = 100 # Hz\n",
2021-11-30 17:14:50 +01:00
"if f > sample_rate/2:\n",
" print(\"Sampling a frequency above the sample_rate/2 gives problems\")\n",
"\n",
2021-11-30 18:03:17 +01:00
"offsets = np.linspace(0, 2*np.pi, 8, endpoint=False)\n",
"\n",
"signals_sine = np.sin( 2*np.pi*f*t )\n",
"\n",
"with_spectrum = True\n",
"\n",
2021-11-30 17:14:50 +01:00
"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",
2021-11-30 18:03:17 +01:00
"axes[1].set_xlim( f-5, f+5)\n",
"axes[1].set_ylim( -1*np.pi - 0.2, np.pi + 0.2)\n",
2021-11-30 17:14:50 +01:00
"\n",
2021-11-30 18:03:17 +01:00
"for phase in offsets:\n",
2021-11-30 17:14:50 +01:00
" 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",
2021-11-30 18:03:17 +01:00
" axes[1].plot(freqs, np.angle(ft_signal), '.-', label='$\\\\varphi = {}\\\\pi$'.format(phase/np.pi))\n",
2021-11-30 17:14:50 +01:00
"if with_spectrum:\n",
" axes[0].legend(loc='center right');\n",
"axes[1].legend(loc='center right');\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 18:03:17 +01:00
"execution_count": 8,
2021-11-23 15:22:20 +01:00
"metadata": {},
"outputs": [
{
"data": {
2021-11-30 18:03:17 +01:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7sAAAEjCAYAAADzMBbxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOzdeXycZb3//9dnsjRJ27RpSze6QwuUsrZAEVQQWQVREWhBEAU5nqMifvV40O9ROXj86c+jop7DQVpAUCuLbBZEWQRUoIE2rC0FWtKkTVu6JOmapFnm8/3jviedJPdM0jYzk6bv5+ORRzLzuZfruu97Mvfnvq77us3dEREREREREelPYrkugIiIiIiIiEhvU7IrIiIiIiIi/Y6SXREREREREel3lOyKiIiIiIhIv6NkV0RERERERPodJbsiIiIiIiLS7yjZFRERERERkX5Hya6IiIiIiIj0O0p2RUQkp8zsMDN71cy2m9l1WVzvMjM7LVvrExERkexSsisiIpjZqWb2opltNbM6M3vBzE4IY1Vm9tEMrv6bwHP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KdkX6IHdf7u5Xufs4YAYwFvh5p8nGAmuS5nGC54omez8p3hD+OQggvIJdHg7GsYUgeR7RuzURERHp27r5zl3b6ZnT1WF8IsEzrNeHz+7eQtCSOjKcbjzw3h4WZU33k3SwIenvRmBzeHE78RrC73yRA5WSXZE+zt3fBu4i+AJOth4Yl3gRdk8eRw+Y2QDgQeAnwCh3Hwo8DljaGUVERPqxiO/cg5Nu/4Hgftt1BInpLmCEuw8Nf0rd/chwujXAIalW04P3dwIliRfhvcA
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/7WczdEREREREREcklkUxXQERERERERGS0KdgVERERERGRnKNgV0RERERERHKOgl0RERERERHJOQp2RUREREREJOco2BUREREREZGco2BXREREREREco6CXREREREREck5CnZFRCQrmdlRZvacme03s8+O4X7XmdlZY7U/ERERSQ8FuyIiMiAzO9PM/mJme82swcyeNLM3hcs2m9nb07j7LwKPunuxu/84XTvpfRzufpy7P5qmfW0zs5PS8dgp+3jUzFrNrCn825DO/YX7LDOzu82s2cxqzOyyXsuPMbOHw9fRRjO7ON11EhERUbArIiL9MrPJwG+B/wLKgFnAv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sKLBxoN8O4vxmYmCiEfYGnHsyxiIiCXZGsY2ZHm9nnzawyLM8GLgVW9Vr1fuB4M3uvmcWATwFHDHM3+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": "iVBORw0KGgoAAAANSU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eCawFvgFc0XrbZeb1dcDvA68XkfJZlTuB5wLzFKv4/rGIXLjcF+Ph4eHh4XEcY9Lf3MsoVvBeB/wW8E7zCCuA/w2kFCvIPxV4JlAWnH8UeBXwUxR/Z38AeERVf5Jitfnnqeqcqv6+daxrge+lfvTYJDwPeBOwGrgVeD/F3P5U4Lcpnl/t4fFdDU92PTyOM6jqXuAqiudM/jnwkIjcLCIbWm99DvA1VX2nsTu9huIRHjbuVtU/N4/U+N/AJmCDOc67VfVOLfBRisdyXH30rszDw8PDw+P4whL+5u4EXq2qiaq+jaKA/P0m/mzgl1T1gKruBP4YeKHZ7qXA76vq583f2TtU9e4Jp/Mqs6+l9vV/XFXfb+YAbwfWA7+nqgnF87S3isiqJe7Lw+OkhCe7Hh7HIVT166r6YlU9DTgP2Ay8uvW2zRTPWC23UYrnktp40IofND/OAZgK9mfMYhy7KcjzuuW9Eg8PDw8Pj+MbE/7mbtfmczrvNvEtQAw8YJ5DvZtCST3FvO904M7DPJV7J7+lgR3Wz4eAh01xu/wdzN98D4/vVniy6+FxnENVbwfeSPEH2MYDwGnlL8aefBpLgIgMgb8D/gDYoKqrgPcAMnZDDw8PDw+PkxiOv7mnWu0/UPTb3k9BTBeBdaq6yvybV9UnmffdC5zVd5glvH4AmCl/Mb3A6w/nWjw8PDzZ9fA47iAiTxSRXxWR08zvpwMvAj7Teuu7gSeLyA+JSAT8ArBxiYcZAEPgISA1C1f5hSw8PDw8PL6rsIS/uacALxeR2PThfi/wHlV9gKL95w9FZF5EAhE5S0SuNdv9BfBrInKRFDhbRLaY2A7gzAmn9k1gSkS+X0R
"text/plain": [
"<Figure size 1152x288 with 3 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7sAAAEjCAYAAADzMBbxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpY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YAQz65/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": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7sAAAEjCAYAAADzMBbxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOy9ebxlV1Xv+x2r2fu01SdVlUpTCQnSBAIJpKNJaBOQTgUFFAwPn3qvXq7vij7x+p48n169XFsULhfEa4OCq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bX+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
]
},
2021-11-30 18:03:17 +01:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### FTs: delta peak: group velocity"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the above plots, the phases follow"
]
},
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",
2021-11-30 18:03:17 +01:00
"execution_count": 41,
2021-11-23 15:22:20 +01:00
"metadata": {},
2021-11-30 18:03:17 +01:00
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA7gAAAEWCAYAAABMsDvsAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOzdeXxcdb3/8ddnkkyWSZrOdKfpCm2gUKC1bFqgelGKQhEQBDdAELz+FK7rBVyo2xVQLoiCCsoVEVlUQJBVkCJgoZS9Ky0tbdOWbknT7Nt8fn+cSQlplkk7yWSS9/PxmEfmnPOdcz6TPB49/ZzPdzF3R0RERERERCTThdIdgIiIiIiIiEgqKMEVERERERGRAUEJroiIiIiIiAwISnBFRERERERkQFCCKyIiIiIiIgOCElwREREREREZEJTgioiIiEi/YGafNrPH++A6c8ysrLevk7jW783sR31xrXQwswVmdmG64xBppQRXpB8xs9lm9m8zqzSzcjN7zsyO6MXrvW1mJ/TW+UVERNrr6l7n7ne4+0fSHWNfMbPzzOzZdMfRW8xsvpk1mVl1m9e3EscWmFl9u2PHt9t2M6tps31sur+T9H/Z6Q5ARAJmNgT4O/CfwD1AGDgWaEhjTNnu3pyu64uIyMDSH+91g42ZGWDuHu+jS97t7p/p5NiX3f237fYVtr4xMwcOc/fVvRadDDiq4Ir0H1MB3P1Od29x9zp3f9zdX0884X3OzH6ReOK9wsz+o/WDZlZsZr8zs81mttHMfmRmWW2Of8HMlptZlZktM7OZZnY7MB54sPWJqplNTDwtvcDM1gP/7Kgb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Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"t_0 = t[n_samples//4]\n",
"signal_step = np.heaviside(t - t_0, 1)\n",
"\n",
"signal_fft = ft.rfft(signal_step) / sample_rate\n",
"signal_ifft = ft.irfft(signal_fft, len(signal_fft))\n",
"ft_freqs = ft.rfftfreq(n_samples, 1/sample_rate)\n",
"\n",
"\n",
"alpha = 0.8\n",
"fig, (ax1, ax2) = plt.subplots(1,2, figsize=(16,4))\n",
"ax1.set_title(\"Spectrum\")\n",
"ax1.set_xlabel(\"f (Hz)\")\n",
"ax1.set_ylabel(\"Amplitude\")\n",
"ax1.set_xlim(-1,20)\n",
"ax1.plot(ft_freqs, np.real(signal_fft), '.-', label='Real', alpha=alpha)\n",
"ax1.plot(ft_freqs, np.imag(signal_fft), '.-', label='Imag', alpha=alpha)\n",
"ax1.plot(ft_freqs, np.abs(signal_fft), '.-', label='Abs', alpha=alpha)\n",
"ax1.legend()\n",
"\n",
"# Signal and Inversed FFT\n",
"ax2.set_title(\"Signal and Inversed FFT\")\n",
"ax2.set_xlabel(\"t (s)\")\n",
"ax2.set_ylabel(\"A(t)\")\n",
"ax2.plot(np.arange(len(signal_step)) / sample_rate, signal_step, label=\"Original\")\n",
"ax2.plot(np.arange(len(signal_ifft)) / sample_rate, np.abs(signal_ifft) - 2, label=\"Inversed FFT (offset -2)\")\n",
"ax2.legend()\n",
"\n",
"plt.show();\n"
]
2021-11-23 15:22:20 +01:00
},
{
"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 18:03:17 +01:00
"execution_count": 11,
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 18:03:17 +01:00
"execution_count": 12,
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 18:03:17 +01:00
"execution_count": 13,
2021-11-25 18:49:42 +01:00
"metadata": {},
"outputs": [
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ktEM4ov1f9DRA8S0eeKtHFE9AgR/YCIVhDRHCI6wyn7GSJ6gYjWENFsIvq/W99Ug8FgMBg6hqq/t48S0X8Xf2OnE9G7yoJE9DoiuoqIFhHRAiL6DhENd9L/xvkbO42I3kxE1yI/fu2OYmO1rxHRIUTERPRZIpoH4P7YciOXKSaibxPRTUT0q0L+c0R0JBF9nYiWENF8IrLZYYZtEhb4GgzbFl4E0EtEvyCiM4hoVCwTEe2F/PiUrwPYE8AMAP9HZHtrcX8vABcDuIqodf7pEuTnje4G4DMALiGiN29pYwwGg8FgGKCo+nv7VgCzkf8N/RaAW4hojyLtF8iPVns9gBMBvBdA+eH5LwB8G8C5yP/GngWgm5k/hXxX+A8Wx4xd7NR1GoA3AHhfTd0/iHwH+VEAngJwL/KY4EAAFwH4WU05BsOgggW+BsM2hGJjnFORn/d5BYClRHQ7Ee0rsr4fwPPMfEsxLerHABaLPHOZ+YriKJZfANgfwL5FPb8rjgZhZn4QwO+RT/EyGAwGg2GbR42/t0sA/IiZNzPzDcg/JJ9ZpJ8B4B+YeS0zLwFwCYCzi3KfA3AxMz9R/I2dycxzK9T5diFrfU31H2bme4u//zcB2BvA95h5M4DrARxCRLvXlGUwDBpY4GswbGNg5heYeRwzjwZwHIADAPxIZDsAwHynDCM/W9TFYid9XfFzFwAovm5PLDbzWIk8kN5ry1piMBgMBsPARcXf2wXsnxk6t0gfA2AEgEXFmdsrkTOs+xT5DgIwq6Eq86uzeHjF+b0ewLLiI3d5DdjeA4ZtEBb4GgzbMJh5OoBrkP9BdrEIwOjyopjCPBo1QEQ7APgNgB8A2JeZdwdwFwBKFjQYDAaDYRtF5O/tgc7
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": [
2021-11-30 18:03:17 +01:00
"dft_sample_rate = 1/1e-3 # s\n",
"dft_n_samples = 2**10\n",
"dft_t = np.arange(dft_n_samples) / dft_sample_rate\n",
"\n",
2021-11-25 18:49:42 +01:00
"f = 1e2 # Hz\n",
2021-11-30 18:03:17 +01:00
"if f > dft_sample_rate/2:\n",
2021-11-25 18:49:42 +01:00
" print(\"Sampling a frequency above the sample_rate/2 gives problems\")\n",
2021-11-23 15:22:20 +01:00
"\n",
2021-11-30 18:03:17 +01:00
"signal_sine = np.sin( 2*np.pi*f*dft_t )\n",
2021-11-23 15:22:20 +01:00
"\n",
2021-11-30 18:03:17 +01:00
"fig, axes = plot_signal_and_spectrum(signal_sine, dft_sample_rate, \"Single frequency at $f = {:g}$MHz\".format(f/10**6), ft_kwargs={'fft': cooley_tukey_DFT})\n",
"axes.flat[1].axvline(dft_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
}