m-thesis-introduction/simulations/08_beacon_sync.ipynb

856 lines
231 KiB
Text
Raw Normal View History

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Beacon Sync\n",
"\n",
"Synchronise two delta peaks, by using an intermediate beacon that was sent out together with it."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import scipy.signal as signal\n",
"import scipy.fft as ft"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Monkey patch correlation_lags\n",
"if not hasattr(signal, 'correlation_lags'):\n",
" def correlation_lags(in1_len, in2_len, mode='full'):\n",
" r\"\"\"\n",
" Calculates the lag / displacement indices array for 1D cross-correlation.\n",
" Parameters\n",
" ----------\n",
" in1_size : int\n",
" First input size.\n",
" in2_size : int\n",
" Second input size.\n",
" mode : str {'full', 'valid', 'same'}, optional\n",
" A string indicating the size of the output.\n",
" See the documentation `correlate` for more information.\n",
" See Also\n",
" --------\n",
" correlate : Compute the N-dimensional cross-correlation.\n",
" Returns\n",
" -------\n",
" lags : array\n",
" Returns an array containing cross-correlation lag/displacement indices.\n",
" Indices can be indexed with the np.argmax of the correlation to return\n",
" the lag/displacement.\n",
" Notes\n",
" -----\n",
" Cross-correlation for continuous functions :math:`f` and :math:`g` is\n",
" defined as:\n",
" .. math::\n",
" \\left ( f\\star g \\right )\\left ( \\tau \\right )\n",
" \\triangleq \\int_{t_0}^{t_0 +T}\n",
" \\overline{f\\left ( t \\right )}g\\left ( t+\\tau \\right )dt\n",
" Where :math:`\\tau` is defined as the displacement, also known as the lag.\n",
" Cross correlation for discrete functions :math:`f` and :math:`g` is\n",
" defined as:\n",
" .. math::\n",
" \\left ( f\\star g \\right )\\left [ n \\right ]\n",
" \\triangleq \\sum_{-\\infty}^{\\infty}\n",
" \\overline{f\\left [ m \\right ]}g\\left [ m+n \\right ]\n",
" Where :math:`n` is the lag.\n",
" Examples\n",
" --------\n",
" Cross-correlation of a signal with its time-delayed self.\n",
" >>> from scipy import signal\n",
" >>> from numpy.random import default_rng\n",
" >>> rng = default_rng()\n",
" >>> x = rng.standard_normal(1000)\n",
" >>> y = np.concatenate([rng.standard_normal(100), x])\n",
" >>> correlation = signal.correlate(x, y, mode=\"full\")\n",
" >>> lags = signal.correlation_lags(x.size, y.size, mode=\"full\")\n",
" >>> lag = lags[np.argmax(correlation)]\n",
" \"\"\"\n",
"\n",
" # calculate lag ranges in different modes of operation\n",
" if mode == \"full\":\n",
" # the output is the full discrete linear convolution\n",
" # of the inputs. (Default)\n",
" lags = np.arange(-in2_len + 1, in1_len)\n",
" elif mode == \"same\":\n",
" # the output is the same size as `in1`, centered\n",
" # with respect to the 'full' output.\n",
" # calculate the full output\n",
" lags = np.arange(-in2_len + 1, in1_len)\n",
" # determine the midpoint in the full output\n",
" mid = lags.size // 2\n",
" # determine lag_bound to be used with respect\n",
" # to the midpoint\n",
" lag_bound = in1_len // 2\n",
" # calculate lag ranges for even and odd scenarios\n",
" if in1_len % 2 == 0:\n",
" lags = lags[(mid-lag_bound):(mid+lag_bound)]\n",
" else:\n",
" lags = lags[(mid-lag_bound):(mid+lag_bound)+1]\n",
" elif mode == \"valid\":\n",
" # the output consists only of those elements that do not\n",
" # rely on the zero-padding. In 'valid' mode, either `in1` or `in2`\n",
" # must be at least as large as the other in every dimension.\n",
"\n",
" # the lag_bound will be either negative or positive\n",
" # this let's us infer how to present the lag range\n",
" lag_bound = in1_len - in2_len\n",
" if lag_bound >= 0:\n",
" lags = np.arange(lag_bound + 1)\n",
" else:\n",
" lags = np.arange(lag_bound, 1)\n",
" return lags\n",
"\n",
" signal.correlation_lags = correlation_lags"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"### signal generation\n",
"def fft_bandpass(signal, band, samplerate):\n",
" \"\"\"\n",
" Simple bandpassing function employing a FFT.\n",
"\n",
" Parameters\n",
" ----------\n",
" signal : arraylike\n",
" band : tuple(low, high)\n",
" Frequencies for bandpassing\n",
" samplerate : float\n",
" \"\"\"\n",
" signal = np.asarray(signal)\n",
"\n",
" fft = ft.rfft(signal)\n",
" freqs = ft.rfftfreq(signal.size, 1/samplerate)\n",
" fft[(freqs < band[0]) | (freqs > band[1])] = 0\n",
" \n",
" return ft.irfft(fft, signal.size), (fft, freqs)\n",
"\n",
"def deltapeak(timelength=1e3, samplerate=1, offset=None, peaklength=1):\n",
" N_samples = int(timelength * samplerate)\n",
" if offset is None:\n",
" offset = (np.random.random(1)*N_samples).astype(int) % N_samples\n",
" elif isinstance(offset, (tuple, list)):\n",
" offset_min = offset[0]\n",
" offset_max = offset[-1]\n",
" \n",
" offset = (np.random.random(1)*(offset_max - offset_min)+offset_min).astype(int) % N_samples\n",
" \n",
" position = (offset + np.arange(0, peaklength)).astype(int) % N_samples\n",
" \n",
" signal = np.zeros(N_samples)\n",
" signal[position] = 1\n",
" \n",
" return signal, position\n",
"\n",
"def sin_delay(f, t, t_delay=0, phase=0):\n",
" return np.sin(2*np.pi*f * (t + t_delay) + phase)\n",
2022-08-01 15:17:24 +02:00
"\n",
"def annotate_width(ax, name, x1, x2, y, text_kw={}, arrow_kw={}):\n",
" default_arrow_kw = dict(\n",
" xy = (x1, y),\n",
" xytext = (x2,y),\n",
" arrowprops = dict(\n",
" arrowstyle=\"<->\",\n",
" shrinkA=False,\n",
" shrinkB=False\n",
" ),\n",
" )\n",
"\n",
" default_text_kw = dict(\n",
" va='bottom',\n",
" ha='center',\n",
" xy=((x1+x2)/2, y)\n",
" )\n",
"\n",
" an1 = ax.annotate(\"\", **{**default_arrow_kw, **arrow_kw})\n",
" an2 = ax.annotate(name, **{**default_text_kw, **text_kw})\n",
"\n",
" return [an1, an2]\n",
"\n",
"def time2phase(time, frequency=1):\n",
" return 2*np.pi*frequency*time\n",
"\n",
"def phase2time(phase, frequency=1):\n",
" return phase/(2*np.pi*frequency)\n",
"\n",
"def time_roll(a, samplerate, time_shift, *roll_args, **roll_kwargs):\n",
" \"\"\"\n",
" Like np.roll, but use samplerate and time_shift to approximate\n",
" the offset to roll.\n",
" \"\"\"\n",
" shift = np.rint(time_shift*samplerate).astype(int)\n",
" return np.roll(a, shift, *roll_args, **roll_kwargs)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2022-08-01 15:17:24 +02:00
"Beacon period [ns]: 14.285714285714285\n",
"Beacon initial [ns]: 4.4\n",
"Beacon initial [phase]: 1.9352210746113125\n",
"Beacon initial [idx]: 22.0\n",
"Beacon difference [ns]: 8.571428571428571\n",
"Beacon difference [phase]: 3.7699111843077517\n",
"Impulse offsets [ns]: [ 75.4 149.6]\n",
"Time difference Impulses [ns]: 74.20000000000002\n"
]
}
],
"source": [
"us = 1e3 # ns\n",
"ns = 1/us # us\n",
"\n",
"\n",
"band = (30, 80) # MHz\n",
"samplerate = 5000 # MHz\n",
"timelength = 0.2 # us\n",
"\n",
"time = np.arange(0, timelength, 1/samplerate)\n",
"\n",
"# generate beacons\n",
"if True: # in-band\n",
" f_beacon = 70 # MHz\n",
"else: # under band\n",
" f_beacon = 20 # MHz\n",
"\n",
"beacon_amplitude = 0.1\n",
"beacon_init_phase = time2phase(4.4*ns, f_beacon)\n",
"beacon_phase_offset = 1.2*np.pi\n",
"\n",
"beacons = np.array([\n",
" beacon_amplitude * sin_delay(f_beacon, time, t_delay=0, phase=-beacon_init_phase),\n",
" beacon_amplitude * sin_delay(f_beacon, time, t_delay=0, phase=-beacon_init_phase-beacon_phase_offset)\n",
"])\n",
"\n",
2022-08-01 15:17:24 +02:00
"\n",
"# generate impulses\n",
"impulses = []\n",
"impulses_offsets = []\n",
2022-08-01 15:17:24 +02:00
"impulses_def_offsets = [\n",
" (0.3*len(time),0.4*len(time)),\n",
2022-08-01 15:17:24 +02:00
" (0.7*len(time),0.8*len(time)),\n",
" ]# random offsets in interval\n",
"for i in range(2):\n",
" offset = None\n",
" if impulses_def_offsets:\n",
" if len(impulses_def_offsets) == 1:\n",
" offset = impulses_def_offsets[0]\n",
" else:\n",
" offset = impulses_def_offsets[i]\n",
" orig_imp, imp_offset = deltapeak(timelength, samplerate, offset=offset, peaklength=1)\n",
"\n",
" ## Bandpass it\n",
" imp, _ = fft_bandpass(orig_imp, band, samplerate)\n",
" imp /= np.max(imp)\n",
" \n",
" impulses.append(imp)\n",
" impulses_offsets.append(imp_offset/samplerate)\n",
"\n",
"impulses = np.array(impulses)\n",
"impulses_offsets = np.array(impulses_offsets)\n",
2022-08-01 15:17:24 +02:00
"print(\"Beacon period [ns]:\", 1/f_beacon/ns)\n",
"print(\"Beacon initial [ns]:\", phase2time(beacon_init_phase, f_beacon) /ns)\n",
"print(\"Beacon initial [phase]:\", beacon_init_phase)\n",
"print(\"Beacon initial [idx]:\", phase2time(beacon_init_phase, f_beacon)*samplerate)\n",
"print(\"Beacon difference [ns]:\", phase2time(beacon_phase_offset, f_beacon)/ns)\n",
"print(\"Beacon difference [phase]:\", beacon_phase_offset)\n",
"print(\"Impulse offsets [ns]:\", impulses_offsets[:,0]/ns)\n",
2022-08-01 15:17:24 +02:00
"print(\"Time difference Impulses [ns]: {}\".format( (impulses_offsets[1,0]-impulses_offsets[0,0])/ns ))"
]
},
{
"cell_type": "code",
2022-08-01 15:17:24 +02:00
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"full_signals = impulses + beacons"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAroAAAEHCAYAAABBQeUvAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOydd3xb1dmAnyt57z0SJ3Ycx3H2MtmLDEYYoS0U2kIKZbQQCoUOK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eXciFRUVNDc3M2zYMHereAyO7pQlcR6VlZXU19eTlJTkbpVObMopJyLQh4n9XDFh6dhY/vlNHltyy/nxVMfG+EokEolE0hO9TkYTQvxICFEjhHgQ+AvwGnCZq8UGiu3bZ7B9u2lCVHl5OXfffTejR49m/fr1bjazTW5ubrexr56KllzBc30zMjIsG3jk5+cD7nc1GgVbcsuZPyoKna73zR568h0bH0JUkA+bc8udrdkn3B1bR9GSr5ZcQVu+WnIFbflqyRW05+tqVC0vpiiKHogFzM+a44ACV0kNNDU17Vx++eV89dVXzJ07l8cff5zo6Gg+//xzd6t1o7i4GICcnBw3m/SOllzBs32fe+45Pv/8c6ZOncr06dO5/fbbGT3afSOIMoprqWxsY+Ho/g1bANDpFOaNimZzbjlGo1CVOEskEolEogY1qy78FngAOAUYT78sgIl2T9IYOTlNrF27loCAABoaGlizZo27lezS2Ghahsld2706gpZcwfN9m5q
"text/plain": [
"<Figure size 864x288 with 3 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Make a figure showing two signals with a beacon per signal\n",
"colors = ['y','g']\n",
"multiplier_name = ['m','n']\n",
"\n",
"\n",
"fig, axes = plt.subplots(3,1, sharex=True, figsize=(12,4))\n",
"axes[-1].set_xlabel(\"Time [ns]\")\n",
2022-08-01 15:17:24 +02:00
"axes[-1].set_yticks([],[])\n",
"for i in range(0, 2):\n",
2022-08-01 15:17:24 +02:00
" axes[i].set_yticks([],[])\n",
" axes[i].set_ylabel(\"Antenna {:d}\".format(i+1))\n",
" axes[i].plot(time/ns, impulses[i])\n",
" axes[i].plot(time/ns, beacons[i], marker='.')\n",
2022-08-01 15:17:24 +02:00
" if not True:\n",
" axes[i].plot(time/ns, full_signals[i])\n",
"\n",
"\n",
"# indicate timing of pulses\n",
"for i, impulse_offset in enumerate(impulses_offsets):\n",
" kwargs = dict(color=colors[i])\n",
" [ax.axvline(impulse_offset/ns, **kwargs) for ax in (axes[i], axes[-1])]\n",
"\n",
2022-08-01 15:17:24 +02:00
"\n",
"# indicate timing of the beacons\n",
2022-08-01 15:17:24 +02:00
"# and annotate ticks and impulse widths\n",
"tmp_beacon_phases = beacon_init_phase + np.arange(0,2)*beacon_phase_offset\n",
"if not True: # mod phases\n",
" tmp_beacon_phases %= 2*np.pi\n",
"tmp_beacon_offsets = phase2time(tmp_beacon_phases, f_beacon)\n",
"\n",
"\n",
"A = np.empty(2)\n",
"B = np.empty(2)\n",
"for i in range(0,2):\n",
" kwargs = dict(color=colors[i], ls=(0, (3,2)))\n",
" tick_kwargs = dict(color='k', alpha=0.2)\n",
"\n",
" # indicate every period of the beacon\n",
" beacon_ticks = tmp_beacon_offsets[i] + [(n)*1/f_beacon for n in range(1+int((time[-1] - time[0]) * f_beacon))]\n",
"\n",
" [axes[i].axvline(tick/ns, **{**kwargs, **tick_kwargs}) for tick in beacon_ticks]\n",
"\n",
" # reference period in beacon\n",
2022-08-01 15:17:24 +02:00
" [ax.axvline(tmp_beacon_offsets[i]/ns, **kwargs) for ax in (axes[i], axes[-1])]\n",
"\n",
" # annotate width between impulse and closest beacon tick\n",
" # and closest beacon tick and reference tick\n",
" closest_beacon_tick_id = np.argmin(np.abs(beacon_ticks-impulses_offsets[i]))\n",
" if closest_beacon_tick_id != 0 and beacon_ticks[closest_beacon_tick_id] > impulses_offsets[i]:\n",
" closest_beacon_tick_id -= 1\n",
" closest_beacon_tick = beacon_ticks[closest_beacon_tick_id]\n",
"\n",
" annotate_width(axes[i], f\"$A_{i+1}$\", closest_beacon_tick/ns, impulses_offsets[i]/ns, 0.7)\n",
" annotate_width(axes[i], f\"$B_{i+1}={multiplier_name[i]}T$\", closest_beacon_tick/ns, tmp_beacon_offsets[i]/ns, 0.4)\n",
"\n",
" A[i] = closest_beacon_tick - impulses_offsets[i]\n",
" B[i] = closest_beacon_tick - tmp_beacon_offsets[i]\n",
2022-08-01 15:17:24 +02:00
"\n",
"# annotate width between beacon reference periods\n",
"annotate_width(axes[-1], \"$t_\\phi$\", tmp_beacon_offsets[0]/ns, tmp_beacon_offsets[-1]/ns, 0.4)\n",
"\n",
"# annotate width between pulses\n",
"annotate_width(axes[-1], \"$\\Delta t$\", impulses_offsets[0]/ns, impulses_offsets[-1]/ns, 0.4)\n",
"\n",
"\n",
"fig.show()\n",
"if False:\n",
" fig.savefig('figures/08_beacon_sync_timing_outline.pdf')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\\Delta t = 74.20000000000002ns\n",
"\\Delta A = 5.7999999999999785ns\n",
"t_phi = 8.571428571428573ns\n",
"B_1 = 57.14285714285714ns = 4.0T\n",
"B_2 = 128.57142857142856ns = 9.0T\n",
"kT = 71.42857142857142ns = 5.0T\n"
]
}
],
"source": [
"t_phi = (tmp_beacon_offsets[1]-tmp_beacon_offsets[0])\n",
"Delta_A = (A[1] - A[0])\n",
"\n",
"print(\"\\Delta t = {}ns\".format( (impulses_offsets[1][0] - impulses_offsets[0][0])/ns ))\n",
"print(\"\\Delta A = {}ns\".format( Delta_A/ns ))\n",
"print(\"t_phi = {}ns\".format( t_phi/ns ))\n",
"print(\"B_1 = {}ns = {}T\".format( (B[0])/ns, (B[0]*f_beacon) ))\n",
"print(\"B_2 = {}ns = {}T\".format( (B[1])/ns, (B[1]*f_beacon) ))\n",
"print(\"kT = {}ns = {}T\".format( (B[1]-B[0])/ns, (B[1]-B[0])*f_beacon ))\n",
"\n"
2022-08-01 15:17:24 +02:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$\n",
2022-08-01 15:17:24 +02:00
"\\Delta t = (A_2 + B_2) - (A_1 + B_1) + t_\\phi\\\\\n",
"\\quad = (A_2 - A_1) + (B_2 - B_1) + t_\\phi\\\\\n",
"\\quad = (A_2 - A_1) + (nT - mT) + t_\\phi\\\\\n",
"\\quad = \\Delta A + (kT) + t_\\phi\n",
"$\n",
"\n",
", where $\\Delta A < T$ and $k \\in \\mathbb{Z}$ and $t_\\phi$ is minimisable.\n",
"\n",
"Then $\\Delta t$ can be determined by iteratively summing the signals, changing $k$, and finding the $k$ belonging to the maximum of the sums."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"def find_best_integer_periods_sum(samplerate, f_beacon, ref_impulse, impulse, k_step=1):\n",
" max_k = int( len(ref_impulse)*f_beacon/samplerate )\n",
" ks = np.arange(-max_k/2, max_k/2, step=k_step)\n",
" \n",
" maxima = np.empty(len(ks))\n",
" \n",
" best_i = 0\n",
" \n",
" for i,k in enumerate(ks, 0):\n",
" augmented_impulse = time_roll(impulse, samplerate, k/f_beacon)\n",
" \n",
" maxima[i] = max(ref_impulse + augmented_impulse)\n",
" \n",
" if maxima[i] > maxima[best_i]:\n",
" best_i = i\n",
" \n",
" return ks[best_i], (ks, maxima)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Best k: -5\n",
"Maximum: 2.0\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAtkAAAEYCAYAAACJEeoSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOzde5Qc93XY+e+tV7/njTdAggRpUQIkAhFkWcfWw5F1aEkrQ1jtOaRoKY59Eq031m6ieFfyOjqWuHHWkTcnyjpaR9EyoSVlIzkRbTDiOhspR4QoMREpSoZJUNSQIAiQAw6AwTz73V1Vv/2juoaDwTy6e6a7BuD9nDMH6Omq7l9X93TfvnV/9yfGGJRSSimllFKbx0p6AEoppZRSSt1oNMhWSimllFJqk2mQrZRSSiml1CbTIFsppZRSSqlNpkG2UkoppZRSm0yDbKWUUkoppTaZBtlKKaWUUkptMg2ylVJKKaWU2mQaZCuluiYirxORvxS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ni/fzHmd+hFFxKekhKKaV64OXz5/nFtx3d0G382b/7Or/0C29d/NkznOP0U3+14bElPvFRRPLAg8DfM8YsLL96hV3MNb8w5kvAlwCOHj1qPvXLd2z6OJVS149/85N/w/zlC/zOz/4Of/TjP6JR+As+9Y7PJT0spZS6oTz77LPsGswkOob6QBrHkg2N47f+9q/zW3/71wF4+umnOXbsGO95+89ds91cxmV5jPk7a9xuoplsEXGJAuz/xxjzZytsMgHsW3J5L/BKP8amlLo+GWP4xnPf4E1jb+JXX/+rHLvtGN8+/23
"text/plain": [
"<Figure size 864x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Make figure showing the sums depending on k\n",
"ref_impulse = impulses[0]\n",
"my_impulse = impulses[1]\n",
"\n",
"# remove 'already determined' offsets\n",
"if True:\n",
" # $t_\\phi$ offset\n",
" my_impulse = time_roll(my_impulse, samplerate, -t_phi)\n",
"\n",
" # $\\Delta A$ offset\n",
" my_impulse = time_roll(my_impulse, samplerate, Delta_A)\n",
"\n",
"best_k, (ks, maxima) = find_best_integer_periods_sum(samplerate, f_beacon, ref_impulse, my_impulse)\n",
"print(\"Best k: {:0g}\".format(best_k))\n",
"print(\"Maximum: {}\".format(maxima[np.where(ks == best_k)][0]))\n",
"\n",
"\n",
"# Make figure\n",
"fig, axes = plt.subplots(1, 1, sharex=True,figsize=(12,4))\n",
"if not hasattr(axes, 'ndim'):\n",
" axes = [axes]\n",
"\n",
"axes[0].set_title(\"Sum of impulses with $kT$ offsets. Best offset: ${:.0f}*T$\".format(best_k))\n",
"axes[-1].set_xlabel(\"Time [ns]\")\n",
"\n",
"if not True:\n",
" i=0\n",
" axes[i].set_ylabel(\"Reference\")\n",
" axes[i].plot(time/ns, ref_impulse, label=\"reference\")\n",
" axes[i].plot(time/ns, my_impulse, label='impulse')\n",
" axes[i].legend()\n",
"\n",
"axes[-1].set_ylabel(\"Sum\")\n",
"\n",
"best_maximum = np.max(maxima)\n",
"axes[-1].axhline(best_maximum, alpha=0.7)\n",
"\n",
"for i, k in enumerate(ks, 0):\n",
" sample_offset = int(k*1/f_beacon*samplerate)\n",
" augmented_impulses = np.roll(my_impulse, sample_offset)\n",
" \n",
" summed_impulse = ref_impulse + augmented_impulses\n",
" if True or k%2 == 1:\n",
" axes[-1].plot(time/ns, summed_impulse, label='k={:.0f}'.format(k),\n",
" alpha=0.1 + 0.9*1/(1+4*abs(best_maximum-maxima[i]))\n",
" )\n",
" \n",
"axes[-1].legend()\n",
"fig.show()\n",
"\n",
"del ref_impulse\n",
"del my_impulse"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Solve it"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAEWCAYAAABIVsEJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO3dd3iUZdbH8e9JT+iQECAQQiD0TgTBAggoqIBtVWxgw+7q6u7q6qrru7rqKrZ1VexrR9eCKyJFsNKC9JaE0EJLaKEGUs77xzzZHWMaYSbPTHI+1zVXZp76mwTmzP2U+xZVxRhjjDleIW4HMMYYE5ysgBhjjKkWKyDGGGOqxQqIMcaYarECYowxplqsgBhjjKkWKyAmqInI5SIyw0fbmisi11VjvSQRUREJ80WOYHcifxMReUhE3vF1JuMfVkCMq5wP7b0iElmd9VX1XVU909e5TPXZ36TusAJiXCMiScBpgAJjXA1jfMJaYXWLFRDjpquA+cCbwPiKFhSRCSKSJSIHRGSDiFzuNf0Hr+VURG4UkQynZfOCiIgzL1REnhKRXc42bq3o0JOIXCMia5ztfC0ibSt5P9eIyDYR2S4id3ltJ0RE7hGR9SKyW0SmiEhTr/kficgOEckTke9EpJvXvGg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MJCQrh08nxWOF2qGGNqnhWQOiT3wFGufG0heYcLeO/6kzmlQ6zbkaqlfVx9ptwwkHoRYVz26nx+3rzX7UjG1ElWQOqIvCMFjH99ITvy8nnj6pPo1aax25FOSGKzGKbcOJCm9SKY8PpCMnYecDuSMXWOFZA64MixIq57axEZOQd
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# single out one period of the beacon\n",
"beacon_samplerate = samplerate # MHz\n",
"beacon_time = np.arange(0, 1/f_beacon, 1/beacon_samplerate)\n",
"ref_beacon = sin_delay(f_beacon, beacon_time, phase=0, t_delay=0)\n",
"\n",
"# .. and show beacon period\n",
"fig, ax = plt.subplots()\n",
"ax.set_title(\"A single beacon period\")\n",
"ax.set_xlabel(\"Time [ns]\")\n",
"ax.set_ylabel(\"Amplitude\")\n",
"ax.plot(beacon_time/ns,ref_beacon)\n",
"fig.show()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"### correlation\n",
"def correlation_and_lag(sig1, sig2, mode=\"full\", normalise=False):\n",
" corr = signal.correlate(sig1, sig2, mode=mode)\n",
" if normalise:\n",
" corr /= np.max(corr)\n",
"\n",
" lags = signal.correlation_lags(sig1.size, sig2.size, mode=mode)\n",
" \n",
" return corr, lags\n",
"\n",
2022-08-01 15:17:24 +02:00
"def find_best_lag(sig1, sig2, fix_one_short=False, fix_positive=False, subtract_means=True, **corr_kwargs):\n",
" if subtract_means:\n",
" sig1 -= np.mean(sig1)\n",
" sig2 -= np.mean(sig2)\n",
" \n",
" corr, lags = correlation_and_lag(sig1, sig2, **corr_kwargs)\n",
" lag_id = corr.argmax()\n",
"\n",
" lag = lags[lag_id]\n",
" \n",
" if fix_one_short:\n",
" # for some reason it is always one short\n",
" if lag > 0:\n",
" lag += 1\n",
" elif lag < 0:\n",
" lag -= 1\n",
"\n",
" # turn negative lag into positive\n",
" if fix_positive and lag < 0:\n",
" lag += len(sig2)\n",
" \n",
" return lag, (corr, lags)\n",
"\n",
"def find_beacon_phase_delay(samplerate, f_beacon, reference_beacon, delayed_beacon, **lag_kwargs):\n",
" \"\"\"\n",
" Return phase delay of `beacon` with respect to `reference_beacon`.\n",
" Note that the returned value can be off by a multiple of $2\\pi$.\n",
" \n",
" Parameters\n",
" ==========\n",
" samplerate : float\n",
" Samplerate of both reference_beacon and delayed_beacon\n",
" f_beacon : float\n",
" Frequency of the beacons\n",
" reference_beacon : ndarray\n",
" The beacon to use as a reference\n",
" beacon : ndarray\n",
" The beacon to find the delay for\n",
" \"\"\"\n",
" \n",
" calc_lag, _ = find_best_lag(reference_beacon, delayed_beacon, **lag_kwargs)\n",
" \n",
" time = calc_lag / samplerate\n",
" \n",
" return 2*np.pi* f_beacon * time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### 1.1 Beacon Phase Delays"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Beacon delays [ns] \\pm k*14.285714285714285ns: [0. 5.6]\n"
]
}
],
"source": [
"beacon_phase_delays = np.array([\n",
" find_beacon_phase_delay(beacon_samplerate, f_beacon, beacons[0], beacon)\n",
" for beacon in beacons\n",
"])\n",
"\n",
"beacon_time_delays = phase2time(beacon_phase_delays, f_beacon)\n",
"\n",
"print(\"Beacon delays [ns] \\pm k*{}ns: {}\".format(1/f_beacon/ns, beacon_time_delays/ns))"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
2022-08-01 15:17:24 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 0.0\n",
"1 2.463008640414398\n"
2022-08-01 15:17:24 +02:00
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYoAAAEpCAYAAACN9mVQAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxv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isl5ExjgcnygiH4hIjeiMgYt9cD2GAMAoCsNAYzI6Qqujp2gh7qWTXCU60f1rcmZ+41OIzjpYACSLyH4RKRWRR0UkwtVGRKeLPdnd1tdy3VCGDvl+v5P2XcmOeAtaISYA+9HBHju96z9AR/9NsZf7q4gEfBpPg/sYRWEYaESjo+Y6UoueCuoPc9E5Biaic328Jc7zgAxFZy27EZ1lcAowFfhvVxtSSjkmPzpr62u5HvgVcK2Tl/gs9Pf3a6VUm1LqI3RU3VscyrymlPpC6aRZz9uvE3QOkWKl1FNKqQ6l1GbgVfv3YRjkGEVhGGg0ALFd9sWiwzP3GaXUKvtL8yTwfXTyoUlOinbmFnhEKXVU6dwCDxEgGcgcUUpVAo+iczs74k52xExgZpeRza3AMI8KbwhIjKIwDDSK0JnyHDN/5XJmAnt3cJpVTCl1Aii1H+8XIvJTB+uqs7a+luuF36Fzck9z2OdOdsQS4NMuo5topdQ9LspjGMAYRWEYaHyCzlT3PREJE5HOnMQf9bUiEZlsN7UNEpFo4A/ol+aubk55CviuiKSISAI6J/dbrranlPo/B+uqs7a+luulrZP26/mxw253siO+BYwXkdvt54aIyHQRcTb6MgwyjKIwDCiUUm3AQnS+45PAXcBC+/7O3vg7LlY3FJ3Rrw5t5joSuEbZ8xw7qesX6Cxke9HKZAv2xd4A5U84pH+1f0cLgCvR2dX+CtyhlNrdW0V
2022-08-01 15:17:24 +02:00
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Make a figure showing the corrected beacons\n",
"fig, ax = plt.subplots(1,1, sharex=True)\n",
"ax.set_xlabel(\"Time [ns]\")\n",
"ax.set_ylabel(\"Amplitude [au]\")\n",
"ax.set_title(\"Beacon delays [ns] $\\pm$ $k*{}$\\n{} == {}\".format(1/f_beacon/ns, beacon_time_delays/ns, None))\n",
"\n",
"for i, _ in enumerate(beacons):\n",
" l = ax.plot(time/ns, beacons[i], label=\"ch {}\".format(i), ls ='--', alpha=0.5)\n",
" \n",
" print(i, beacon_phase_delays[i], )\n",
"\n",
2022-08-01 15:17:24 +02:00
" if True:\n",
" corrected_beacon = sin_delay(f_beacon, beacon_time, phase=beacon_phase_delays[i], t_delay=0)\n",
" else:\n",
2022-08-01 15:17:24 +02:00
" corrected_beacon = sin_delay(f_beacon, beacon_time, t_delay=beacon_time_delays[i], phase=0)\n",
" \n",
2022-08-01 15:17:24 +02:00
" ax.plot(beacon_time/ns, 2*beacon_amplitude*corrected_beacon, label='ch {} corrected'.format(i), color=l[0].get_color())\n",
" \n",
" # indicate start of uncorrected beacons\n",
" ax.axvline(phase2time((2*np.pi+beacon_time_delays[i])%2*np.pi, f_beacon)/ns, color=l[0].get_color())\n",
"\n",
"ax.legend(ncol=2)\n",
"ax.margins(y=0.3)\n",
"if True:\n",
" ax.set_xlim(time[0]/ns - 1, time[2*samplerate//f_beacon]/ns)\n",
"\n",
"fig.show()\n",
"\n",
"\n",
"#ax.plot((double_signal_time) * ns, signal_2(double_signal_time + calc_shift), 'r--', label='Recovered')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### 1.2 Impulse vs beacon delays\n",
"\n",
"Find the delay within a single beacon period"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"#def find_beacon_impulse_delay(samplerate, f_beacon, impulse, init_phase=0):\n",
"def find_beacon_impulse_phase_delay(samplerate, f_beacon, reference_beacon, impulse, **lag_kwargs):\n",
" \"\"\"\n",
" Return phase delay of `beacon` with respect to `reference_beacon`.\n",
" Note that the returned value can be off by a multiple of $2\\pi$.\n",
" \n",
" Parameters\n",
" ==========\n",
" samplerate : float\n",
" Samplerate of both reference_beacon and delayed_beacon\n",
" f_beacon : float\n",
" Frequency of the beacons\n",
" reference_beacon : ndarray\n",
" The beacon to use as a reference\n",
" beacon : ndarray\n",
" The beacon to find the delay for\n",
" \"\"\"\n",
" \n",
" calc_lag, _ = find_best_lag(reference_beacon, impulse, **lag_kwargs)\n",
" \n",
" return 2*np.pi* f_beacon * calc_lag / samplerate"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Beacon Impuls delays: $[-454.90261624 -921.11496603]$ns\n"
]
}
],
"source": [
"impulse_beacon_phase_delays = np.empty( len(impulses) )\n",
"\n",
"for i, _ in enumerate(impulses):\n",
" impulse_beacon_phase_delays[i] = find_beacon_impulse_phase_delay(\n",
" beacon_samplerate, f_beacon, \n",
" ref_beacon, impulses[i]\n",
" )\n",
"\n",
"print(\"Beacon Impuls delays: ${}$ns\".format(impulse_beacon_phase_delays/f_beacon/ns))"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEKCAYAAAAfGVI8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAVt0lEQVR4nO3df6zdd33f8ecLQxItUDDYk5DjEENdkhS1CRwZKqTBBEkc/rCRilqnQyQsnTVGYIOtUhCagsw/FDbRsaUlpvWASsOBVNpuO1CaEhhbh8HHIwuxK8PFUOKZKQaHaF2yZE7e++N8s3t8fa/v19fH9zj383xIRz7fz/fz+Z7P/eje8/L35ydVhSSpXc+bdgckSdNlEEhS4wwCSWqcQSBJjTMIJKlxBoEkNW7JIEiyJ8kjSR5aZH2SfCrJbJIHk7x2bN3NSb7fvW6eZMclSZPRZ4/gs8DWM6y/EdjcvXYCfwCQ5KXAHcDrgS3AHUnWnktnJUmTt2QQVNU3gBNnqLId+HyN7ANekuTlwA3AfVV1oqoeBe7jzIEiSZqC509gGxuAh8eWj3Zli5WfJslORnsTXHrppa+78sorJ9AtSWrHgQMHflpV65fTdhJBkAXK6gzlpxdW7Q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dcnCDYAD48tH+3KTpPkFcAm4P6x4kuSDJPsS/L2Rdrt7OoMjx8/3rPrkqRJ6BMEWaCsFqm7A7inqp4eK7u8qgbAbwG/l+RVp22sandVDapqsH79+h5dkiRNSp8gOApsHFu+DDi2SN0dzDssVFXHun+PAF/n1PMHkqQp6xME+4HNSTYluYjRl/1pV/8keTWwFvjmWNnaJBd379cBbwQOzW8rSZqeJa8aqqq
"text/plain": [
"<Figure size 432x288 with 2 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# Make a figure showing the corrected beacons\n",
"fig, axes = plt.subplots(len(impulses),1, sharex=True)\n",
"axes[-1].set_xlabel(\"Time [us]\")\n",
"ax.set_title(\"Beacon Impuls delays: ${}$ns\".format(impulse_beacon_phase_delays/f_beacon/ns))\n",
"\n",
"for i, beacon in enumerate(beacons):\n",
" ax.set_ylabel(\"Amplitude [au]\")\n",
" ax.plot(time, beacon, label=\"ch {}\".format(i))\n",
"\n",
2022-08-01 15:17:24 +02:00
"ax.plot(beacon_time, corrected_beacon, label='phase corrected (overlaps ch 0)')\n",
"\n",
"ax.legend()\n",
"\n",
"fig.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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
}