假币称重:汉明纠错码的应用

假币称重:汉明纠错码的应用

这是一道经典的信息论题目,存在不唯一的最优解。大部分参考书中似乎都没有给出一般性(任意数量的假币)的解决方案,本模型的结果正确性有待考究。
完整代码查看 github

问题描述

设有 n ​ n​ n 枚硬币,其中仅有一枚假币,在已知或未知假币与真比之间重量关系两种情况下 ,通过无砝码天平称重的方法鉴别假币,求所需的最少称重次数。要求:

  1. 试用信息论的原理进行分析,并给出 n = 12 , 39 ​ n=12,39​ n=12,39 的具体称重策略;
  2. 编程实现可视化。

emmm,这里的可视化是指用图表表示出称重策略就好了还是要画出天平,托盘呢 ?

称重次数下界

使用无砝码天平进行称重只可能有三种结果(左盘重,等重,右盘重)。则每称重一次最多可以获得(等概情形)的信息量为

I = log ⁡ 2 3 bits I = \log_23 \quad \text{bits} I=log23bits

假设所有硬币中出现假币是等可能的,若已知假币较真币要轻,则对于硬币来说一共有 n + 1 n +1 n+1 种可能状态,即其中某一个硬币较轻或者它们一样重。此时的熵为 log ⁡ 2 ( n + 1 ) ​ \log_2(n+1)​ log2(n+1) ,则通过称重的方式获知哪一块是假币需要的次数

k ≥ log ⁡ 2 ( n + 1 ) log ⁡ 2 3 = log ⁡ 3 ( n + 1 ) k \ge \frac{\log_2(n+1)}{\log_23} = \log_3(n+1) klog23log2(n+1)=log3(n+1)

而若事先不知道假币是轻还是重,则一共有 2 n + 1 2n+1 2n+1 种状态,此时最少称重次数为

k min ⁡ = ⌈ log ⁡ 3 ( 2 n + 1 ) ⌉ k_{\min} =\lceil \log_3(2n+1) \rceil kmin=log3(2n+1)

其中 ⌈ ⋅ ⌉ \lceil \cdot \rceil 为向上取整符号。下图给出了是否已知假币轻重对称重次数下界的影响。

由图可知已知假币与真币轻重关系在大部分情况下具有更低的称重次数下界。但是一般情况下应该不知道假币与真币轻重关系,下面主要讨论这种情形。

事实上已知轻重时可以用类似下面的方法给出最优策略,但是为达到称重次数下界需要的搜索量似乎更大

以上确定了称重次数的下界,但是如何设置称重策略来达到这个下界呢?下面参考信号纠错的思想构造性的给出一种最优策略 。

汉明纠错码

汉明纠错码是一种线性分组码,可以用来恢复特定情况下某一位发生变异的信号 。而唯一的假币正是相当于发生了变异的真币。而且汉明码是完备码,它在于分组长度相同、最小距离为 3 的码中能达到最高的码率。

  1. 编码的距离一般只两个编码不同元素的最大个数

  2. Todd K Moon. Error correction coding. Mathematical Methods and Algorithms. Jhon Wiley and Son, pages 2001–2006, 2005.

汉明码纠错主要应用了线性变换的零空间概念

已本题为例,取硬币为 12 枚,只需要称三次便可以找到假币。而长度为 3 的码要表示 12 种以上数字至少是 3 进制。故而可对 1-12 号硬币进行如下编码

H = [ 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 2 2 2 0 0 0 1 1 2 0 1 2 0 1 2 0 1 2 0 ] H=\left[ \begin{array}{llllllllllll}{0} & {0} & {0} & {0} & {0} & {0} & {0} & {0} & {1} & {1} & {1} & {1} \\ {0} & {0} & {1} & {1} & {1} & {2} & {2} & {2} & {0} & {0} & {0} & {1} \\ {1} & {2} & {0} & {1} & {2} & {0} & {1} & {2} & {0} & {1} & {2} & {0}\end{array}\right] H=001002010011012020021022100101102110

其中 H H H 通常称为奇偶校验矩阵(parity check matrix)。易知矩阵 H H H 的秩 r a n k ( H ) = 3 rank(H) = 3 rank(H)=3(即这种编码的最大汉明距离也为 3),从而其零空间的维度为

dim ⁡ ( K e r ( H ) ) = 12 − r a n k ( H ) = 9 \dim (Ker(H)) = 12 - rank(H) = 9 dim(Ker(H))=12rank(H)=9

这意味着存在 2 9 2^9 29 12 × 1 12 \times 1 12×1 的向量 c \mathbf{c} c 使得

H c = 0 \mathbf{H}\mathbf{c} = 0 Hc=0

这些所有的向量 c \mathbf{c} c 便可以作为信息发送出去,而且若其中某一个位置上元素发生了改变可以通过以下途径快速辨识出是哪个位置发生了错误:

设发出信息为 c \mathbf{c} c c \mathbf{c} c 必须属于 H H H 的零空间),而位置 i i i 发生了变异(对应本题中的假币序号),收到的信息为 r = c + e i \mathbf{r} = \mathbf{c} + \mathbf{e}_i r=c+ei,其中 e i \mathbf{e}_i ei 表示仅第 i i i 个位置为 1 ,其余地方为零。从而

H r = H ( c + e i ) = H e i \mathbf{H} \mathbf{r} = \mathbf{H}(\mathbf{c} + \mathbf{e}_i) = \mathbf{H} \mathbf{e}_i Hr=H(c+ei)=Hei

H e i \mathbf{H}\mathbf{e}_i Hei 表示矩阵 H H H 的第 i ​ i​ i 列。故而只需要对收到的信息做一次矩阵乘法再去矩阵内进行匹配便可知道变异位置,从而找到假币。

假币称重最优策略

但是上述模型并不能直接应用过来,因为接受信息 r \mathbf{r} r 在这里并不能量化成假币的质量,我们只能通过天平比较不同数量的硬币质量。故而需对编码方式进行修改,将三进制的基改为 { − 1 , 0 , 1 } \{-1,0,1\} {1,0,1} ,则可以用 − 1 -1 1 表示将硬币放在左盘, 0 0 0 表示将硬币搁置一旁, 1 ​ 1​ 1 表示放在右盘。

