notebook: update examples

refactor into import, simulation and plotting 3 codeblocks
remove extra config for wrapper
add docs string for RNG
change adpll_period & start_up_delay unit
This commit is contained in:
morgan 2023-12-13 15:44:11 +08:00
parent 0b724e84da
commit 7c4a680787
3 changed files with 109 additions and 103 deletions

View File

@ -39,74 +39,76 @@
"from plotly.subplots import make_subplots\n", "from plotly.subplots import make_subplots\n",
"import plotly.graph_objects as go\n", "import plotly.graph_objects as go\n",
"import numpy as np\n", "import numpy as np\n",
"from wave_gen import square_arr\n", "from wrpll import WRPLL_simulator"
"from wrpll import WRPLL_simulator\n", ]
"\n", },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# settings\n", "# settings\n",
"timestep = 4e-10 # even number is recommended to avoid strange glitches\n", "timestep = 1e-10\n",
"total_steps = 300_000_000\n", "total_steps = 200_000_000\n",
"sim_mode = \"both\"\n", "sim_mode = \"both\"\n",
"adpll_period = int(100e-6/timestep) # in simulation steps, 100μs is minimum, smaller = more frequency adjustment and filter calulation per unit time\n", "adpll_period = 100e-6 # in seconds, the period that pll will trigger, (minimum > the sampling rate of collector)\n",
"start_up_delay = int(100e-6/timestep) # in simulation steps, the frequency adjustment is DISABLE until steps > start_up_delay\n", "start_up_delay = 100e-6 # in seconds, the frequency adjustment is DISABLE until time > start_up_delay\n",
"\n", "\n",
"gtx_freq = 125_001_519\n", "gtx_freq = 125_001_519\n",
"\n", "\n",
"helper_init_freq = gtx_freq * (4096-1)/4096\n",
"\n", "\n",
"helper_filter = {\n", "helper_filter = {\n",
" \"KP\": 2,\n", " \"KP\": 2,\n",
" \"KI\": 4,\n", " \"KI\": 0.5,\n",
" \"KD\": 0,\n", " \"KD\": 0,\n",
"}\n", "}\n",
"\n", "\n",
"main_filter = { \n", "main_filter = {\n",
" \"KP\": 12,\n", " \"KP\": 12,\n",
" \"KI\": 0,\n", " \"KI\": 0,\n",
" \"KD\": 0,\n", " \"KD\": 0,\n",
"}\n", "}\n",
"\n", "\n",
"\n", "\n",
"t = np.linspace(0, timestep*total_steps, total_steps)\n", "# simulation have RNG for\n",
"\n", "# - gtx, main and helper jitter\n",
"# simulation will start with\n", "# - starting phase for main and helper\n",
"# - random phase for main & helper\n", "# - base_adpll error\n",
"# - gussian based base_adpll error\n",
"# - gussian jitter for gtx, main and helper with the set standard deviation\n",
"\n", "\n",
"wrpll_sim = WRPLL_simulator(\n", "wrpll_sim = WRPLL_simulator(\n",
" time=t,\n", " timestep=timestep,\n",
" total_steps=total_steps,\n",
" sim_mode=sim_mode,\n", " sim_mode=sim_mode,\n",
" helper_filter=helper_filter,\n", " helper_filter=helper_filter,\n",
" main_filter=main_filter,\n", " main_filter=main_filter,\n",
" gtx_freq=gtx_freq,\n", " gtx_freq=gtx_freq,\n",
" adpll_write_period=adpll_period,\n", " adpll_write_period=adpll_period,\n",
" start_up_delay=start_up_delay,\n", " start_up_delay=start_up_delay,\n",
" helper_init_freq=helper_init_freq,\n",
" # preset\n",
" gtx_jitter_SD=19e-12, # 0 = no jitter\n",
" dcxo_jitter_SD=9e-12,\n",
" dcxo_freq=125_000_000,\n",
" freq_acquisition_SD=100,\n",
" N=4096, # hardware used 4096\n",
" blind_period=300, # 300 is used to remove most glitches in simulation (for details see README 'Limitation')\n",
" cycle_slip_comp=True,\n",
")\n", ")\n",
"wrpll_sim.run()\n", "wrpll_sim.run()"
"\n", ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# faster than pyplot with resampling feature\n", "# faster than pyplot with resampling feature\n",
"# see https://github.com/predict-idlab/plotly-resampler\n", "# see https://github.com/predict-idlab/plotly-resampler\n",
"\n", "\n",
"fig = FigureWidgetResampler(make_subplots(rows=4, shared_xaxes=True))\n", "fig = FigureWidgetResampler(make_subplots(rows=4, shared_xaxes=True))\n",
"fig.add_trace(go.Scattergl(name='phase error'), hf_x=t, hf_y=wrpll_sim.phase_err, row=1, col=1)\n", "fig.add_trace(go.Scattergl(name='phase error'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.phase_err, row=1, col=1)\n",
"\n", "\n",
"fig.add_trace(go.Scattergl(name='freq error (ppm)'), hf_x=t, hf_y=(\n", "fig.add_trace(go.Scattergl(name='freq error (ppm)'), hf_x=wrpll_sim.time, hf_y=(\n",
" wrpll_sim.mainfreq-gtx_freq) * (1e6/gtx_freq), row=2, col=1)\n", " wrpll_sim.mainfreq-gtx_freq) * (1e6/gtx_freq), row=2, col=1)\n",
"\n", "\n",
"fig.add_trace(go.Scattergl(name='period error'), hf_x=t, hf_y=wrpll_sim.period_err, row=3, col=1)\n", "fig.add_trace(go.Scattergl(name='period error'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.period_err, row=3, col=1)\n",
"\n", "\n",
"fig.add_trace(go.Scattergl(name='gtx'), hf_x=t, hf_y=wrpll_sim.gtx+1, row=4, col=1)\n", "fig.add_trace(go.Scattergl(name='gtx'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.gtx+1, row=4, col=1)\n",
"fig.add_trace(go.Scattergl(name='main'), hf_x=t, hf_y=wrpll_sim.main, row=4, col=1)\n", "fig.add_trace(go.Scattergl(name='main'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.main, row=4, col=1)\n",
"fig.add_trace(go.Scattergl(name='helper'), hf_x=t, hf_y=wrpll_sim.helper-1, row=4, col=1)\n", "fig.add_trace(go.Scattergl(name='helper'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.helper-1, row=4, col=1)\n",
"\n", "\n",
"\n", "\n",
"fig.update_layout(\n", "fig.update_layout(\n",

