【python】Reed-solomon codes的二维码应用(十一)

        今天来说一下消除纠正。

        如果错误的位置是已知的,比如在长度为10的RS码中,已知错误的是第三个和第五个位置,纠正它是最简单的。这被称为消除纠正。对于每一个添加的纠错码,都可以纠正一个消除(即添加的n个纠错码能够保证纠正n个消除码字)。如果错误位置未知,那么对于一个错误,需要2个错误校验符号(即对于t个错误,我们需要2t个错误校验符号才能纠正)。这在实际应用中非常有用,比如QR码的某些位置被覆盖或被剪掉什么的。扫描器很难知道发生了什么,所以不是所有的QR码扫描器都能纠正消除。
有了伴随式,接下来计算定位式:

def rs_find_errata_locator(e_pos):
    '''eg:"_"为误码,"h_ll_ worldxxxxxxxxx"中误码位置应为: n-1 - [1, 4] = [18, 15] = erasures_loc.'''

    e_loc = [1] # 初始化为1而非0是因为要计算乘法
    for i in e_pos:
        e_loc = gf_poly_mul( e_loc, gf_poly_add([1], [gf_pow(2, i), 0]) )
    return e_loc
        解释一下这个代码求得是什么,我们之前定义过错误定位多项式A(X):
        
        e_pos是代表错误位置的一个列表,如 n-1 - [1, 4] = [18, 15]其中[18,15]就是错误位置。 gf_poly_add([1], [gf_pow(2, i), 0])
代表表达式(X*x + 1 ),不断迭代就有错误定位多项式A(X)了。
         接下来计算错误判别式(erasure/error evaluator polynomial),通过一个多项式乘法而后一个多项式除法来实现:
        

def rs_find_error_evaluator(synd, err_loc, nsym):

    # Omega(x) = [ Synd(x) * Error_loc(x) ] mod x^(n-k+1)
    remainder = gf_poly_div( gf_poly_mul(synd, err_loc), ([1] + [0]*(nsym+1)) ) # 除法运算只是为了截短

    # Faster way that is equivalent
    #remainder = gf_poly_mul(synd, err_loc) # 乘法
    #remainder = remainder[len(remainder)-(nsym+1):] # 截短

    return remainder

        这里的gf_poly_mul(synd, err_loc)

        代表S1,S2,S3...Sv的多项式乘以Av,Av-1...A1 ,得到的数最后除以[1] + [0]*(nsym+1),为了截胡咔咔咔把前面的不必要的数字都去掉。      

猜你喜欢

转载自blog.csdn.net/weixin_39878297/article/details/80218382