c = ( 0 , 0 , ⋯   , 0 ) \mathbf{c} = (0,0,\cdots,0) c=(0,0,,0) (零向量必然属于 H \mathbf{H} H 的零空间)表示没有假币的情形,有假币则是在某一个位置将 0 变成 1(此时假币重) 或者 -1(此时假币轻)。编码后结果如下图所示。

将硬币编码为上述三进制的代码如下:

function y = ternary(num,length)
k = 3;
now = num;
for i=1:length-1
    if mod(now,3^i) / 3^(i-1)==2  % Equivalent to -1
        y(i) = -1 ;
    else
        y(i) = mod(now,3^i) / 3^(i-1);
    end
    now = now - y(i)*3^(i-1);
end
y(length) = now / 3^(length-1);
y = y';
end

但是使用天平必须左右摆放的硬币数目一致,故而需要使得上图中编码结果每一行的 -1 的数目等于 1 的数目,只需要将部分硬币的编码乘以 -1 即可(并不会改变矩阵的秩)。由于每一个硬币的编码都有可能被要求变为相反数,故而一共需要编码 2 n + 1 2n+1 2n+1 种状态,编码长度即 k = ⌈ log ⁡ 3 ( 2 n + 1 ) ⌉ ​ k = \lceil \log_3(2n+1) \rceil ​ k=log3(2n+1) 恰好达到称重次数的下界。

对上述编码进行调整的方案有很多,不同的方案可以得到不同的最优策略。亦即本问题的最优策略不唯一,对哪些硬币进行调整这是一个组合搜索问题,当硬币数较多时是 NP Hard 的,这里采用遗传算法进行搜索。损失函数定义如下

设变量 x i x_i xi 表示是否将第 i i i 号硬币的编码变为其相反数。设原来的编码矩阵为 R k × n R_{k \times n} Rk×n ,对于每一轮称重 -1 和 1的数目相等相当于编码的和为零。故而转化为一下优化问题

min ⁡ x ∑ j = 1 k ∑ i = 1 n x i R j i x i = − 1 , 1 i = 1 , 2 , ⋯   , n \min \limits_{\mathbf{x}} \quad\sum_{j=1}^k\sum_{i=1}^nx_iR_{ji} \\ x_i = -1,1\quad i=1,2,\cdots,n xminj=1ki=1nxiRjixi=1,1i=1,2,,n

遗传算法调整编码

39 枚硬币最优策略搜索过程示意如下图所示

!c400

其中12 枚硬币的一种调整方式如下图所示

加粗的编码表示较原先进行了调整。39 枚硬币的称重策略可视化为下图

其中黑色表示放在左盘,白色表示放在右盘。

确定假币位置与轻重