View File

@ -39,21 +39,27 @@
"from plotly.subplots import make_subplots\n", "from plotly.subplots import make_subplots\n",
"import plotly.graph_objects as go\n", "import plotly.graph_objects as go\n",
"import numpy as np\n", "import numpy as np\n",
"from wave_gen import square_arr\n", "from wrpll import WRPLL_simulator"
"from wrpll import WRPLL_simulator\n", ]
"\n", },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# settings\n", "# settings\n",
"timestep = 4e-10 # even number is recommended to avoid strange glitches\n", "timestep = 1e-10\n",
"total_steps = 200_000_000\n", "total_steps = 100_000_000\n",
"sim_mode = \"helper_pll\"\n", "sim_mode = \"helper_pll\"\n",
"adpll_period = int(100e-6/timestep) # in simulation steps, 100μs is minimum, smaller = more frequency adjustment and filter calulation per unit time\n", "adpll_period = 100e-6 # in seconds, the period that pll will trigger, (minimum > the sampling rate of collector)\n",
"start_up_delay = int(100e-6/timestep) # in simulation steps, the frequency adjustment is DISABLE until steps > start_up_delay\n", "start_up_delay = 100e-6 # in seconds, the frequency adjustment is DISABLE until time > start_up_delay\n",
"\n", "\n",
"gtx_freq = 125_001_519\n", "gtx_freq = 125_001_519\n",
"\n", "\n",
"helper_filter = {\n", "helper_filter = {\n",
" \"KP\": 2,\n", " \"KP\": 2,\n",
" \"KI\": 4,\n", " \"KI\": 0.5,\n",
" \"KD\": 0,\n", " \"KD\": 0,\n",
"}\n", "}\n",
"\n", "\n",
@ -63,53 +69,46 @@
" \"KD\": 0,\n", " \"KD\": 0,\n",
"}\n", "}\n",
"\n", "\n",
"\n", "# simulation have RNG for\n",
"t = np.linspace(0, timestep*total_steps, total_steps)\n", "# - gtx, main and helper jitter\n",
"\n", "# - starting phase for main and helper\n",
"# simulation will start with\n", "# - base_adpll error\n",
"# - random phase for main & helper\n",
"# - gussian based base_adpll error\n",
"# - gussian jitter for gtx, main and helper with the set standard deviation\n",
"\n", "\n",
"wrpll_sim = WRPLL_simulator(\n", "wrpll_sim = WRPLL_simulator(\n",
" time=t,\n", " timestep=timestep,\n",
" total_steps=total_steps,\n",
" sim_mode=sim_mode,\n", " sim_mode=sim_mode,\n",
" helper_filter=helper_filter,\n", " helper_filter=helper_filter,\n",
" main_filter=main_filter,\n", " main_filter=main_filter,\n",
" gtx_freq=gtx_freq,\n", " gtx_freq=gtx_freq,\n",
" adpll_write_period=adpll_period,\n", " adpll_write_period=adpll_period,\n",
" start_up_delay=start_up_delay,\n", " start_up_delay=start_up_delay,\n",
" # preset\n",
" gtx_jitter_SD=19e-12, # 0 = no jitter\n",
" dcxo_jitter_SD=9e-12,\n",
" dcxo_freq=125_000_000,\n",
" freq_acquisition_SD=500,\n",
" N=4096, # hardware used 4096\n",
" blind_period=300, # 300 is used to remove most glitches in simulation (for details see README 'Limitation')\n",
" cycle_slip_comp=True,\n",
")\n", ")\n",
"\n", "wrpll_sim.run()"
"wrpll_sim.run()\n", ]
"\n", },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# faster than pyplot with resampling feature\n", "# faster than pyplot with resampling feature\n",
"# see https://github.com/predict-idlab/plotly-resampler\n", "# see https://github.com/predict-idlab/plotly-resampler\n",
"\n", "\n",
"fig = FigureWidgetResampler(make_subplots(rows=3, shared_xaxes=True))\n", "fig = FigureWidgetResampler(make_subplots(rows=2, shared_xaxes=True))\n",
"fig.add_trace(go.Scattergl(name='period error'), hf_x=t, hf_y=wrpll_sim.period_err, row=1, col=1)\n", "fig.add_trace(go.Scattergl(name='period error'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.period_err, row=1, col=1)\n",
"\n",
"fig.add_trace(go.Scattergl(name='gtx'), hf_x=t, hf_y=wrpll_sim.gtx+1, row=2, col=1)\n",
"fig.add_trace(go.Scattergl(name='main'), hf_x=t, hf_y=wrpll_sim.main, row=2, col=1)\n",
"fig.add_trace(go.Scattergl(name='helper'), hf_x=t, hf_y=wrpll_sim.helper-1, row=2, col=1)\n",
"\n",
"fig.add_trace(go.Scattergl(name='helper'), hf_x=t, hf_y=wrpll_sim.helper_adpll, row=3, col=1)\n",
"\n", "\n",
"fig.add_trace(go.Scattergl(name='gtx'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.gtx+1, row=2, col=1)\n",
"fig.add_trace(go.Scattergl(name='main'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.main, row=2, col=1)\n",
"fig.add_trace(go.Scattergl(name='helper'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.helper-1, row=2, col=1)\n",
"\n", "\n",
"fig.update_layout(\n", "fig.update_layout(\n",
" xaxis2=dict(title=\"time (sec)\"),\n", " xaxis2=dict(title=\"time (sec)\"),\n",
"\n", "\n",
" yaxis1=dict(title=\"beating period error\"),\n", " yaxis1=dict(title=\"beating period error\"),\n",
" yaxis2=dict(title=\"Signal\"),\n", " yaxis2=dict(title=\"Signal\"),\n",
" height=500,\n", " height=1000,\n",
" showlegend=True,\n", " showlegend=True,\n",
" title_text=\"PLL example\",\n", " title_text=\"PLL example\",\n",
" legend=dict(\n", " legend=dict(\n",

