space-workshop/U02_4_Sync.en.ipynb
2025-09-19 23:21:37 +02:00

80 lines
2.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "f611b5a0",
"metadata": {},
"source": [
"# Synchronization"
]
},
{
"cell_type": "markdown",
"id": "0c5468d3",
"metadata": {},
"source": [
"Currently, the samples are still represented as complex numbers.\n",
"To continue working with them, we convert them to their magnitudes:\n",
"```{math}\n",
"s = a + bi \\mapsto |s| = \\sqrt{a^2 + b^2}\n",
"```\n",
"\n",
"Here is a visualization of the signal as processed so far:\n",
"```{figure} img/reference/filtered_full_scaled.webp\n",
"---\n",
"name: fig:filtered_full_scaled.en\n",
"---\n",
"Filtered signal.\n",
"We observe that the sync lines are bent.\n",
"```\n",
"\n",
"The sync patterns mark the beginning of each line.\n",
"To \"straighten out\" the image, we have to find them.\n",
"\n",
"We proceed as follows:\n",
"- Sync A has the pattern `000011001100110011001100110011000000000`.\n",
" We have 4 samples per pixel, and thus also per 0/1 in the pattern.\n",
" We want to find this pattern.\n",
" This is easiest if we scale both the pattern and our samples into the range between $-1$ and $1$.\n",
" For every `0` in the pattern, we take four $-1$s, and for every `1` we take four $1$s.\n",
" We save this sequence of 39 * 4 = 156 values as $p$.\n",
"- We now look at blocks $x$ of 8320 samples.\n",
" We find the minimum value $x_{min}$ and the maximum value $x_{max}$ within the block, and scale it such that the minimum is at $-1$ and the maximum at $1$:\n",
" ```{math}\n",
" x[n] \\mapsto -1 + 2 \\cdot \\frac{x[n] - x_{min}}{x_{max} - x_{min}}\n",
" ```\n",
"- We want to find the position that best matches the pattern.\n",
" To do this, we iterate over all positions $i$ in the block from 0 to (8320-156).\n",
" For each position, we compute the *correlation*\n",
" ```{math}\n",
" z = \\sum_{n=0}^{156} x[i + n] \\cdot p[n]\n",
" ```\n",
" The position with the highest $z$ value is the one that matches best.\n",
"- This way, we can find the starting position of each line.\n",
" From there, we can take every fourth sample to get the pixel values for this line."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}