至此上述编码不仅符合汉明纠错码的性质,而且给出了硬币的称重策略。由汉明纠错码知假币位置可唯一确定。那如何判断轻重呢?每一次称重结果若为左盘重,记编码 -1,若两边等重,记编码 0 ,若左盘轻则记 1。最后将此编码反译为硬币编号,则对应编号的硬币为假币。并且若编码和原编码匹配,则说明假币较重;若为原编码的相反数,则说明假币较轻。比如最后得到 − 1 , 0 , − 1 ​ -1,0,-1​ 1,0,1 ,则假币为 − 1 × 3 0 + 0 × 3 2 − 1 × 3 2 = − 10 ​ -1 \times 3^0 + 0 \times 3^2 - 1 \times 3^2 = -10​ 1×30+0×321×32=10 ,即 10 号为假币,且得到的序列与上图中编码序列相同,故而10号为假币,且较真币更重。

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Error Correction Coding - Mathematical Methods and Algorithms (Source Files Contained).pdf Error Correction Coding Mathematical Methods and Algorithms Todd K. Moon Utah State University @ E ! C I E N C E A JOHN WILEY & SONS, INC., PUBLICATION Preface vii List of Program Files xxxi List of Laboratory Exercises XXXii List of Algorithms d V List of Figures XI List of Tables xlii List of Boxes Xliii Part I Introduction and Foundations 1 A Context for Error Correction Coding 2 1.1 F’urpose of This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 Introduction: Where Are Codes? . . . . . . . . . . . . . . . . . . . . . . . 2 1.3 The Communications System . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.4 Basic Digital Communications . . . . . . . . . . . . . . . . . . . . . . . . 9 1.4.1 Binary Phase-Shift Keying . . . . . . . . . . . . . . . . . . . . . . 10 1.4.2 More General Digital Modulation . . . . . . . . . . . . . . . . . . 11 1.5 Signal Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 1.5.1 The Gaussian Channel . . . . . . . . . . . . . . . . . . . . . . . . 14 1 S.2 MAP and ML Detection . . . . . . . . . . . . . . . . . . . . . . . 16 1.5.3 Special Case: Binary Detection . . . . . . . . . . . . . . . . . . . 18 1.5.4 Probability of Error for Binary Detection . . . . . . . . . . . . . . 19 1 S.5 Bounds on Performance: The Union Bound . . . . . . . . . . . . . 22 1.5.6 The Binary Symmetric Channel . . . . . . . . . . . . . . . . . . . 23 1 S.7 The BSC and the Gaussian Channel Model . . . . . . . . . . . . . 25 1.6 Memoryless Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 1.7 Simulation and Energy Considerations for Coded Signals . . . . . . . . . . 26 1.8 Some Important Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . 27 1.8.1 Detection of Repetition Codes Over a BSC . . . . . . . . . . . . . 28 Soft-Decision Decoding of Repetition Codes Over the AWGN 1.8.3 Simulation of Results . . . . . . . . . . . . . . . . . . . . . . . . . 33 1.8.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 1.9 HammingCodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 1.9.1 Hard-Input Decoding Hamming Codes . . . . . . . . . . . . . . . 35 1.9.2 Other Representations of the Hamming Code . . . . . . . . . . . . 36 An Algebraic Representation . . . . . . . . . . . . . . . . . . . . . 37 A Polynomial Representation . . . . . . . . . . . . . . . . . . . . 37 1 A Trellis Representation . . . . . . . . . . . . . . . . . . . . . . . 38 The Tanner Graph Representation . . . . . . . . . . . . . . . . . . 38 1.10 The Basic Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 1.12 A Bit of Information Theory . . . . . . . . . . . . . . . . . . . . . . . . . 40 1.12.1 Definitions for Discrete Random Variables . . . . . . . . . . . . . . 40 Entropy and Conditional Entropy . . . . . . . . . . . . . . . . . . 40 Relative Entropy. Mutual Information. and Channel Capacity . . . . 41 1.12.2 Definitions for Continuous Random Variables . . . . . . . . . . . . 43 1.12.3 The Channel Coding Theorem . . . . . . . . . . . . . . . . . . . . 45 1.12.4 “Proof“ of the Channel Coding Theorem . . . . . . . . . . . . . . . 45 1.12.5 Capacity for the Continuous-Time AWGN Channel . . . . . . . . . 49 1.12.6 Transmission at Capacity with Errors . . . . . . . . . . . . . . . . 51 1.12.7 The Implication of the Channel Coding Theorem . . . . . . . . . . 52 1.11 Historical Milestones of Coding Theory . . . . . . . . . . . . . . . . . . . 40 Lab 1 Simulating a Communications Channel . . . . . . . . . . . . . . . 53 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Use of Coding in Conjunction with the BSC . . . . . . . . . . . . . . . . . 53 Programming Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Resources and Implementation Suggestions . . . . . . . . . . . . . . . . . 54 1.13 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 1.14 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 Part I1 Block Codes 61 2 Groups and Vector Spaces 62 2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 2.2 Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 2.2.1 Subgroups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 2.2.2 Cyclic Groups and the Order of an Element . . . . . . . . . . . . . 66 2.2.3 Cosets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 2.2.4 Lagrange’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . . 68 2.2.5 Induced Operations; Isomorphism . . . . . . . . . . . . . . . . . . 69 2.2.6 Homomorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 2.3 Fields: A Prelude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 2.4 Review of Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 2.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 2.6 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 3 Linear Block Codes 83 3.1 Basic Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 3.2 The Generator Matrix Description of Linear Block Codes . . . . . . . . . . 84 3.2.1 Rudimentary Implementation . . . . . . . . . . . . . . . . . . . . . 86 3.3 The Parity Check Matrix and Dual Codes . . . . . . . . . . . . . . . . . . 86 3.3.1 Some Simple Bounds on Block Codes . . . . . . . . . . . . . . . . 88 3.4 Error Detection and Correction over Hard-Input Channels . . . . . . . . . . 90 3.4.1 Error Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 3.4.2 Error Correction: The Standard Array . . . . . . . . . . . . . . . . 90 3.6 Hamming Codes and Their Duals . . . . . . . . . . . . . . . . . . . . . . . 97 3.7 Performance of Linear Codes . . . . . . . . . . . . . . . . . . . . . . . . . 98 3.7.1 Error detection performance . . . . . . . . . . . . . . . . . . . . . 99 3.7.2 Error Correction Performance . . . . . . . . . . . . . . . . . . . . 100 3.7.3 Performance for Soft-Decision Decoding . . . . . . . . . . . . . . 103 3.8 Erasure Decoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 3.8.1 Binary Erasure Decoding . . . . . . . . . . . . . . . . . . . . . . . 105 3.9 Modifications to Linear Codes . . . . . . . . . . . . . . . . . . . . . . . . 105 3.10 Best Known Linear Block Codes . . . . . . . . . . . . . . . . . . . . . . . 107 3.11 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 3.12 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 113 4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 4.2 Basic Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 4.3 Rings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 4.3.1 Rings of Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . 115 4.4 QuotientRings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 4.5 IdealsinRings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 4.6 Algebraic Description of Cyclic Codes . . . . . . . . . . . . . . . . . . . . 120 4.7 Nonsystematic Encoding and Parity Check . . . . . . . . . . . . . . . . . . 122 4.8 Systematic Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 4.9 Some Hardware Background . . . . . . . . . . . . . . . . . . . . . . . . . 126 4.9.1 Computational Building Blocks . . . . . . . . . . . . . . . . . . . 126 4.9.2 Sequences and Power series . . . . . . . . . . . . . . . . . . . . . 127 4.9.3 Polynomial Multiplication . . . . . . . . . . . . . . . . . . . . . . 128 Last-Element-First Processing . . . . . . . . . . . . . . . . . . . . 128 First-Element-First Processing . . . . . . . . . . . . . . . . . . . . 128 4.9.4 Polynomial division . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Last-Element-First Processing . . . . . . . . . . . . . . . . . . . . 129 4.9.5 Simultaneous Polynomial Division and Multiplication . . . . . . . 132 First-Element-First Processing . . . . . . . . . . . . . . . . . . . . 132 4.10 Cyclic Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 4.1 1 Syndrome Decoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 4.12 Shortened Cyclic Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . Method 1: Simulating the Extra Clock Shifts . . . . . . . . . . . . 144 Method 2: Changing the Error Pattern Detection Circuit . . . . . . 147 4.13 Binary CRC Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 4.13.1 Byte-Oriented Encoding and Decoding Algorithms . . . . . . . . . 150 4.13.2 CRC Protecting Data Files or Data Packets . . . . . . . . . . . . . 153 Appendix 4.A Linear Feedback Shift Registers . . . . . . . . . . . . . . . . . . . 154 Appendix 4.A. 1 Basic Concepts . . . . . . . . . . . . . . . . . . . . . . . . 154 Appendix 4.A.2 Connection With Polynomial Division Appendix 4.A.3 Some Algebraic Properties of Shift Sequences . . . . . . . 3.5 Weight Distributions of Codes and Their Duals . . . . . . . . . . . . . . . 95 4 Cyclic Codes, Rings, and Polynomials 143 . . . . . . . . . . . 157 160 Lab 2 Polynomial Division and Linear Feedback Shift Registers . . . 161 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Preliminary Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Programming Part: BinLFSR . . . . . . . . . . . . . . . . . . . . . . . . 161 Resources and Implementation Suggestions . . . . . . . . . . . . . . . . . 161 Programming Part: BinPolyDiv . . . . . . . . . . . . . . . . . . . . . . 162 Follow-On Ideas and Problems . . . . . . . . . . . . . . . . . . . . . . . . 162 Lab 3 CRC Encoding and Decoding . . . . . . . . . . . . . . . . . . . . . 162 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Preliminary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Programming Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Resources and Implementation Suggestions . . . . . . . . . . . . . . . . . 163 4.14 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 4.15 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 5 Rudiments of Number Theory and Algebra 171 5.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 5.2 Number Theoretic Preliminaries . . . . . . . . . . . . . . . . . . . . . . . 175 5.2.1 Divisibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 5.2.3 The Sugiyama Algorithm . . . . . . . . . . . . . . . . . . . . . . . 182 5.2.4 Congruence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 5.2.5 The q!~ Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 5.2.6 Some Cryptographic Payoff . . . . . . . . . . . . . . . . . . . . . 186 Fermat's Little Theorem . . . . . . . . . . . . . . . . . . . . . . . 186 RSA Encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 5.3 The Chinese Remainder Theorem . . . . . . . . . . . . . . . . . . . . . . . 188 5.3.1 The CRT and Interpolation . . . . . . . . . . . . . . . . . . . . . . 190 The Evaluation Homomorphism . . . . . . . . . . . . . . . . . . . 190 The Interpolation Problem . . . . . . . . . . . . . . . . . . . . . . 191 5.4 Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 5.4.1 An Examination of IR and C . . . . . . . . . . . . . . . . . . . . . 194 5.4.2 Galois Field Construction: An Example . . . . . . . . . . . . . . . 196 5.4.3 Connection with Linear Feedback Shift Registers . . . . . . . . . . 199 5.5 Galois Fields: Mathematical Facts . . . . . . . . . . . . . . . . . . . . . . 200 5.6 Implementing Galois Field Arithmetic . . . . . . . . . . . . . . . . . . . . 204 5.6.1 Zech Logarithms . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 5.6.2 Hardware Implementations . . . . . . . . . . . . . . . . . . . . . . 205 5.7 Subfields of Galois Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 5.8 Irreducible and Primitive polynomials . . . . . . . . . . . . . . . . . . . . 207 5.9 Conjugate Elements and Minimal Polynomials . . . . . . . . . . . . . . . . 209 5.9.1 Minimal Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . 212 5.10 Factoring x" - 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 5.1 1 Cyclotomic Cosets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Programming the Euclidean Algorithm . . . . . . . . . . . . . . . 223 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Preliminary Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Programming Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 Preliminary Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 Programming Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 5.12 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 5.13 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 Lab 5 Programming Galois Field Arithmetic . . . . . . . . . . . . . . . . 224 6 BCH and Reed-Solomon Codes: Designer Cyclic Codes 235 6.1 BCHCodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 6.1.1 Designing BCH Codes . . . . . . . . . . . . . . . . . . . . . . . . 235 6.1.2 TheBCHBound . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 6.1.3 Weight Distributions for Some Binary BCH Codes . . . . . . . . . 239 6.1.4 Asymptotic Results for BCH Codes . . . . . . . . . . . . . . . . . 240 6.2 Reed-Solomon Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 6.2.1 Reed-Solomon Construction 1 . . . . . . . . . . . . . . . . . . . . 242 6.2.2 Reed-Solomon Construction 2 . . . . . . . . . . . . . . . . . . . . 243 6.2.3 Encoding Reed-Solomon Codes . . . . . . . . . . . . . . . . . . . 244 6.2.4 MDS Codes and Weight Distributions for RS Codes . . . . . . . . . 245 Decoding BCH and RS Codes: The General Outline . . . . . . . . . . . . . 247 6.3.1 Computation of the Syndrome . . . . . . . . . . . . . . . . . . . . 247 6.3.2 The Error Locator Polynomial . . . . . . . . . . . . . . . . . . . . 248 6.3.3 ChienSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 6.4 Finding the Error Locator Polynomial . . . . . . . . . . . . . . . . . . . . 250 6.4.2 Berlekamp-Massey Algorithm . . . . . . . . . . . . . . . . . . . . 253 Simplifications for Binary Codes . . . . . . . . . . . . . . . . . . . 259 6.5 Non-Binary BCH and RS Decoding . . . . . . . . . . . . . . . . . . . . . 261 6.5.1 Forney’s Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 262 6.6 Euclidean Algorithm for the Error Locator Polynomial . . . . . . . . . . . 266 Erasure Decoding for Nonbinary BCH or RS codes . . . . . . . . . . . . . 267 6.8 Galois Field Fourier Transform Methods . . . . . . . . . . . . . . . . . . . 269 6.8.1 Equivalence of the Two Reed-Solomon Code Constructions . . . . 274 6.8.2 Frequency-Domain Decoding . . . . . . . . . . . . . . . . . . . . 275 6.9 Variations and Extensions of Reed-Solomon Codes . . . . . . . . . . . . . 276 6.9.1 Simple Modifications . . . . . . . . . . . . . . . . . . . . . . . . . 276 6.9.3 GoppaCodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 Decoding Alternant Codes . . . . . . . . . . . . . . . . . . . . . . 280 The McEliece Public Key Cryptosystem . . . . . . . . . . . . . . . 280 Lab 6 Programming the Berlekamp-Massey Algorithm . . . . . . . . . 281 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Preliminary Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Programming Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Resources and Implementation Suggestions Lab 7 programming the BCH Decoder . . . . . . . . . . . . . . . . . . . 283 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 Preliminary Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 Programming Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 Resources and Implementation Suggestions . . . . . . . . . . . . . . . . . 283 Follow-On Ideas and Problems . . . . . . . . . . . . . . . . . . . . . . . . 284 Lab 8 Reed-Solomon Encoding and Decoding . . . . . . . . . . . . . . 284 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 Programming Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 Appendix 6.A Proof of Newton’s Identities . . . . . . . . . . . . . . . . . . . . . 285 6.10 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 6.1 1 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 293 7.1 Introduction: Workload for Reed-Solomon Decoding . . . . . . . . . . . . 293 7.2 Derivations of Welch-Berlekamp Key Equation . . . . . . . . . . . . . . . 293 7.3 Finding the Error Values . . . . . . . . . . . . . . . . . . . . . . . . . . . 300 7.4 Methods of Solving the WB Key Equation . . . . . . . . . . . . . . . . . . 302 7.4.1 Background: Modules . . . . . . . . . . . . . . . . . . . . . . . . 302 7.4.2 The Welch-Berlekamp Algorithm . . . . . . . . . . . . . . . . . . 303 7.4.3 Modular Solution of the WB Key Equation . . . . . . . . . . . . . 310 7.6.1 Bounded Distance, ML, and List Decoding . . . . . . . . . . . . . 322 Error Correction by Interpolation . . . . . . . . . . . . . . . . . . . 323 7.6.3 Polynomials in ?Lvo Variables . . . . . . . . . . . . . . . . . . . . 324 Degree and Monomial Order . . . . . . . . . . . . . . . . . . . . . 325 Zeros and Multiple Zeros . . . . . . . . . . . . . . . . . . . . . . . 328 7.6.4 The GS Decoder: The Main Theorems . . . . . . . . . . . . . . . . 330 The Interpolation Theorem . . . . . . . . . . . . . . . . . . . . . . 331 The Factorization Theorem . . . . . . . . . . . . . . . . . . . . . . 331 The Correction Distance . . . . . . . . . . . . . . . . . . . . . . . 333 The Number of Polynomials in the Decoding List . . . . . . . . . . 335 Algorithms for Computing the Interpolation Step . . . . . . . . . . 337 Finding Linearly Dependent Columns: The Feng-Tzeng Algorithm 338 Finding the Intersection of Kernels: The Katter Algorithm . . . . . 342 7.6.6 A Special Case: m = 1 and L = 1 . . . . . . . . . . . . . . . . . . 348 7.6.7 The Roth-Ruckenstein Algorithm . . . . . . . . . . . . . . . . . . 350 What to Do with Lists of Factors? . . . . . . . . . . . . . . . . . . 354 7.6.8 Soft-Decision Decoding of Reed-Solomon Codes . . . . . . . . . . 358 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358 A Factorization Theorem . . . . . . . . . . . . . . . . . . . . . . . 360 Mapping from Reliability to Multiplicity . . . . . . . . . . . . . . 361 The Geometry of the Decoding Regions . . . . . . . . . . . . . . . 363 Computing the Reliability Matrix . . . . . . . . . . . . . . . . . . 364 7.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365 7.8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368 8 Other Important Block Codes 369 8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369 8.2 Hadamard Matrices. Codes. and Transforms . . . . . . . . . . . . . . . . . 369 8.2.1 Introduction to Hadamard Matrices . . . . . . . . . . . . . . . . . 369 8.2.2 The Paley Construction of Hadamard Matrices . . . . . . . . . . . 371 8.2.3 Hadamard Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 374 8.3 Reed-Muller Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 8.3.1 Boolean Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 375 8.3.2 Definition of the Reed-Muller Codes . . . . . . . . . . . . . . . . . 376 8.3.3 Encoding and Decoding Algorithms for First-Order RM Codes . . . 379 Encoding RM (1. m) Codes . . . . . . . . . . . . . . . . . . . . . 379 Decoding RM(1, m) Codes . . . . . . . . . . . . . . . . . . . . . 379 Expediting Decoding Using the Fast Hadamard Transform . . . . . 382 The Reed Decoding Algorithm for RM(r. m) Codes, I 2 1 . . . . . 384 Details for an RM(2. 4) Code . . . . . . . . . . . . . . . . . . . . 384 8.3.5 Other Constructions of Reed-Muller Codes . . . . . . . . . . . . . 391 Building Long Codes from Short Codes: The Squaring Construction . . . . 392 8.3.4 A Geometric Viewpoint . . . . . . . . . . . . . . . . . . . . . . . 387 8.4 8.5 Quadratic Residue Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 396 8.6 Golaycodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398 8.6.1 Decoding the Golay Code . . . . . . . . . . . . . . . . . . . . . . 400 Algebraic Decoding of the $23 Golay Code . . . . . . . . . . . . . 400 Arithmetic Decoding of the 524 Code . . . . . . . . . . . . . . . . 401 8.7 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403 8.8 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404 9 Bounds on Codes 406 9.1 The Gilbert-Varshamov Bound . . . . . . . . . . . . . . . . . . . . . . . . 409 9.2 The Plotkin Bound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410 9.3 The Griesmer Bound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411 9.4 The Linear Programming and Related Bounds . . . . . . . . . . . . . . . . 413 9.4.1 Krawtchouk Polynomials . . . . . . . . . . . . . . . . . . . . . . . 415 9.4.2 Character . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415 9.4.3 Krawtchouk Polynomials and Characters . . . . . . . . . . . . . . 416 9.5 The McEliece-Rodemich-Rumsey-WelcBh ound . . . . . . . . . . . . . . . 418 9.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 9.7 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424 10 Bursty Channels. Interleavers. and Concatenation 425 10.1 Introduction to Bursty Channels . . . . . . . . . . . . . . . . . . . . . . . 425 10.2 Interleavers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425 10.3 An Application of Interleaved RS Codes: Compact Discs . . . . . . . . . . 427 10.4 Productcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430 10.5 Reed-Solomon Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431 10.6 Concatenated Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432 10.7 Fire Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433 10.7.1 Fire Code Definition . . . . . . . . . . . . . . . . . . . . . . . . . 433 10.7.2 Decoding Fire Codes: Error Trapping Decoding . . . . . . . . . . . 435 10.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 10.9 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438 11 Soft-Decision Decoding Algorithms 439 1 1.2 Generalized Minimum Distance Decoding . . . . . . . . . . . . . . . . . . 441 11.1 Introduction and General Notation . . . . . . . . . . . . . . . . . . . . . . 439 1 1.2.1 Distance Measures and Properties . . . . . . . . . . . . . . . . . . 442 1 1.3 The Chase Decoding Algorithms . . . . . . . . . . . . . . . . . . . . . . . 445 11.4 Halting the Search: An Optimality Condition . . . . . . . . . . . . . . . . 445 1 1.5 Ordered Statistic Decoding . . . . . . . . . . . . . . . . . . . . . . . . . . 447 1 1.6 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449 1 1.7 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450 Part I11 Codes on Graphs 12 Convolutional Codes 452 12.1 Introduction and Basic Notation . . . . . . . . . . . . . . . . . . . . . . . 452 12.1.1 TheState . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456 12.2 Definition of Codes and Equivalent Codes . . . . . . . . . . . . . . . . . . 458 12.2.1 Catastrophic Encoders . . . . . . . . . . . . . . . . . . . . . . . . 461 12.2.2 Polynomial and Rational Encoders . . . . . . . . . . . . . . . . . . 464 12.2.3 Constraint Length and Minimal Encoders . . . . . . . . . . . . . . 465 12.2.4 Systematic Encoders . . . . . . . . . . . . . . . . . . . . . . . . . 468 12.3 Decoding Convolutional Codes . . . . . . . . . . . . . . . . . . . . . . . . 469 12.3.1 Introduction and Notation . . . . . . . . . . . . . . . . . . . . . . 469 12.3.2 The Viterbi Algorithm . . . . . . . . . . . . . . . . . . . . . . . . 471 12.3.3 Some Implementation Issues . . . . . . . . . . . . . . . . . . . . . 481 The Basic Operation: Add-Compare-Select . . . . . . . . . . . . . 481 Decoding Streams of Data: Windows on the Trellis . . . . . . . . . 481 Output Decisions . . . . . . . . . . . . . . . . . . . . . . . . . . . 482 Hard and Soft Decoding; Quantization . . . . . . . . . . . . . . . . 484 Synchronization Issues . . . . . . . . . . . . . . . . . . . . . . . . 486 12.4 Some Performance Results . . . . . . . . . . . . . . . . . . . . . . . . . . 487 12.5 Error Analysis for Convolutional Codes . . . . . . . . . . . . . . . . . . . 491 12.5.1 Enumerating Paths Through the Trellis . . . . . . . . . . . . . . . . 493 Enumerating on More Complicated Graphs: Mason’s Rule . . . . . 496 12.5.2 Characterizing the Node Error Probability P, and the Bit Error Rate Pb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498 12.5.3 A Bound on Pd for Discrete Channels . . . . . . . . . . . . . . . . 501 Performance Bound on the BSC . . . . . . . . . . . . . . . . . . . 503 12.5.4 A Bound on Pd for BPSK Signaling Over the AWGN Channel . . . 503 12.5.5 Asymptotic Coding Gain . . . . . . . . . . . . . . . . . . . . . . . 504 12.6 Tables of Good Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 12.7 Puncturing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507 Puncturing to Achieve Variable Rate . . . . . . . . . . . . . . . . . 509 12.8 SuboptimalDecodingAlgorithmsforConvolutionalCodes . . . . . . . . . 510 12.8.1 Tree Representations . . . . . . . . . . . . . . . . . . . . . . . . . 511 12.8.2 The Fano Metric . . . . . . . . . . . . . . . . . . . . . . . . . . . 511 12.8.3 The Stack Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 515 12.8.4 The Fano Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 517 12.8.5 Other Issues for Sequential Decoding . . . . . . . . . . . . . . . . 520 12.9 Convolutional Codes as Block Codes . . . . . . . . . . . . . . . . . . . . . 522 12.10 Trellis Representations of Block and Cyclic Codes . . . . . . . . . . . . . . 523 12.10.1 Block Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523 12.10.2 Cyclic Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524 12.10.3 Trellis Decoding of Block Codes . . . . . . . . . . . . . . . . . . . 525 Programming Convolutional Encoders . . . . . . . . . . . . . . . 526 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526 Programming Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 Programming Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 12.1 1 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529 12.12 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533 13 'Ikellis Coded Modulation 535 13.1 Adding Redundancy by Adding Signals . . . . . . . . . . . . . . . . . . . 535 13.2 Background on Signal Constellations . . . . . . . . . . . . . . . . . . . . . 535 13.3 TCM Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537 The General Ungerboeck Coding Framework . . . . . . . . . . . . 544 13.3.2 The Set Partitioning Idea . . . . . . . . . . . . . . . . . . . . . . . 545 13.4 Some Error Analysis for TCM Codes . . . . . . . . . . . . . . . . . . . . . 546 13.4.1 General Considerations . . . . . . . . . . . . . . . . . . . . . . . . 546 A Description of the Error Events . . . . . . . . . . . . . . . . . . 548 13.4.3 Known Good TCM Codes . . . . . . . . . . . . . . . . . . . . . . 552 13.5 Decodmg TCM Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554 13.6 Rotational Invariance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556 Differential Encoding . . . . . . . . . . . . . . . . . . . . . . . . . 558 Constellation Labels and Partitions . . . . . . . . . . . . . . . . . . 559 13.7 Multidimensional TCM . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561 13.7.1 Some Advantages of Multidimensional TCM . . . . . . . . . . . . 562 13.7.2 Lattices and Sublattices . . . . . . . . . . . . . . . . . . . . . . . . 563 Basic Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 563 Common Lattices . . . . . . . . . . . . . . . . . . . . . . . . . . . 565 Sublattices and Cosets . . . . . . . . . . . . . . . . . . . . . . . . 566 The Lattice Code Idea . . . . . . . . . . . . . . . . . . . . . . . . 567 Sources of Coding Gain in Lattice Codes . . . . . . . . . . . . . . 567 Some Good Lattice Codes . . . . . . . . . . . . . . . . . . . . . . 571 13.8 The V.34 Modem Standard . . . . . . . . . . . . . . . . . . . . . . . . . . 571 Lab 11 Trellis-Coded Modulation Encoding and Decoding . . . . . . . . 578 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578 Programming Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578 13.9 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578 13.10 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580 Part IV Iteratively Decoded Codes 581 14 lbrbo Codes 582 14.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582 14.2 Encoding Parallel Concatenated Codes . . . . . . . . . . . . . . . . . . . . 584 14.3 Turbo Decoding Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . 586 14.3.1 The MAP Decoding Algorithm . . . . . . . . . . . . . . . . . . . . 588 14.3.2 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588 14.3.3 Posterior Probability . . . . . . . . . . . . . . . . . . . . . . . . . 590 14.3.4 Computing at and pt . . . . . . . . . . . . . . . . . . . . . . . . . 592 14.3.6 Normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594 14.3.7 Summary of the BCJR Algorithm . . . . . . . . . . . . . . . . . . 596 14.3.8 A MatrixNector Formulation . . . . . . . . . . . . . . . . . . . . . 597 14.3.9 Comparison of the Viterbi and BCJR Algorithms . . . . . . . . . . 598 14.3.10 The BCJR Algorithm for Systematic Codes . . . . . . . . . . . . . 598 14.3.11 Turbo Decoding Using the BCJR Algorithm . . . . . . . . . . . . . 600 The Terminal State of the Encoders . . . . . . . . . . . . . . . . . 602 14.3.12 Likelihood Ratio Decoding . . . . . . . . . . . . . . . . . . . . . . 602 Log Prior Ratio Ap. . . . . . . . . . . . . . . . . . . . . . . . . . 603 Log Posterior A,. . . . . . . . . . . . . . . . . . . . . . . . . . . . 605 14.3.13 Statement of the Turbo Decoding Algorithm . . . . . . . . . . . . . 605 14.3.14 Turbo Decoding Stopping Criteria . . . . . . . . . . . . . . . . . . 605 The Cross Entropy Stopping Criterion . . . . . . . . . . . . . . . . 606 The Sign Change Ratio (SCR) Criterion . . . . . . . . . . . . . . . 607 The Hard Decision Aided (HDA) Criterion . . . . . . . . . . . . . 608 14.3.15 Modifications of the MAP Algorithm . . . . . . . . . . . . . . . . 608 The Max-Log-MAP Algorithm . . . . . . . . . . . . . . . . . . . . 608 14.3.16 Corrections to the Max-Log-MAP Algorithm . . . . . . . . . . . . 609 14.3.17 The Soft Output Viterbi Algorithm . . . . . . . . . . . . . . . . . . 610 14.4 On the Error Floor and Weight Distributions . . . . . . . . . . . . . . . . . 612 14.4.1 The Error Floor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612 14.4.2 Spectral Thinning and Random Interleavers . . . . . . . . . . . . . 614 14.4.3 On Interleavers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618 14.5 EXIT Chart Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619 14.5.1 TheEXITChart . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622 Block Turbo Coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623 14.7 Turbo Equalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626 14.7.1 Introduction to Turbo Equalization . . . . . . . . . . . . . . . . . . 626 14.7.2 The Framework for Turbo Equalization . . . . . . . . . . . . . . . 627 Lab 12 Turbo Code Decoding . . . . . . . . . . . . . . . . . . . . . . . . . 629 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629 Programming Part . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629 14.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629 14.9 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632 15 Low-Density Parity-Check Codes 634 15.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634 15.2 LDPC Codes: Construction and Notation . . . . . . . . . . . . . . . . . . . 635 15.3 Tanner Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638 15.4 Transmission Through a Gaussian Channel . . . . . . . . . . . . . . . . . . 638 15.5 Decoding LDPC Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 640 15.5.1 The Vertical Step: Updating qmn(x) . . . . . . . . . . . . . . . . . 641 15.5.2 Horizontal Step: Updating rmn (x) . . . . . . . . . . . . . . . . . . 644 15.5.3 Terminating andInitializing the Decoding Algorithm . . . . . . . . 647 15.5.4 Summary of the Algorithm . . . . . . . . . . . . . . . . . . . . . . 648 15.5.5 Message Passing Viewpoint . . . . . . . . . . . . . . . . . . . . . 649 15.5.6 Likelihood Ratio Decoder Formulation . . . . . . . . . . . . . . . 649 15.6 Why Low-Density Parity-Check Codes? . . . . . . . . . . . . . . . . . . . 653 15.7 The Iterative Decoder on General Block Codes . . . . . . . . . . . . . . . . 654 15.8 Density Evolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655 15.9 EXIT Charts for LDPC Codes . . . . . . . . . . . . . . . . . . . . . . . . 659 15.10 Irregular LDPC Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 660 15.10.1 Degree Distribution Pairs . . . . . . . . . . . . . . . . . . . . . . . 662 15.10.2 Some Good Codes . . . . . . . . . . . . . . . . . . . . . . . . . . 664 15.10.3 Density Evolution for Irregular Codes . . . . . . . . . . . . . . . . 664 15.10.4 Computation and Optimization of Density Evolution . . . . . . . . 667 15.10.5 Using Irregular Codes . . . . . . . . . . . . . . . . . . . . . . . . 668 15.1 1 More on LDPC Code Construction 668 15.1 1.1 A Construction Based on Finite Geometries . . . . . . . . . . . . . 668 15.1 1.2 Constructions Based on Other Combinatoric Objects . . . . . . . . 669 15.12 Encoding LDPC Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669 15.13 A Variation: Low-Density Generator Matrix Codes . . . . . . . . . . . . . 671 15.14 Serial Concatenated Codes; Repeat-Accumulate Codes . . . . . . . . . . . 671 15.14.1 Irregular RA Codes . . . . . . . . . . . . . . . . . . . . . . . . . . 673 Lab 13 Programming an LDPC Decoder . . . . . . . . . . . . . . . . . . . 674 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675 Numerical Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . 675 15.15 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676 15.16 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679 16.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680 16.2 Operations in Semirings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681 16.3 Functions on Local Domains . . . . . . . . . . . . . . . . . . . . . . . . . 681 16.4 Factor Graphs and Marginalization . . . . . . . . . . . . . . . . . . . . . . 686 Marginalizing on a Single Variable . . . . . . . . . . . . . . . . . . 687 16.4.2 Marginalizing on All Individual Variables . . . . . . . . . . . . . . 691 16.5 Applications to Coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694 16.5.1 Blockcodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694 16.5.2 ModificationstoMessagePassingfor Binary Variables . . . . . . . 695 16.5.3 Trellis Processing and the FonvardBackward Algorithm . . . . . . 696 16.5.4 Turbo Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699 Summary of Decoding Algorithms on Graphs . . . . . . . . . . . . . . . . 699 16.7 Transformations of Factor Graphs . . . . . . . . . . . . . . . . . . . . . . . 700 16.7.1 Clustering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700 16.7.2 Stretching Variable Nodes . . . . . . . . . . . . . . . . . . . . . . 701 16.7.3 Exact Computation of Graphs with Cycles . . . . . . . . . . . . . . 702 16.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706 16.9 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708 16 Decoding Algorithms on Graphs 680 16.4.1 16.6 Part V Space-Time Coding 709 17 Fading Channels and Space-Time Codes 710 17.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710 17.2 Fading Channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710 17.2.1 Rayleigh Fading . . . . . . . . . . . . . . . . . . . . . . . . . . . 712 . . . . . . . . 714 17.3.1 The Narrowband MIMO Channel . . . . . . . . . . . . . . . . . . 716 17.3.2 Diversity Performance with Maximal-Ratio Combining . . . . . . . 717 17.4 Space-Time Block Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 719 17.4.1 The Alamouti Code . . . . . . . . . . . . . . . . . . . . . . . . . . 719 17.4.2 A More General Formulation . . . . . . . . . . . . . . . . . . . . . 721 17.4.3 Performance Calculation . . . . . . . . . . . . . . . . . . . . . . . 721 Real Orthogonal Designs . . . . . . . . . . . . . . . . . . . . . . . 723 EncodingandDecodingBasedonOrthogonalDesigns . . . . . . . 724 Generalized Real Orthogonal Designs . . . . . . . . . . . . . . . . 726 17.4.4 Complex Orthogonal Designs . . . . . . . . . . . . . . . . . . . . 727 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728 Space-Time Trellis Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 728 17.5.1 Concatenation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729 17.6 How Many Antennas? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732 17.7 Estimating Channel Information . . . . . . . . . . . . . . . . . . . . . . . 733 17.8 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733 17.9 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 734 A Log Likelihood Algebra 735 A.l Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737 References Index 739 750
JDK并没有直接提供实现汉明校验码的功能,但是你可以使用Java语言来实现汉明校验码的算法。汉明校验码是一种错误检测和纠正的方法,它通过在数据中添加冗余位来检测和纠正错误。 下面是一个简单的Java代码示例,用于计算汉明校验码: ```java public class HammingCode { public static void main(String[] args) { String data = "1010101"; // 原始数据 int[] hammingCode = generateHammingCode(data); // 生成汉明校验码 System.out.println("汉明校验码:" + Arrays.toString(hammingCode)); // 模拟一个错误的数据 hammingCode = 1 - hammingCode; int errorPosition = checkErrorPosition(hammingCode); // 检测错误位置 if (errorPosition != -1) { System.out.println("错误位置:" + errorPosition); hammingCode[errorPosition] = 1 - hammingCode[errorPosition]; // 纠正错误位 System.out.println("纠正后的汉明校验码:" + Arrays.toString(hammingCode)); } else { System.out.println("没有错误"); } } // 生成汉明校验码 public static int[] generateHammingCode(String data) { int dataLength = data.length(); int[] hammingCode = new int[dataLength + getParityBitCount(dataLength)]; int dataIndex = 0; int hammingIndex = 0; // 遍历汉明码数组,将数据位和冗余位填入 for (int i = 1; i <= hammingCode.length; i++) { if (isPowerOfTwo(i)) { // 冗余位位置 hammingCode[i - 1] = 0; // 先填充0 } else { hammingCode[i - 1] = Integer.parseInt(String.valueOf(data.charAt(dataIndex++))); // 填充数据位 } } // 计算冗余位的值 for (int i = 0; i < hammingCode.length; i++) { if (isPowerOfTwo(i + 1)) { // 冗余位位置 int parityBit = calculateParityBit(hammingCode, i); hammingCode[i] = parityBit; } } return hammingCode; } // 检测错误位置 public static int checkErrorPosition(int[] hammingCode) { int errorPosition = 0; // 计算冗余位的值,并与实际值比较 for (int i = 0; i < hammingCode.length; i++) { if (isPowerOfTwo(i + 1)) { // 冗余位位置 int parityBit = calculateParityBit(hammingCode, i); if (parityBit != hammingCode[i]) { errorPosition += i + 1; } } } return errorPosition; } // 计算冗余位的值 public static int calculateParityBit(int[] hammingCode, int parityBitIndex) { int parityBit = 0; for (int i = 0; i < hammingCode.length; i++) { if (!isPowerOfTwo(i + 1) && ((i + 1) & (parityBitIndex + 1)) != 0) { parityBit ^= hammingCode[i]; } } return parityBit; } // 判断一个数是否为2的幂次方 public static boolean isPowerOfTwo(int num) { return (num & (num - 1)) == 0; } // 根据数据长度计算冗余位的数量 public static int getParityBitCount(int dataLength) { int parityBitCount = 0; while (Math.pow(2, parityBitCount) < dataLength + parityBitCount + 1) { parityBitCount++; } return parityBitCount; } } ``` 这段代码演示了如何生成汉明校验码,并检测和纠正错误位置。你可以根据自己的需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值