View File

@ -42,15 +42,21 @@
"from plotly.subplots import make_subplots\n", "from plotly.subplots import make_subplots\n",
"import plotly.graph_objects as go\n", "import plotly.graph_objects as go\n",
"import numpy as np\n", "import numpy as np\n",
"from wave_gen import square_arr\n", "from wrpll import WRPLL_simulator"
"from wrpll import WRPLL_simulator\n", ]
"\n", },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# settings\n", "# settings\n",
"timestep = 4e-10 # even number is recommended to avoid strange glitches\n", "timestep = 1e-10\n",
"total_steps = 200_000_000\n", "total_steps = 100_000_000\n",
"sim_mode = \"main_pll\"\n", "sim_mode = \"main_pll\"\n",
"adpll_period = int(100e-6/timestep) # in simulation steps, 100μs is minimum, smaller = more frequency adjustment and filter calulation per unit time\n", "adpll_period = 100e-6 # in seconds, the period that pll will trigger, (minimum > the sampling rate of collector)\n",
"start_up_delay = int(100e-6/timestep) # in simulation steps, the frequency adjustment is DISABLE until steps > start_up_delay\n", "start_up_delay = 100e-6 # in seconds, the frequency adjustment is DISABLE until time > start_up_delay\n",
"\n", "\n",
"gtx_freq = 125_001_519\n", "gtx_freq = 125_001_519\n",
"\n", "\n",
@ -58,58 +64,57 @@
"\n", "\n",
"helper_filter = { # unused\n", "helper_filter = { # unused\n",
" \"KP\": 2,\n", " \"KP\": 2,\n",
" \"KI\": 4,\n", " \"KI\": 0.5,\n",
" \"KD\": 0,\n", " \"KD\": 0,\n",
"}\n", "}\n",
"\n", "\n",
"main_filter = { \n", "main_filter = {\n",
" \"KP\": 12,\n", " \"KP\": 12,\n",
" \"KI\": 0,\n", " \"KI\": 0,\n",
" \"KD\": 0,\n", " \"KD\": 0,\n",
"}\n", "}\n",
"\n", "\n",
"\n", "\n",
"t = np.linspace(0, timestep*total_steps, total_steps)\n", "# simulation have RNG for\n",
"# - gtx, main and helper jitter\n",
"# - starting phase for main and helper\n",
"# - base_adpll error\n",
"\n", "\n",
"# simulation will start with\n",
"# - random phase for main & helper\n",
"# - gussian based base_adpll error\n",
"# - gussian jitter for gtx, main and helper with the set standard deviation\n",
"\n", "\n",
"wrpll_sim = WRPLL_simulator(\n", "wrpll_sim = WRPLL_simulator(\n",
" time=t,\n", " timestep=timestep,\n",
" total_steps=total_steps,\n",
" sim_mode=sim_mode,\n", " sim_mode=sim_mode,\n",
" helper_filter=helper_filter,\n", " helper_filter=helper_filter,\n",
" main_filter=main_filter,\n", " main_filter=main_filter,\n",
" gtx_freq=gtx_freq,\n", " gtx_freq=gtx_freq,\n",
" adpll_write_period=adpll_period,\n", " adpll_write_period=adpll_period,\n",
" start_up_delay=start_up_delay,\n", " start_up_delay=start_up_delay,\n",
" helper_init_freq=helper_init_freq,\n", " helper_init_freq=helper_init_freq\n",
" # preset\n",
" gtx_jitter_SD=19e-12, # 0 = no jitter\n",
" dcxo_jitter_SD=9e-12,\n",
" dcxo_freq=125_000_000,\n",
" freq_acquisition_SD=100,\n",
" N=4096, # hardware used 4096\n",
" blind_period=300, # 300 is used to remove most glitches in simulation (for details see README 'Limitation')\n",
" cycle_slip_comp=True,\n",
")\n", ")\n",
"wrpll_sim.run()\n", "wrpll_sim.run()"
"\n", ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# faster than pyplot with resampling feature\n", "# faster than pyplot with resampling feature\n",
"# see https://github.com/predict-idlab/plotly-resampler\n", "# see https://github.com/predict-idlab/plotly-resampler\n",
"\n", "\n",
"fig = FigureWidgetResampler(make_subplots(rows=4, shared_xaxes=True))\n", "fig = FigureWidgetResampler(make_subplots(rows=4, shared_xaxes=True))\n",
"fig.add_trace(go.Scattergl(name='phase error'), hf_x=t, hf_y=wrpll_sim.phase_err, row=1, col=1)\n", "fig.add_trace(go.Scattergl(name='phase error'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.phase_err, row=1, col=1)\n",
"\n", "\n",
"fig.add_trace(go.Scattergl(name='freq error (ppm)'), hf_x=t, hf_y=(\n", "fig.add_trace(go.Scattergl(name='freq error (ppm)'), hf_x=wrpll_sim.time, hf_y=(\n",
" wrpll_sim.mainfreq-gtx_freq) * (1e6/gtx_freq), row=2, col=1)\n", " wrpll_sim.mainfreq-gtx_freq) * (1e6/gtx_freq), row=2, col=1)\n",
"\n", "\n",
"fig.add_trace(go.Scattergl(name='period error'), hf_x=t, hf_y=wrpll_sim.period_err, row=3, col=1)\n", "fig.add_trace(go.Scattergl(name='period error'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.period_err, row=3, col=1)\n",
"\n", "\n",
"fig.add_trace(go.Scattergl(name='gtx'), hf_x=t, hf_y=wrpll_sim.gtx+1, row=4, col=1)\n", "fig.add_trace(go.Scattergl(name='gtx'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.gtx+1, row=4, col=1)\n",
"fig.add_trace(go.Scattergl(name='main'), hf_x=t, hf_y=wrpll_sim.main, row=4, col=1)\n", "fig.add_trace(go.Scattergl(name='main'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.main, row=4, col=1)\n",
"fig.add_trace(go.Scattergl(name='helper'), hf_x=t, hf_y=wrpll_sim.helper-1, row=4, col=1)\n", "fig.add_trace(go.Scattergl(name='helper'), hf_x=wrpll_sim.time, hf_y=wrpll_sim.helper-1, row=4, col=1)\n",
"\n", "\n",
"\n", "\n",
"fig.update_layout(\n", "fig.update_layout(\n",