mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-12-22 11:33:32 +01:00
441 lines
91 KiB
Text
441 lines
91 KiB
Text
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Phase by Correlation"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"##### Continuous Cross Correlation\n",
|
||
|
"For signals $u(t)$ and $v(t)$ \n",
|
||
|
"and correlation parameter $\\tau$:\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
" Corr(\\tau; u, v)\n",
|
||
|
" =\n",
|
||
|
" \\int_{-\\infty}^\\infty \\mathrm{d}t \\; u(t) \\, v^*(t - \\tau)\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"##### Discrete Cross Correlation\n",
|
||
|
"For signals $u[n]$ and $v[n]$ \n",
|
||
|
"and correlation parameter $k$:\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
" Corr(k; u, v)\n",
|
||
|
" = \\sum_n u[n] \\, v^*[n-k]\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"---\n",
|
||
|
"\n",
|
||
|
"Writing\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
" u(t, \\phi_t) = A_1 \\exp(2i \\pi f t + \\phi_t)\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"Correlation $u \\triangleq u(t_1, \\phi_{t1})$ and $ v \\triangleq u(t_2, \\phi_{t2}) $:\n",
|
||
|
"\n",
|
||
|
"$$\n",
|
||
|
" Corr(\\vec{\\tau}; u_1, u_2)\n",
|
||
|
" =\n",
|
||
|
" \\int_{-\\infty}^\\infty \\mathrm{d}\\vec{\\zeta} \\; u_1(\\vec{\\zeta}) \\, u_2^*(\\vec{\\zeta} - \\vec{\\tau})\n",
|
||
|
"$$\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import numpy as np\n",
|
||
|
"import matplotlib.pyplot as plt\n",
|
||
|
"from scipy import signal\n",
|
||
|
"rng = np.random.default_rng()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"class SineWave:\n",
|
||
|
" \"\"\"\n",
|
||
|
" A periodic sine wave, totally described by its frequencies, phases and amplitudes.\n",
|
||
|
" \"\"\"\n",
|
||
|
" def __init__(self, frequencies, phase = 0, amplitude = 1):\n",
|
||
|
" self.freqs = frequencies\n",
|
||
|
" self.phase = phase\n",
|
||
|
" self.amplitude = amplitude\n",
|
||
|
" \n",
|
||
|
" def __call__(self, time, complx=True):\n",
|
||
|
" if complx:\n",
|
||
|
" return self.amplitude * np.exp( 2j * self.freqs*time + 2j * self.phase)\n",
|
||
|
" else:\n",
|
||
|
" return self.amplitude * np.cos( self.freqs*time + self.phase)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": null,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Initial signal"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"mysignal = SineWave( 5e1, np.pi/2, 1)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Frequencies: 50.0\n",
|
||
|
"Phase: 0.5π\n",
|
||
|
"Amplitude: 1\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# show the signals\n",
|
||
|
"print(\"Frequencies:\", signal.freqs)\n",
|
||
|
"print(\"Phase:\", \"{}π\".format(signal.phase/np.pi))\n",
|
||
|
"print(\"Amplitude:\", signal.amplitude)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"[<matplotlib.lines.Line2D at 0x14591292bb10>]"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAD4CAYAAADhNOGaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nOy9d3hUx9m/f8+qFyQQaiABoghUEFVUYxtTTTHgXmM7ceIkb5z+S+LkTU+cOMk3id/0OHYc3AvGBoMwohiMbZooQh0JUSTUJYSEunbn98esHBlLqO3u2ZHOfV177e7ZUz6I3fPMPPMUIaXExMTExGToYjFagImJiYmJsZiGwMTExGSIYxoCExMTkyGOaQhMTExMhjimITAxMTEZ4ngaLaA/hIaGypiYGKNlmJiYmGjFsWPHqqSUYVdv19IQxMTEkJaWZrQMExMTE60QQpzvarvpGjIxMTEZ4piGwMTExGSIYxoCExMTkyGOaQhMTExMhjimITAxMTEZ4jjEEAgh/i2EqBBCZHbzuRBC/EkIUSCEOCWEmNX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K9jzM/AOgBvdrDPdDd8BYYEDvzdaiUk3HCys5sOCajUD9Xd8FVB3wzQEJl1S39zGsx+cZVl8uFPqqQwELw8LX7lpElkldd3PCkrTIS8FFn4VAlwb7tojwdFqVnDiRXNW4Kb8eU8B4cN8uG/e0OiPbhoCky554dB5Lje18dUl7jMt7syGmVGMCfHjT3vyu54VHPg9+ATB3EddL643LPqmOStwU46eq+F
|
||
|
"text/plain": [
|
||
|
"<Figure size 432x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"timing = np.linspace( 0, 5/signal.freqs, int(signal.freqs*4))\n",
|
||
|
"raw = mysignal(timing)\n",
|
||
|
"\n",
|
||
|
"fig, ax = plt.subplots()\n",
|
||
|
"ax.plot(timing, raw.real)\n",
|
||
|
"ax.plot(timing, raw.imag)\n",
|
||
|
"ax.plot(timing, np.abs(raw))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"### Correlate signal with a sine wave\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"$$ u[n] = \\exp(2 \\pi i f \\frac{n}{f_s} + i\\phi_t)$$\n",
|
||
|
"sampled with $f_s$, such that $N = f_s T$\n",
|
||
|
"\n",
|
||
|
"$$ v(t; f, \\chi) = \\exp(2 \\pi i f t + i\\chi ) $$\n",
|
||
|
"\n",
|
||
|
"---\n",
|
||
|
"\n",
|
||
|
"$$\\begin{align}\n",
|
||
|
"Corr(\\eta; u[n], v(t)) \n",
|
||
|
" &= \\sum_{n=0}^{N-1} u[n] \\; v^*(t - \\eta; f, \\chi) \\quad \\quad \\quad \\quad \\quad \\quad \\quad \\quad \\quad \\\\\n",
|
||
|
" &= \\sum_{n=0}^{N-1} u[n] \\; \\exp(-2 \\pi i f ( t - \\eta ) -i\\chi ) \\\\\n",
|
||
|
" &= \\sum_{n=0}^{N-1} u[n] \\; \\exp(-2 \\pi i f ( \\frac{n}{f_s} - \\eta ) -i\\chi ) \\\\\n",
|
||
|
" &= \\sum_{n=0}^{N-1} \\exp(2 \\pi i f \\frac{n}{f_s} + i\\phi_t) \\; \\exp(-2 \\pi i f ( \\frac{n}{f_s} - \\eta ) -i\\chi ) \\\\\n",
|
||
|
" &= \\sum_{n=0}^{N-1} \\exp(2 \\pi i f \\frac{n}{f_s} + i\\phi_t -2 \\pi i f ( \\frac{n}{f_s} - \\eta ) -i\\chi ) \\\\\n",
|
||
|
" &= \\sum_{n=0}^{N-1} \\exp(2 \\pi i f ( \\frac{n}{f_s} - \\frac{n}{f_s} + \\eta ) + i\\phi_t -i\\chi ) \\\\\n",
|
||
|
" &= \\sum_{n=0}^{N-1} \\exp(2 \\pi i f \\eta + i\\phi_t -i\\chi ) \\\\\n",
|
||
|
" &= \\exp(2 \\pi i f \\eta + i\\phi_t -i\\chi ) \\sum_{n=0}^{N-1} 1 \\\\\n",
|
||
|
" &= (N-1) \\exp(2 \\pi i f \\eta + i\\phi_t -i\\chi ) \\\\\n",
|
||
|
"\\end{align}$$\n",
|
||
|
"\n",
|
||
|
"---\n",
|
||
|
"Max correlation if $ 2 \\pi i f \\eta + i\\phi_t -i\\chi = 0 + 2 \\pi i k$ :\n",
|
||
|
"\n",
|
||
|
"$$ \\eta = \\frac{ \\chi - \\phi_t }{ 2 \\pi f } $$\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def correlate_function( eta, timing, raw, func, func_params=[] ):\n",
|
||
|
" N = len(raw)\n",
|
||
|
" \n",
|
||
|
" \n",
|
||
|
" np.sum( raw * func(timing - eta) )\n",
|
||
|
" \n",
|
||
|
" \n",
|
||
|
" "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"---\n",
|
||
|
"\n",
|
||
|
"$$\\begin{align}\n",
|
||
|
"Corr(\\eta; u[n], v(t)) \n",
|
||
|
" &= \\sum_{n=0}^{N-1} u[n] \\; v^*(t - \\eta; f', \\chi) \\quad \\quad \\quad \\quad \\quad \\quad \\quad \\quad \\quad \\\\\n",
|
||
|
" &= \\sum_{n=0}^{N-1} u[n] \\; \\exp(-2 \\pi i f' ( t - \\eta ) -i\\chi ) \\\\\n",
|
||
|
" &= \\sum_{n=0}^{N-1} u[n] \\; \\exp(-2 \\pi i f' ( \\frac{n}{f_s} - \\eta ) -i\\chi ) \\\\\n",
|
||
|
" &= \\sum_{n=0}^{N-1} \\exp(2 \\pi i f \\frac{n}{f_s} + i\\phi_t) \\; \\exp(-2 \\pi i f' ( \\frac{n}{f_s} - \\eta ) -i\\chi ) \\\\\n",
|
||
|
" &= \\sum_{n=0}^{N-1} \\exp(2 \\pi i f \\frac{n}{f_s} + i\\phi_t -2 \\pi i f' ( \\frac{n}{f_s} - \\eta ) -i\\chi ) \\\\\n",
|
||
|
" &= \\sum_{n=0}^{N-1} \\exp(2 \\pi i [\\frac{n}{f_s}(f-f') + f' \\eta ] + i\\phi_t -i\\chi ) \\\\\n",
|
||
|
" &= \\exp{(i (\\phi_t - \\chi))} \\; \\exp{(2 \\pi i f' \\eta)} \\; \\sum_{n=0}^{N-1} \\exp(2 \\pi i \\frac{(f-f')}{f_s} n) \\\\\n",
|
||
|
"\\end{align}$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"---\n",
|
||
|
"Write $\\alpha = \\frac{(f-f')}{f_s}$,\n",
|
||
|
"$$\\begin{align}\n",
|
||
|
"0\n",
|
||
|
" &= \\frac{\\partial}{\\partial \\alpha} \\sum_{n=0}^{N-1} \\exp(2 \\pi i \\alpha n)\n",
|
||
|
" \\\\\n",
|
||
|
" &= \\sum_{n=0}^{N-1} \\frac{\\partial}{\\partial \\alpha} \\exp(2 \\pi i \\alpha n)\n",
|
||
|
" \\\\\n",
|
||
|
" &= \\sum_{n=1}^{N-1} \\frac{1}{2 \\pi i n} \\exp(2 \\pi i \\alpha n)\n",
|
||
|
" \\\\\n",
|
||
|
" &= \\frac{1}{2 \\pi } \\sum_{n=1}^{N-1} \\frac{ \\cos(2 \\pi \\alpha n) - i \\sin(2 \\pi \\alpha n)}{ni}\n",
|
||
|
" \\\\\n",
|
||
|
" &= \\frac{-1}{2 \\pi } \\sum_{n=1}^{N-1} \\frac{ i \\cos(2 \\pi \\alpha n) + \\sin(2 \\pi \\alpha n)}{n}\n",
|
||
|
"\\end{align}$$\n",
|
||
|
"\n",
|
||
|
"Actually, we are looking at the amplitude (or power) so we take the absolute value:\n",
|
||
|
"$$\\begin{align}\n",
|
||
|
" \\\\\n",
|
||
|
" &= \\frac{1}{2 \\pi } \\sum_{n=1}^{N-1} {\\frac{ \\cos(2 \\pi \\alpha n) + \\sin(2 \\pi \\alpha n)}{n}}\n",
|
||
|
" \\\\\n",
|
||
|
" &= \\frac{1}{\\sqrt{2} \\pi } \\sum_{n=1}^{N-1} {\\frac{ \\sin( 2 \\pi \\alpha n + \\frac{\\pi}{4}) }{n}}\n",
|
||
|
" \\\\\n",
|
||
|
" &= \\sum_{n=1}^{N-1} \\frac{1}{\\sqrt{2} \\pi } {\\frac{ \\sin( 2 \\pi \\alpha n + \\frac{\\pi}{4}) }{n}}\n",
|
||
|
" \\\\\n",
|
||
|
" &= \\sum_{n=1}^{N-1} \\sqrt{2} \\alpha {\\frac{ \\sin( 2 \\pi \\alpha n + \\frac{\\pi}{4}) }{2 \\pi \\alpha n}}\n",
|
||
|
"\\end{align}$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"---\n",
|
||
|
"\n",
|
||
|
"We get a $\\sin(2\\pi\\alpha n + \\frac{\\pi}{4}) $ dependency, \\\n",
|
||
|
"the amplitude is zero when\n",
|
||
|
"$$\n",
|
||
|
" 2\\pi\\alpha n + \\frac{\\pi}{4} = \\pi k \\; \\text{with k integer}\n",
|
||
|
"$$\n",
|
||
|
"or\n",
|
||
|
"$$\n",
|
||
|
" \\alpha n = \\frac{4k-1}{8} = \\frac{k}{2} - \\frac{1}{8} \\;\\text{with k,n integer}\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"Likewise, the amplitude is maximal when\n",
|
||
|
"$$\n",
|
||
|
" 2\\pi\\alpha n + \\frac{\\pi}{4} = \\pi (k+\\frac{1}{2}) \\; \\text{with k integer}\n",
|
||
|
"$$\n",
|
||
|
"or\n",
|
||
|
"$$\n",
|
||
|
" \\alpha n = \\frac{4k+1}{8} = \\frac{k}{2} + \\frac{1}{8} \\; \\text{with k,n integer}\n",
|
||
|
"$$\n",
|
||
|
"\n",
|
||
|
"---"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"$$\\begin{align}\n",
|
||
|
"Corr(\\eta; u[n], v(t)) \n",
|
||
|
"&= \\exp{(i (\\phi_t - \\chi))} \\; \\exp{(2 \\pi i f' \\eta)} \\; \\sum_{n=0}^{N-1} \\exp(2 \\pi i \\frac{n}{f_s}(f-f'))\n",
|
||
|
"\\\\\n",
|
||
|
"&= \\exp{(\\pi i ( 2f' \\eta + \\phi_t - \\chi))} \\; \\sum_{n=0}^{N-1} \\exp(2 \\pi i \\frac{n}{f_s}(f-f'))\n",
|
||
|
"\\end{align}$$\n",
|
||
|
"maximal with\n",
|
||
|
"$$\n",
|
||
|
"n = \\frac{f_s}{2(f - f')} {(k + \\frac{1}{4})} \\text{, and }\n",
|
||
|
"\\eta = \\frac{ \\chi - \\phi_t }{ 2 \\pi f' }\n",
|
||
|
"$$"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": []
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 4,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"ename": "TypeError",
|
||
|
"evalue": "almost_sinc() missing 1 required positional argument: 'N'",
|
||
|
"output_type": "error",
|
||
|
"traceback": [
|
||
|
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||
|
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
|
||
|
"\u001b[0;32m<ipython-input-4-a147ffca3697>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 33\u001b[0m \u001b[0;31m#ax.plot(alphas, np.abs(misfit)**2, label=\"Power\")\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 35\u001b[0;31m \u001b[0max\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0malphas\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0malmost_sinc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msinc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpi\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;36m1.5\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0malphas\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mN\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mabs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msinc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpi\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;36m1.5\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0malphas\u001b[0m \u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m \u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 36\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 37\u001b[0m \u001b[0mn\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0;36m10\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||
|
"\u001b[0;31mTypeError\u001b[0m: almost_sinc() missing 1 required positional argument: 'N'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAs8A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KnTjiVlQdXStcNIcQJ9c7+d7qVbEBkDYbLwKgzQHLngpzoug2AC6ZcQJO3ibK6ssQGK4QQx1h1aBUazTmTzul6raPzXuSS5Hl0S7KZCYU03kD30edD7YfY27J3CCMTQoxmbf42SmtL+Vj+x7pe01rj9gcNj9pEk+xjZ89On3g6FmXh/UPvJzZgIYQ4xsoDK8lx5jA3c27Xax2+EDaLydDM2XAwMqIchqIPqY5jRm6iD7OVB1cOSUxCiNFvTfUagjrYLXn2BEKEw8ZHbSzmyGZPx96/UmwpLMpdJMmzEOKECYQCfHD4Az6W/7GuFpsQKdswOnM2HEjyPEhJvYzcjHeNZ3bGbEmehRAnzL8P/psUWwolOSVdr0U7ZwxkytNlN3cr2wA4K+8sdjbvpLq9OjHBCiHEMUrrSmkPtHf78A/RsrORUbIBkjwPmt0S6ZV6bN0zREafy+rKaPG1DFFkQojRKqzDrDq0ijMmnoHFdPRB0+GPfIh32YyP3LjsFtz+YLc1GtEHmow+CyFOhJUHV2Iz2Thtwmldr3kDkW25R8LmKFGSPMfBZes+7QmRh09Ih/jg8AdDFJUQYrTa1rSNBk8DZ+Wf1e11tz+IzWLCMoB6wSSbmXAYfMGjvemnpk0lLzlPkmchxAnx/sH3OWX8KSRZk7peG2mLBUGS57gk2SK9Uo9VlF1EijWFtdVrhygqIcRoterQKhSKMyae0e11jz9E0gBGnQGc1sj5x97DlFKclXcWa6vX4g/54w9YCCE61XTUUNVaxbKJy7q9Hr0HDfQeNpQkeY5Dks2MPxgmGDo6cmM2mTll/Cl8ePh
|
||
|
"text/plain": [
|
||
|
"<Figure size 864x288 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {
|
||
|
"needs_background": "light"
|
||
|
},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Frequency misfit term alpha = (f - f')/fs\n",
|
||
|
"\n",
|
||
|
"N = 10\n",
|
||
|
"\n",
|
||
|
"def misfit_term(alpha, N):\n",
|
||
|
" n = np.arange(0, N-1)\n",
|
||
|
" \n",
|
||
|
" alpha_n = np.outer(n, alpha)\n",
|
||
|
" return np.sum(np.exp( 2j*np.pi* alpha_n), axis=0)\n",
|
||
|
"\n",
|
||
|
"def almost_sinc(\n",
|
||
|
" x, phase=np.pi/4):\n",
|
||
|
" return np.sin(2*np.pi*alpha*n + phase) / (np.sqrt(2)*np.pi*n)\n",
|
||
|
"\n",
|
||
|
"def almost_sinc(alpha, N, phase=np.pi/4):\n",
|
||
|
" n = np.arange(0, N-1)\n",
|
||
|
" \n",
|
||
|
" alpha_n = np.outer(n, alpha)\n",
|
||
|
" return np.sum(almost_sinc_per_n, axis=0)\n",
|
||
|
"\n",
|
||
|
"####\n",
|
||
|
"alphas = np.linspace(-1, 1, 2*500)\n",
|
||
|
"misfit = misfit_term(alphas, N)\n",
|
||
|
"\n",
|
||
|
"\n",
|
||
|
"fig, ax = plt.subplots(figsize=(12,4))\n",
|
||
|
"ax.set_xlabel(\"alpha\")\n",
|
||
|
"ax.set_ylabel(\"misfit sum term\")\n",
|
||
|
"ax.axhline(N-1)\n",
|
||
|
"\n",
|
||
|
"ax.plot(alphas, np.real(misfit), alpha=0.3, label=\"Real\")\n",
|
||
|
"ax.plot(alphas, np.imag(misfit), alpha=0.3, label=\"Imag\")\n",
|
||
|
"ax.plot(alphas, np.abs(misfit), label=\"Abs\")\n",
|
||
|
"#ax.plot(alphas, np.abs(misfit)**2, label=\"Power\")\n",
|
||
|
"if True:\n",
|
||
|
" ax.plot(alphas, (N-1)*almost_sinc(np.sinc(2*np.pi*1.5*alphas)) + (N-1)*np.abs(np.sinc(2*np.pi*1.5*(alphas -1 ))))\n",
|
||
|
"if True:\n",
|
||
|
" n= 10\n",
|
||
|
" ax.plot(alphas, -1*(N-1)*np.sin(2*np.pi*alphas*n - np.pi/4))\n",
|
||
|
"\n",
|
||
|
"fig.legend(loc='center right')\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# Header"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"s\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"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
|
||
|
}
|