-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial.html
More file actions
764 lines (692 loc) · 36.6 KB
/
Copy pathtutorial.html
File metadata and controls
764 lines (692 loc) · 36.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PAM4 SerDes TX Linear Fit — Tutorial</title>
<style>
:root{--bg:#f8f9fa;--card:#fff;--ac:#2563eb;--ac2:#059669;--warn:#d97706;
--cbg:#1e293b;--cfg:#e2e8f0;--bdr:#e2e8f0;}
*{box-sizing:border-box;margin:0;padding:0;}
body{font-family:'Segoe UI','Microsoft JhengHei',sans-serif;background:var(--bg);color:#1e293b;line-height:1.75;}
.container{max-width:1060px;margin:0 auto;padding:20px;}
nav{background:var(--cbg);color:#fff;padding:10px 0;position:sticky;top:0;z-index:99;}
nav .container{display:flex;align-items:center;gap:18px;flex-wrap:wrap;}
nav a{color:#93c5fd;text-decoration:none;font-size:.85em;}nav a:hover{color:#fff;}
nav .title{font-size:1.15em;font-weight:700;color:#fff;margin-right:auto;}
section{background:var(--card);border:1px solid var(--bdr);border-radius:12px;padding:30px 32px;margin:22px 0;box-shadow:0 1px 4px rgba(0,0,0,.06);}
h1{font-size:1.9em;margin-bottom:6px;color:var(--ac);}
h2{font-size:1.45em;margin:22px 0 10px;color:var(--ac);border-bottom:2px solid var(--ac);padding-bottom:4px;}
h3{font-size:1.1em;margin:16px 0 6px;color:#334155;}
p,li{margin-bottom:7px;}ul,ol{padding-left:22px;}
pre{background:var(--cbg);color:var(--cfg);padding:14px 18px;border-radius:8px;overflow-x:auto;font-size:.86em;line-height:1.5;margin:10px 0;font-family:Consolas,'Courier New',monospace;}
code{font-family:Consolas,'Courier New',monospace;background:#f1f5f9;padding:1px 5px;border-radius:4px;font-size:.9em;}
pre code{background:none;padding:0;}
table{border-collapse:collapse;width:100%;margin:10px 0;}
th,td{border:1px solid var(--bdr);padding:7px 10px;text-align:center;}
th{background:#f1f5f9;font-weight:600;}tr:nth-child(even){background:#f8fafc;}
.note{background:#eff6ff;border-left:4px solid var(--ac);padding:12px 16px;border-radius:0 8px 8px 0;margin:12px 0;}
.warn{background:#fffbeb;border-left:4px solid var(--warn);padding:12px 16px;border-radius:0 8px 8px 0;margin:12px 0;}
.key{background:#f0fdf4;border-left:4px solid var(--ac2);padding:12px 16px;border-radius:0 8px 8px 0;margin:12px 0;}
.eq{background:#f8fafc;border:1px solid var(--bdr);padding:14px 20px;border-radius:8px;margin:12px 0;text-align:center;font-size:1.08em;font-family:'Cambria Math','Times New Roman',serif;}
.flow{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin:14px 0;justify-content:center;}
.flow .box{background:var(--ac);color:#fff;padding:7px 14px;border-radius:8px;font-weight:600;font-size:.88em;text-align:center;min-width:90px;}
.flow .box.green{background:var(--ac2);}.flow .box.orange{background:var(--warn);}.flow .box.red{background:#dc2626;}
.flow .arrow{font-size:1.3em;color:#94a3b8;}
.tag{display:inline-block;padding:1px 9px;border-radius:12px;font-size:.78em;font-weight:600;}
.tag.blue{background:#dbeafe;color:#1e40af;}.tag.green{background:#dcfce7;color:#166534;}.tag.red{background:#fee2e2;color:#991b1b;}
.matrix{display:inline-block;border-left:2px solid #334155;border-right:2px solid #334155;padding:3px 8px;margin:4px;vertical-align:middle;}
.matrix td{border:none;padding:2px 7px;font-family:Consolas,monospace;font-size:.82em;}
/* ---- figure + annotation layout ---- */
.fig-section{margin:18px 0;}
.fig-section img{width:100%;border:1px solid #ddd;border-radius:8px;margin:8px 0;cursor:zoom-in;}
.fig-section img:hover{box-shadow:0 2px 12px rgba(0,0,0,.15);}
.fig-row{display:flex;gap:18px;align-items:flex-start;margin:14px 0;}
.fig-row .fig-img{flex:1.1;min-width:0;}
.fig-row .fig-img img{width:100%;border:1px solid #ddd;border-radius:8px;}
.fig-row .fig-note{flex:1;min-width:260px;}
.callout{display:inline-block;background:#fef3c7;border:1px solid #f59e0b;padding:1px 7px;border-radius:6px;font-size:.85em;font-weight:600;margin:2px 0;}
footer{text-align:center;padding:28px;color:#94a3b8;font-size:.83em;}
@media(max-width:750px){.fig-row{flex-direction:column;}.container{padding:10px;}section{padding:16px;}}
</style>
</head>
<body>
<nav><div class="container">
<span class="title">PAM4 SerDes Linear Fit Tutorial</span>
<a href="#overview">Overview</a>
<a href="#workflow">Flow</a>
<a href="#tab-waveform">Waveform</a>
<a href="#tab-eye">Eye</a>
<a href="#tab-pulse">Pulse</a>
<a href="#tab-step">Step</a>
<a href="#tab-ac">AC</a>
<a href="#tab-linfit">Linear Fit</a>
<a href="#tab-hist">Histogram</a>
<a href="#faq">FAQ</a>
<a href="#math">Math</a>
</div></nav>
<div class="container">
<!-- ============================================================ -->
<section id="overview">
<h1>PAM4 Channel Pulse Response Extraction</h1>
<div class="key">
<strong>已知:</strong>ideal PRBS pattern <code>a[n]</code>(無 ISI)+ 量測波形 <code>y[n]</code>(有 ISI)<br>
<strong>求解:</strong>channel pulse response <code>h[k]</code><br>
<strong>驗證:</strong><code>conv(a, h) ≈ y</code>,FFT(h) ≈ channel 頻率響應
</div>
</section>
<!-- ============================================================ -->
<section id="workflow">
<h2>完整流程</h2>
<div class="flow">
<div class="box">Ideal PRBS<br><small>a[n], 無 ISI</small></div><span class="arrow">→</span>
<div class="box orange">Loss Channel<br><small>H(f)</small></div><span class="arrow">→</span>
<div class="box red">Measured<br><small>y[n], 有 ISI</small></div><span class="arrow">→</span>
<div class="box green">Linear Fit<br><small>y = A·h</small></div><span class="arrow">→</span>
<div class="box">Pulse h[k]</div>
</div>
<p style="text-align:center;margin:10px 0;">
驗證:<code>conv(a, h)</code> = <strong>fitted waveform</strong> ≈ measured waveform<br>
頻域:<code>FFT(h)</code> = 系統 AC response
</p>
</section>
<!-- ============================================================ -->
<!-- TAB 1: WAVEFORM -->
<!-- ============================================================ -->
<section id="tab-waveform">
<h2>Tab 1: Waveform — 三種波形比較</h2>
<div class="fig-section"><img src="tutorial_img/waveform.png" alt="Waveform"></div>
<h3>上圖:三條線分別是什麼</h3>
<table>
<tr><th>顏色</th><th>名稱</th><th>來源</th><th>意義</th></tr>
<tr><td><span class="tag blue">藍</span></td>
<td>Ideal PRBS (symbols)</td>
<td>已知的輸入 pattern <code>a[n]</code></td>
<td>完美方波,只有 {-3, -1, +1, +3} 四個值,<strong>沒有 ISI</strong></td></tr>
<tr><td><span class="tag red">紅</span></td>
<td>Measured (after channel)</td>
<td>ideal PRBS 通過 lossy channel 後的波形</td>
<td>有 ISI:level 之間的轉換變慢、振幅被壓縮、相鄰 symbol 互相干擾</td></tr>
<tr><td><span class="tag green">綠虛線</span></td>
<td>Fitted = conv(symbols, h)</td>
<td>ideal symbols 跟提取的 pulse response 做 convolution</td>
<td>如果 linear fit 正確,<strong>這條線應該跟紅線幾乎完全重疊</strong></td></tr>
</table>
<h3>下圖:Error = Measured − Fitted</h3>
<div class="fig-row"><div class="fig-note">
<p><strong>看什麼:</strong></p>
<ul>
<li><strong>幅度越小越好</strong>:RMS 值顯示在標題</li>
<li><strong>應該看起來像白噪音</strong>(隨機、無規律)</li>
<li>如果有低頻波動 → DC offset 沒 fit 好</li>
<li>如果有週期性 → tap 數量不夠</li>
</ul>
<div class="key">
<strong>判讀標準:</strong><br>
SNDR(meas vs fitted) 應該 ≈ 你設定的 noise SNR。<br>
例:noise SNR = 40 dB → 預期 SNDR ≈ 37~40 dB
</div>
</div></div>
</section>
<!-- ============================================================ -->
<!-- TAB 1b: WAVEFORM (OS) -->
<!-- ============================================================ -->
<section id="tab-waveform-os">
<h2>Tab 1b: Waveform (OS) — Oversampled 波形</h2>
<div class="fig-section"><img src="tutorial_img/waveform_os.png" alt="Waveform OS"></div>
<h3>看什麼</h3>
<table>
<tr><th>圖</th><th>內容</th><th>注意事項</th></tr>
<tr><td>上圖(藍)</td><td>Ideal PRBS (ZOH):完美方波,每個 symbol 維持 1 UI</td>
<td>Rise/fall 幾乎是瞬間的(1 sample = 1/64 UI)<br>只有 {-3,-1,+1,+3} 四個 level</td></tr>
<tr><td>下圖(紅)</td><td>Measured:通過 channel 後的類比波形</td>
<td>轉換變慢(rise time 增加)<br>振幅被壓縮<br>有 ISI(相鄰 symbol 互相干擾)<br>overshoot / ringing 可能出現</td></tr>
</table>
<div class="note">
<strong>跟 Tab 1 的差異:</strong>Tab 1 是 1 sample/UI(只看 sampling 點的值),
這裡是完整的 oversampled 波形(64 samp/UI),可以看到 transition 的完整形狀。
</div>
</section>
<!-- ============================================================ -->
<!-- TAB 2: EYE DIAGRAM -->
<!-- ============================================================ -->
<section id="tab-eye">
<h2>Tab 2: Eye Diagram — PAM4 眼圖</h2>
<div class="fig-section"><img src="tutorial_img/eye_diagram.png" alt="Eye Diagram"></div>
<h3>看什麼</h3>
<div class="fig-row"><div class="fig-note">
<table>
<tr><th>特徵</th><th>好的眼圖</th><th>差的眼圖</th></tr>
<tr><td>眼睛開口(垂直)</td><td>大、清晰的三個菱形開口</td><td>開口小或完全閉合</td></tr>
<tr><td>眼睛寬度(水平)</td><td>開口寬,佔大部分 UI</td><td>開口窄,只在中心一小段</td></tr>
<tr><td>Level 分離度</td><td>四個水平 level 清楚分開</td><td>level 模糊、重疊</td></tr>
<tr><td>Crossing 處的散佈</td><td>集中在同一個時間點</td><td>jitter 大 → 散佈寬</td></tr>
<tr><td>噪音</td><td>每個 level 附近的線條集中</td><td>線條粗、散開</td></tr>
</table>
</div></div>
<h3>繪製方式</h3>
<ol>
<li>用 CDR 找到最佳 sampling phase</li>
<li>把 oversampled 波形摺疊成 2 UI 為一段</li>
<li>Cubic 插值到 128 pts/UI(讓曲線平滑)</li>
<li>疊在一起畫成 2D density heatmap(白底)</li>
<li>顏色越深 = 那個位置通過的 trace 越多</li>
</ol>
<div class="note">
<strong>PAM4 有 3 個 eye:</strong> 在 level -3/-1、-1/+1、+1/+3 之間各有一個菱形開口。<br>
Channel loss 越大 → 眼睛越閉合。ISI 讓不同 symbol transition 的軌跡分散開來。
</div>
</section>
<!-- ============================================================ -->
<!-- TAB 3: PULSE RESPONSE -->
<!-- ============================================================ -->
<section id="tab-pulse">
<h2>Tab 3: Pulse Response — 提取的脈衝響應</h2>
<div class="fig-section"><img src="tutorial_img/pulse_response.png" alt="Pulse Response"></div>
<h3>上圖:Extracted vs True</h3>
<div class="fig-row"><div class="fig-note">
<table>
<tr><th>顏色</th><th>名稱</th><th>來源</th></tr>
<tr><td><span class="tag blue">藍 ●</span></td><td>Extracted</td><td>Linear fit 解出來的 h[k]</td></tr>
<tr><td><span class="tag green">綠 ■</span></td><td>True (impulse test)</td><td>Ground truth:送 impulse 通過同樣 channel 得到的真實 pulse</td></tr>
</table>
<p><strong>看什麼:</strong>兩組點應該<strong>完全重疊</strong>。如果重疊 = linear fit 正確。</p>
</div></div>
<h3>每個 tap 的物理意義</h3>
<div class="eq">
y[n] = h[0]·a[n] + h[1]·a[n-1] + h[2]·a[n-2] + ⋯
</div>
<table>
<tr><th>Tap</th><th>名稱</th><th>意義</th><th>理想值</th></tr>
<tr><td>h[cursor]</td><td><strong>Main cursor</strong></td><td>當前 symbol 對 output 的貢獻(最大的 tap)</td><td>趨近 1.0(無 loss)</td></tr>
<tr><td>h[cursor−1], h[cursor−2]</td><td>Pre-cursor</td><td>未來 symbol 對當前 output 的干擾</td><td>趨近 0(無 ISI)</td></tr>
<tr><td>h[cursor+1], h[cursor+2], ...</td><td>Post-cursor</td><td>過去 symbol 對當前 output 的干擾</td><td>趨近 0(無 ISI)</td></tr>
</table>
<div class="warn">
<strong>Pre/post cursor 越大 = ISI 越嚴重。</strong><br>
Channel loss 越大 → cursor 變小、pre/post cursor 變大 → 眼圖越閉合。
</div>
<h3>下圖:Extraction Error</h3>
<p>每個 tap 的 extracted − true 差值。RMS 值越小代表提取越準確。</p>
<p>典型值:RMS < 0.001 表示提取非常準確。</p>
</section>
<!-- ============================================================ -->
<!-- TAB 3b: STEP RESPONSE -->
<!-- ============================================================ -->
<section id="tab-step">
<h2>Tab 3b: Step Response — 階躍響應</h2>
<div class="fig-section"><img src="tutorial_img/step_response.png" alt="Step Response"></div>
<h3>Step Response 是什麼</h3>
<div class="eq">step[n] = Σ<sub>k=0</sub><sup>n</sup> h[k] = cumsum(pulse response)</div>
<p>就是 pulse response 的<strong>累積和</strong>。物理意義:如果輸入一個 step(從 0 跳到 1),輸出的波形就是 step response。</p>
<h3>看什麼</h3>
<table>
<tr><th>特徵</th><th>意義</th></tr>
<tr><td>Final value</td><td>系統的 DC gain。理想值 = 1.0(無 loss 時 pulse response 總和 = 1)</td></tr>
<tr><td>50% point(紫星)</td><td>上升到一半所需的 tap 數,反映 channel 的 group delay</td></tr>
<tr><td>上升斜率</td><td>越陡 = channel bandwidth 越大,transition 越快</td></tr>
<tr><td>收斂速度</td><td>多少 tap 後趨於穩定?越慢 = ISI 越嚴重,需要更多 tap</td></tr>
<tr><td>Overshoot / ringing</td><td>超越 final value 再回來 = channel 有 peaking</td></tr>
</table>
<div class="note">
<strong>在 SI 分析中:</strong>Step response 常用來判斷 channel 的 rise time 和 settling behavior。
如果 step response 收斂太慢 → equalizer 需要更多 tap 來補償。
</div>
</section>
<!-- ============================================================ -->
<!-- TAB 4: AC RESPONSE -->
<!-- ============================================================ -->
<section id="tab-ac">
<h2>Tab 4: AC Response — 頻率響應</h2>
<div class="fig-section"><img src="tutorial_img/ac_response.png" alt="AC Response"></div>
<h3>三條線分別代表什麼</h3>
<table>
<tr><th>顏色</th><th>名稱</th><th>計算方式</th><th>包含什麼</th></tr>
<tr><td><span class="tag blue">藍 實線</span></td>
<td>Extracted |G(f)|</td>
<td><code>FFT(h_extracted)</code></td>
<td>Channel + ZOH sinc + Aliasing<br>= 1 sps 系統的實際頻率響應</td></tr>
<tr><td><span class="tag green">綠 虛線</span></td>
<td>True pulse</td>
<td><code>FFT(impulse test result)</code></td>
<td>同上(ground truth)</td></tr>
<tr><td><span class="tag red">紅 點線</span></td>
<td>Pure channel H(f)</td>
<td>直接從你的 IL 設定計算</td>
<td>只有 Channel<br>(不含 sinc 和 aliasing)</td></tr>
</table>
<h3>如何判讀</h3>
<div class="key">
<ul>
<li><strong>藍線和綠線重疊</strong> → linear fit 正確!</li>
<li><strong>紅線跟藍/綠不同</strong> → 正常!紅線是純 channel,藍/綠包含 ZOH sinc 和 aliasing</li>
</ul>
</div>
<h3>為什麼 Extracted ≠ Pure Channel?</h3>
<p>信號從 ideal PRBS 到 1 sps 量測波形,經過三個處理:</p>
<div class="flow">
<div class="box">ZOH<br><small>sinc(f) 衰減</small></div><span class="arrow">×</span>
<div class="box orange">Channel<br><small>H(f) loss</small></div><span class="arrow">→ 降採樣 →</span>
<div class="box red">Aliasing<br><small>高頻摺疊</small></div>
</div>
<table>
<tr><th>效果</th><th>@ Nyquist</th><th>說明</th></tr>
<tr><td>(A) 純 Channel</td><td>-10.0 dB</td><td>你設定的</td></tr>
<tr><td>(B) ZOH sinc</td><td>-3.9 dB</td><td>sinc(0.5) = 2/π ≈ 0.637</td></tr>
<tr><td>(C) = A + B</td><td>-13.9 dB</td><td>無 aliasing 的預期值</td></tr>
<tr><td>(D) 含 Aliasing</td><td>~-8 dB</td><td>旁瓣能量摺疊回來 → loss 變少</td></tr>
</table>
<div class="eq">
G(f) = Σ<sub>k=−∞</sub><sup>∞</sup> sinc(f + k·f<sub>baud</sub>) × H<sub>ch</sub>(f + k·f<sub>baud</sub>)
</div>
<p>k=0 是主要項,k≠0 是 aliasing。sinc 的旁瓣 (sidelobes) 在 1.5×, 2.5× f<sub>baud</sub> 處非零,
乘上 channel 後摺疊回基帶。</p>
<pre><code>頻率 (× f_baud) |sinc| 說明
0.0 1.000 DC
0.5 (Nyquist) 0.637 主瓣邊緣
1.0 0.000 零點
1.5 0.212 第1旁瓣 → 摺疊回來!
2.0 0.000 零點
2.5 0.127 第2旁瓣 → 也摺疊回來!</code></pre>
</section>
<!-- ============================================================ -->
<!-- TAB 5: LINEAR FIT -->
<!-- ============================================================ -->
<section id="tab-linfit">
<h2>Tab 5: Linear Fit — 六張子圖完整解讀</h2>
<div class="fig-section"><img src="tutorial_img/linear_fit.png" alt="Linear Fit"></div>
<!-- PANEL 1 -->
<h3>子圖 (1):Matrix A 熱力圖</h3>
<div class="fig-row"><div class="fig-note">
<p><strong>是什麼:</strong>矩陣 A 的前 50 行,用顏色表示每個元素的值。</p>
<ul>
<li><span style="color:#b91c1c;font-weight:700;">紅 = +3</span>、
<span style="color:#f97316;font-weight:700;">淡紅 = +1</span>、
<span style="color:#3b82f6;font-weight:700;">淡藍 = −1</span>、
<span style="color:#1e3a8a;font-weight:700;">深藍 = −3</span></li>
<li>X 軸 = column k = tap index</li>
<li>Y 軸 = row = output sample index</li>
</ul>
<p><strong>為什麼是斜條紋:</strong>每一行是上一行往右 shift 一格 → Toeplitz 結構。</p>
<div class="eq">
A[i, k] = a[n<sub>i</sub> − k]
</div>
<pre><code>Row i : [a[n], a[n-1], ..., a[n-L+1]]
Row i+1: [a[n+1], a[n], ..., a[n-L+2]]
↑ 整列右移一格</code></pre>
<p><strong>看什麼:</strong></p>
<ul>
<li>斜條紋清晰 → 結構正確</li>
<li>顏色隨機分布 → PRBS pattern 有良好隨機性</li>
<li>如果出現大面積同色塊 → pattern 有長串重複 → cond# 會變差</li>
</ul>
</div></div>
<!-- PANEL 2 -->
<h3>子圖 (2):一行範例</h3>
<div class="fig-row"><div class="fig-note">
<p><strong>是什麼:</strong>從矩陣 A 中取出一行(例如 n=2057),畫成 bar chart。</p>
<p>每個 bar 的高度是 <code>a[n-k]</code> 的值。</p>
<p><strong>數學意義:</strong>這一行代表一條方程式:</p>
<div class="eq" style="font-size:.95em;">
y[2057] = h[0]×<span style="color:#b91c1c;">a[2057]</span>
+ h[1]×<span style="color:#b91c1c;">a[2056]</span>
+ …
+ h[30]×<span style="color:#b91c1c;">a[2027]</span>
</div>
<p>Bar chart 顯示的是<span style="color:#b91c1c;">紅色部分</span>(已知的 symbol 值)。
<span style="color:#1d4ed8;">h[k]</span> 是我們要求的未知數。</p>
<p><strong>看什麼:</strong>值域應該只有 {-3, -1, +1, +3},分布接近隨機。</p>
</div></div>
<!-- PANEL 3 -->
<h3>子圖 (3):y vs A·h — 量測值 vs 擬合值</h3>
<div class="fig-row"><div class="fig-note">
<table>
<tr><th>線</th><th>代表</th></tr>
<tr><td><span class="tag blue">藍</span> y</td><td>量測波形(真實值)</td></tr>
<tr><td><span class="tag red">紅虛線</span> A·h+dc</td><td>模型預測值 = 矩陣 A 乘以解出的 h,再加 DC offset</td></tr>
</table>
<p><strong>看什麼:兩條線越重疊越好。</strong></p>
<ul>
<li>完全重疊 → 模型完美解釋數據</li>
<li>系統性偏移 → 需要 fit DC offset</li>
<li>某些區域偏差大 → tap 不夠或非線性</li>
</ul>
<p><strong>對應的數學量:</strong></p>
<div class="eq">
R² = 1 − Σ(y − ŷ)² / Σ(y − ȳ)²
</div>
<table>
<tr><th>R²</th><th>意義</th></tr>
<tr><td>0.9999</td><td>非常好:99.99% 的 variance 被解釋</td></tr>
<tr><td>0.999</td><td>好:可能 tap 不夠或 noise 較大</td></tr>
<tr><td>< 0.99</td><td>需要檢查 alignment、tap 數量、或非線性問題</td></tr>
</table>
</div></div>
<!-- PANEL 4 -->
<h3>子圖 (4):Residual = y − A·h</h3>
<div class="fig-row"><div class="fig-note">
<p><strong>是什麼:</strong>上面圖 (3) 兩條線之間的差值。</p>
<div class="eq">e[n] = y[n] − ŷ[n] = y[n] − (A·ĥ + dc)</div>
<ul>
<li>綠色曲線 = 每個 sample 的 error</li>
<li>橘色虛線 = ±RMS 邊界</li>
</ul>
<p><strong>看什麼:</strong></p>
<ul>
<li><callout>應該像白噪音</callout>(隨機、無結構)</li>
<li>如果有週期性 → channel impulse response 比 L taps 更長 → <strong>增加 tap 數量</strong></li>
<li>如果有低頻飄移 → 啟用 DC offset fitting</li>
<li>如果 amplitude 隨時間變化 → 系統不穩定</li>
</ul>
<p><strong>SNDR 計算:</strong></p>
<div class="eq">
SNDR = 10 · log<sub>10</sub>( mean(y²) / mean(e²) )
</div>
</div></div>
<!-- PANEL 5 -->
<h3>子圖 (5):SVD of A — 奇異值</h3>
<div class="fig-row"><div class="fig-note">
<p><strong>是什麼:</strong>矩陣 A 的所有奇異值 σ<sub>i</sub>,由 SVD 分解得到。</p>
<div class="eq">A = U · Σ · V<sup>T</sup></div>
<p><strong>看什麼:</strong></p>
<ul>
<li><callout>奇異值越 flat(平坦)越好</callout></li>
<li>Flat = 所有方向的信息量均衡 = well-conditioned = 解穩定</li>
<li>如果有驟降 → 那些方向的 h[k] 難以確定 → ill-conditioned</li>
</ul>
<p><strong>Condition number:</strong></p>
<div class="eq">
cond(A) = σ<sub>max</sub> / σ<sub>min</sub>
</div>
<table>
<tr><th>Cond #</th><th>意義</th></tr>
<tr><td>1 ~ 3</td><td>非常好(PRBS 典型值 ≈ 2.2)</td></tr>
<tr><td>10 ~ 100</td><td>勉強可以</td></tr>
<tr><td>> 1000</td><td>不可靠,需要 regularization 或換 pattern</td></tr>
</table>
<p><strong>為什麼 PRBS 的 cond# 低?</strong></p>
<pre><code>A<sup>T</sup>A 的元素 [i,j] = N · R<sub>aa</sub>[i-j]
= symbols 的自相關
PRBS autocorrelation:
R[0] = E[a²] = 5.0 (PAM4 平均功率)
R[k≠0] ≈ 0 (偽隨機 ≈ 白噪音)
→ A<sup>T</sup>A ≈ 5N · I (常數 × 單位矩陣)
→ 所有 σ<sub>i</sub> ≈ √(5N)
→ cond ≈ 1</code></pre>
</div></div>
<!-- PANEL 6 -->
<h3>子圖 (6):Summary 文字</h3>
<div class="fig-row"><div class="fig-note">
<p>右下角的文字框總結整個 linear fit 的結果:</p>
<ul>
<li><strong>Model</strong>:使用的數學模型</li>
<li><strong>A 的大小</strong>:N × L = 方程式數 × 未知數</li>
<li><strong>Rank</strong>:= L 表示所有 tap 都可被唯一確定</li>
<li><strong>Cond#</strong>:condition number</li>
<li><strong>Verify row</strong>:代回一行驗算,確認 Σ h[k]·a[n-k] ≈ y[n]</li>
<li><strong>R²、SNDR</strong>:最終擬合品質</li>
</ul>
</div></div>
<!-- CONFIDENCE INTERVAL -->
<h3>Confidence Interval(信賴區間)</h3>
<p>在 Pulse Response 圖上,每個 tap 周圍的<strong>淡藍色陰影</strong>是 95% confidence interval。</p>
<div class="eq">
Cov(ĥ) = σ² · (A<sup>T</sup>A)<sup>−1</sup>
</div>
<p>其中 σ² = SS<sub>res</sub> / (N − L) 是 noise variance 的估計值。</p>
<p>每個 tap 的標準差:<code>std(h[k]) = sqrt( Cov[k,k] )</code></p>
<p>95% CI = <code>h[k] ± 1.96 × std(h[k])</code></p>
<table>
<tr><th>看什麼</th><th>意義</th></tr>
<tr><td>CI 很窄</td><td>該 tap 的值很確定(精度高)</td></tr>
<tr><td>CI 很寬</td><td>該 tap 的值不確定(可能被噪音主導)</td></tr>
<tr><td>relative CI < 1%</td><td>非常可靠</td></tr>
<tr><td>relative CI > 50%</td><td>該 tap 基本上是噪音,不具物理意義</td></tr>
</table>
<div class="note">
<strong>PRBS 的優勢:</strong>因為 A<sup>T</sup>A ≈ 5N·I,所以
Cov(ĥ) ≈ (σ²/5N)·I,每個 tap 的 CI 都一樣寬(均勻可靠)。
如果用非 PRBS pattern,某些 tap 的 CI 可能比其他的寬很多。
</div>
<!-- SIX PANELS STORY -->
<h3>六張圖的邏輯串連</h3>
<div class="key">
<ol>
<li><strong>圖(1)</strong>:我們建了什麼方程組?→ Toeplitz 矩陣,每行是 symbols 的 shift</li>
<li><strong>圖(2)</strong>:一條方程式長什麼樣?→ h[k] 乘上哪些 symbol 值</li>
<li><strong>圖(3)</strong>:解出來準嗎?→ y vs A·h 越重疊越好</li>
<li><strong>圖(4)</strong>:不準的部分長什麼樣?→ 殘差應該是白噪音</li>
<li><strong>圖(5)</strong>:方程組穩定嗎?→ flat SVD = 穩定</li>
<li><strong>圖(6)</strong>:所有數字一覽</li>
</ol>
</div>
</section>
<!-- ============================================================ -->
<!-- TAB 6: HISTOGRAM -->
<!-- ============================================================ -->
<section id="tab-hist">
<h2>Tab 6: Histogram — Level 分佈</h2>
<div class="fig-section"><img src="tutorial_img/histogram.png" alt="Histogram"></div>
<h3>看什麼</h3>
<div class="fig-row"><div class="fig-note">
<table>
<tr><th>顏色</th><th>代表</th></tr>
<tr><td><span style="color:#e74c3c;">■</span> 紅</td><td>被 classify 到 Level −3 的 samples</td></tr>
<tr><td><span style="color:#e67e22;">■</span> 橘</td><td>Level −1</td></tr>
<tr><td><span style="color:#2ecc71;">■</span> 綠</td><td>Level +1</td></tr>
<tr><td><span style="color:#3498db;">■</span> 藍</td><td>Level +3</td></tr>
<tr><td>灰色虛線</td><td>估計的四個 level 中心位置</td></tr>
</table>
<p><strong>看什麼:</strong></p>
<ul>
<li><callout>四個分佈應該清楚分開</callout>(不重疊)</li>
<li>各分佈的寬度 = noise + ISI 造成的散佈</li>
<li>Level 間距應該均等 → RLM ≈ 1.0</li>
<li>分佈形狀應接近 Gaussian(中央極限定理)</li>
</ul>
<p><strong>RLM (Ratio Level Mismatch):</strong></p>
<div class="eq">
RLM = 3 × min(ΔV<sub>01</sub>, ΔV<sub>12</sub>, ΔV<sub>23</sub>) / V<sub>swing</sub>
</div>
<p>理想 = 1.0。< 0.9 表示 level 間距不均,可能是非線性問題。</p>
<p><strong>如果分佈重疊嚴重:</strong></p>
<ul>
<li>Channel loss 太大 → level 被壓縮</li>
<li>Noise 太大 → 每個 level 的散佈太寬</li>
<li>→ BER 會很高</li>
</ul>
</div></div>
</section>
<!-- ============================================================ -->
<!-- MATH DEEP DIVE -->
<!-- ============================================================ -->
<section id="math">
<h2>數學推導</h2>
<h3>A. 從摺積到矩陣方程</h3>
<p>量測信號是 symbols 和 channel pulse 的摺積:</p>
<div class="eq">
y[n] = (a * h)[n] = Σ<sub>k=0</sub><sup>L-1</sup> h[k] · a[n−k]
</div>
<p>寫成矩陣形式:y = A · h,其中 A 是 Toeplitz 矩陣。</p>
<p>如果有 N 個 output samples 和 L 個 taps:A 是 N×L,方程組是<strong>超定的</strong>(N >> L)。</p>
<h3>B. Least Squares 求解</h3>
<div class="eq">
ĥ = argmin<sub>h</sub> ‖ y − A·h ‖²
</div>
<p><strong>Normal Equation:</strong></p>
<div class="eq">
A<sup>T</sup>A · ĥ = A<sup>T</sup>y  ⟹  ĥ = (A<sup>T</sup>A)<sup>−1</sup> A<sup>T</sup>y
</div>
<p><strong>幾何意義:</strong>把 y 投影到 A 的 column space 上。殘差 e = y − Aĥ 垂直於 column space:</p>
<div class="eq">A<sup>T</sup> · e = 0</div>
<h3>C. SVD 解法(數值穩定)</h3>
<pre><code>A = U · Σ · V<sup>T</sup>
ĥ = V · Σ<sup>−1</sup> · U<sup>T</sup> · y
其中 Σ<sup>−1</sup> = diag(1/σ₁, 1/σ₂, ..., 1/σ_L)
如果 σ_k 很小 → 1/σ_k 很大 → 放大噪音 → 解不穩定
如果所有 σ_k 差不多大(PRBS 的情況)→ 解非常穩定</code></pre>
<h3>D. Regularization(正則化)</h3>
<p>當 cond# 過大時,加 Tikhonov regularization:</p>
<div class="eq">
ĥ = (A<sup>T</sup>A + λI)<sup>−1</sup> A<sup>T</sup>y
</div>
<p>λ > 0 防止 1/σ<sub>k</sub> 爆掉,代價是引入少量 bias。對 PRBS 通常不需要。</p>
<h3>E. PRBS 為什麼適合做 Linear Fit</h3>
<pre><code>PRBS 的自相關:R[τ] = E[a[n]·a[n+τ]]
PAM4 ({-3,-1,+1,+3}) 的統計:
E[a] = 0 (均值為零)
E[a²] = (9+1+1+9)/4 = 5.0 (功率 = 5)
R[0] = 5.0
R[τ≠0] ≈ 0 (偽隨機序列近似白噪音)
→ A<sup>T</sup>A ≈ 5N · I (5N 倍的單位矩陣)
→ (A<sup>T</sup>A)<sup>−1</sup> ≈ (1/5N) · I
→ ĥ ≈ (1/5N) · A<sup>T</sup>y (類似 matched filter)
→ Condition number ≈ 1 (理想情況)</code></pre>
</section>
<!-- ============================================================ -->
<!-- FAQ -->
<!-- ============================================================ -->
<section id="faq">
<h2>常見問題 FAQ</h2>
<h3>Q1: Tap 數量要設多少?</h3>
<p>取決於 channel 的 impulse response 長度:</p>
<table>
<tr><th>Channel 類型</th><th>建議 taps</th></tr>
<tr><td>Short reach(< 5 dB loss)</td><td>11 ~ 21</td></tr>
<tr><td>Medium reach(5-15 dB)</td><td>21 ~ 41</td></tr>
<tr><td>Long reach(> 15 dB)</td><td>41 ~ 101</td></tr>
</table>
<p><strong>判斷方法:</strong>跑一次後看 residual,如果有週期性結構就增加 tap 數。
或看 step response 是否已經收斂到 final value。</p>
<h3>Q2: R² 很低怎麼辦?</h3>
<ol>
<li>增加 tap 數量(channel 可能有長尾)</li>
<li>檢查 alignment(lag 是否合理)</li>
<li>檢查 CDR phase(相位是否最佳)</li>
<li>啟用 DC offset fitting</li>
<li>如果以上都做了還是低 → 系統可能有非線性(此工具假設線性)</li>
</ol>
<h3>Q3: 眼圖完全閉合怎麼辦?</h3>
<p>眼圖閉合代表 channel loss 太大,不代表 linear fit 有問題。嘗試:</p>
<ul>
<li>降低 channel IL(例如 -5 dB)</li>
<li>降低 noise(增加 SNR)</li>
<li>在實際系統中:需要 equalization (CTLE/DFE/FFE)</li>
</ul>
<h3>Q4: SNDR 比設定的 noise SNR 低很多?</h3>
<ul>
<li>Tap 不夠 → channel 的 tail 沒有被完整 capture</li>
<li>Circular convolution artifact → 波形開頭和結尾的 edge effect</li>
<li>Alignment 不準 → 部分 symbol 對應錯誤</li>
</ul>
<h3>Q5: 為什麼提取的 IL 跟設定的不一樣?</h3>
<p>因為提取的 pulse response 是在 1 sps 下的<strong>等效響應</strong>,包含:</p>
<ul>
<li>ZOH sinc 衰減(在 Nyquist 約 -3.9 dB)</li>
<li>降採樣的 aliasing(sinc 旁瓣能量摺疊回來)</li>
</ul>
<p>→ 看 AC Response 圖的藍線和綠線是否重疊。如果重疊,提取就是正確的。</p>
</section>
<!-- ============================================================ -->
<!-- CHANNEL COMPARISON -->
<!-- ============================================================ -->
<section id="channel-cmp">
<h2>Channel Loss 模型比較</h2>
<table>
<tr><th>模型</th><th>公式</th><th>物理來源</th><th>適用場景</th></tr>
<tr><td><strong>Linear</strong></td>
<td>IL(f) = IL<sub>nyq</sub> × f/f<sub>nyq</sub></td>
<td>簡化模型</td>
<td>快速模擬、初步估算</td></tr>
<tr><td><strong>Sqrt (skin effect)</strong></td>
<td>IL(f) = IL<sub>nyq</sub> × √(f/f<sub>nyq</sub>)</td>
<td>導體中的集膚效應:電流集中在導體表面,電阻 ∝ √f</td>
<td>中短距離 PCB trace</td></tr>
<tr><td><strong>a√f + bf</strong></td>
<td>IL(f) = a√f + b·f</td>
<td>a = skin effect,b = dielectric loss</td>
<td>完整 PCB/cable 模型</td></tr>
<tr><td><strong>S-parameter</strong></td>
<td>從 .s4p 檔案讀取</td>
<td>實測或 EM 模擬</td>
<td>最精確,真實系統</td></tr>
</table>
<div class="note">
<strong>本工具目前支援 linear 和 sqrt。</strong>
a√f + bf 和 S-parameter 在未來版本加入。
</div>
<h3>同一 IL@Nyquist 下不同模型的差異</h3>
<pre><code>例:IL@Nyquist = -10 dB,f_nyq = 14 GHz
頻率 Linear Sqrt 差異
───── ────── ────── ────
2 GHz -1.4 dB -3.8 dB sqrt 在低頻衰減更多
7 GHz -5.0 dB -7.1 dB
14 GHz -10.0 dB -10.0 dB 定義點,相同
→ sqrt 模型的 loss 集中在低頻(skin effect 特性)
→ linear 模型的 loss 均勻分佈在所有頻率</code></pre>
</section>
<!-- ============================================================ -->
<!-- PRBS COMPARISON -->
<!-- ============================================================ -->
<section id="prbs-cmp">
<h2>PRBS Pattern 比較</h2>
<table>
<tr><th>Pattern</th><th>Polynomial</th><th>Period</th><th>適合的 channel 長度</th></tr>
<tr><td>PRBS7</td><td>x<sup>7</sup>+x<sup>6</sup>+1</td><td>127</td><td>短 channel(< 10 tap)</td></tr>
<tr><td><strong>PRBS9</strong></td><td>x<sup>9</sup>+x<sup>5</sup>+1</td><td>511</td><td>中等 channel</td></tr>
<tr><td>PRBS13</td><td>x<sup>13</sup>+x<sup>12</sup>+x<sup>2</sup>+x+1</td><td>8191</td><td>長 channel</td></tr>
<tr><td>PRBS15</td><td>x<sup>15</sup>+x<sup>14</sup>+1</td><td>32767</td><td>很長的 channel</td></tr>
<tr><td>PRBS31</td><td>x<sup>31</sup>+x<sup>28</sup>+1</td><td>2.1×10<sup>9</sup></td><td>BER 測試用</td></tr>
</table>
<h3>PAM4 的 Quaternary PRBS</h3>
<table>
<tr><th>Pattern</th><th>做法</th><th>用途</th></tr>
<tr><td><strong>PRBSQ9</strong></td>
<td>兩個 decorrelated PRBS9 組成 MSB/LSB</td>
<td>PAM4 linear fit(4 level 都有覆蓋)</td></tr>
<tr><td>PRBS9 pairs</td>
<td>一個 PRBS9 取連續 2 bit 為一組</td>
<td>替代方案,但 level 分佈可能不均</td></tr>
</table>
<h3>Pattern 長度對 Linear Fit 的影響</h3>
<pre><code>Pattern 越長:
✓ 方程式越多(N 越大)→ 統計上越可靠
✓ autocorrelation 越接近 delta → cond# 越低
✓ 對長 channel 的 tail 也能 capture
✗ 計算時間增加(矩陣更大)
✗ 記憶體用量增加
建議:
N (symbols) >= 10 × L (taps) 以上
例:L = 31 taps → 至少 310 symbols → 1 個 PRBS9 period (511) 就夠
L = 101 taps → 至少 1010 symbols → 用 2~4 個 period</code></pre>
</section>
<!-- ============================================================ -->
<!-- GUI GUIDE -->
<!-- ============================================================ -->
<section id="gui">
<h2>GUI 操作指南</h2>
<h3>啟動</h3>
<pre><code>python gui.py</code></pre>
<h3>滑鼠操作(所有圖表通用)</h3>
<table>
<tr><th>操作</th><th>效果</th></tr>
<tr><td>滾輪上 / 下</td><td>以游標為中心放大 / 縮小</td></tr>
<tr><td>右鍵拖曳</td><td>框選區域放大</td></tr>
<tr><td>右鍵雙擊</td><td>重置到原始比例</td></tr>
</table>
<h3>驗證 Checklist</h3>
<table>
<tr><th>項目</th><th>預期</th><th>不符時的處理</th></tr>
<tr><td>R²</td><td>≥ 0.999</td><td>增加 tap 數量或檢查 alignment</td></tr>
<tr><td>SNDR (fit)</td><td>≈ noise SNR</td><td>模型不足或有非線性</td></tr>
<tr><td>Fitted vs Measured</td><td>幾乎重疊</td><td>tap 不夠或 pattern 太短</td></tr>
<tr><td>Pulse: 藍 vs 綠</td><td>完全重疊</td><td>linear fit 有問題</td></tr>
<tr><td>AC: 藍 vs 綠</td><td>完全重疊</td><td>頻域驗證有問題</td></tr>
<tr><td>Condition #</td><td>≈ 2</td><td>pattern 不夠隨機</td></tr>
<tr><td>Residual</td><td>白噪音狀</td><td>有結構 → 增加 taps</td></tr>
</table>
</section>
</div>
<footer>PAM4 SerDes TX Linear Fit Framework — numpy / scipy / matplotlib</footer>
</body>
</html>