Hamming code

Also known as (7,4) code,7 trainsmitted bits for 4 source code.

TRANSMIT

The transmitted procedure can be reprecented as follows.

$t=G^Ts$

where G is:

import numpy as np
G = np.matrix(
    [[1,0,0,0],
     [0,1,0,0],
     [0,0,1,0],
     [0,0,0,1],
     [1,1,1,0],
     [0,1,1,1],
     [1,0,1,1]]).T
s=np.matrix([[1,1,1,0]]).T

t = (G.T*s)%2

visualization

$t_5,t_6,t_7$ is called parity-check bits

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

DECODING

1.intuitive way: measure the similarity between the recieved bits $r$ and the encoded codes $t$

2.Syndrome decoding

dashed line for which parity is not even(unhappy)

full line for which parity is even(happy)

find the unique bit,that lies inside all unhappy circles and outside all happy circles

the corresponding syndrome z as follow:

(b) 110 ($t_5$ not even,$t_6$ not even,$t_7$ even),$r_2$ should be unflipped

(c) 100 ($t_5$ not even,$t_6$ even,$t_7$ even),$r_5$ should be unflipped

(d) 111 ($t_5$ not even,$t_6$ not even,$t_7$ not even),$r_3$ should be unflipped

all the situations is listed in table below:

the syndrome z can be achieved by matrix:

$z=Hr$

which H is:

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

PERFORMANCE

1.when there is only one bit flipped in all 7 bits,the decoder can always get right

2.when there are more than one bits flippend,the decoder get wrong

the single bit error rate,can be estimate as follow:

$p_b \approx \frac{1-{(1-f)}^2-7{(1-f)}^6f}{2}$

the exact error rate is about 0.6688,which can be computed with following program.

 1 import numpy as np
 2 import copy
 3 import itertools
 4 from scipy.misc import comb
 5
 6 def encode(s):
 7     G = np.array(
 8         [[1,0,0,0],
 9          [0,1,0,0],
10          [0,0,1,0],
11          [0,0,0,1],
12          [1,1,1,0],
13          [0,1,1,1],
14          [1,0,1,1]]
15     )
16
17     return np.dot(G,s)%2
18
19 def decode(r):
20     t_hat = copy.deepcopy(r)
21     H = np.array(
22         [[1,1,1,0,1,0,0],
23          [0,1,1,1,0,1,0],
24          [1,0,1,1,0,0,1]]
25     )
26
27     syndrome_map = {0:-1,
28            1:6,
29            10:5,
30            11:3,
31            100:4,
32            101:0,
33            110:1,
34            111:2}
35
36     syndrome = np.dot(np.dot(H,r)%2,np.array([100,10,1]))
37     if syndrome_map[syndrome]>=0:
38         t_hat[syndrome_map[syndrome]] = (t_hat[syndrome_map[syndrome]]+1)%2
39
40     return t_hat
41
42 def flipn(flip_list,t):
43     ‘‘‘
44     flipped the bits specified by flip_list and return it
45     :param flip_list:
46     :param t:
47     :return:
48     ‘‘‘
49     r = copy.deepcopy(t)
50     for flip in flip_list:
51         r[flip] = (r[flip]+1)%2
52     return r
53
54 def flipn_avg_err(n,s):
55     ‘‘‘
56     get the average error bits when flip n bits
57     :param n:
58     :param s:
59     :return:
60     ‘‘‘
61     t = encode(s)
62     items = range(7)
63     errors = 0
64     count = 0
65     for flip in itertools.combinations(items,n):
66         r = flipn(list(flip),t)
67         t_hat = decode(r)
68
69         errors += 4-sum(s==t_hat[:4])
70         count += 1
71     return errors*1.0/count
72
73 f = 0.9
74 s = np.array([0,0,0,0])
75 all_error = 0.0
76 for n in range(2,8):
77     error = flipn_avg_err(n,s)
78     all_error += error*comb(7,n)*(f**(7-n))*((1-f)**n)
79 print all_error/4

python

时间: 2024-11-10 15:06:22

Hamming code的相关文章

URAL 1792. Hamming Code (枚举)

1792. Hamming Code Time limit: 1.0 second Memory limit: 64 MB Let us consider four disks intersecting as in the figure. Each of the three shapes formed by the intersectionof three disks will be called a petal. Write zero or one on each of the disks.

[USACO][枚举]Hamming Code

题意: 给出N,B,D,要求输出N个十进制数字,他们之间的Hamming距离在长度为B位的时候都等于D. 思路: 感觉图论就是一个,允许我们记忆化的边权好工具!(废话用edges存边了还不是当然的) 代码: /* ID :ggy_7781 TASK :hamming LANG :C++11 */ #include <bits/stdc++.h> #define maxB 8 #define maxN 64 #define maxD 7 using namespace std; int N,B,

基本的RAID介绍

RAID是一个我们经常能见到的名词.但却因为很少能在实际环境中体验,所以很难对其原理 能有很清楚的认识和掌握.本文将对RAID技术进行介绍和总结,以期能尽量阐明其概念. RAID全称为独立磁盘冗余阵列(Rdeundant Array of Independent Disks),基本思想就是把 多个相对便宜的硬盘组合起来,成为一个硬盘阵列组,使性能达到甚至超过一个价格昂贵. 容量巨大的硬盘.RAID通常被用在服务器电脑上,使用完全相同的硬盘组成一个逻辑扇区, 因此操作系统只会把它当做一个硬盘. R

《大话存储2》读书笔记——第4章 北斗七星 大话/详解7种RAID

转自于:http://www.cnblogs.com/jfzhu/p/3999283.html http://www.cnblogs.com/xiaoluo501395377/archive/2013/05/25/3099464.html https://msdn.microsoft.com/en-us/library/ms190764.aspx http://blog.csdn.net/ronmy/article/details/5819270 传统磁盘的劣势 我们知道一台PC机种都会包含CP

RAID基本知识

RAID是英文Redundant Array of Independent Disks(独立磁盘冗余阵列),简称磁盘阵列.下面将各个级别的RAID介绍如下. 一.为什么使用Raid? 1.对磁盘高速存取(提速): RAID将普通硬盘组成一个磁盘阵列,在主机写入数据,RAID控制器把主机要写入的数据分解为多个数据块,然后并行写入磁盘阵列:主机读取数据时,RAID控制器并行读取分散在磁盘阵列中各个硬盘上的数据,把它们重新组合后提供给主机.由于采用并行读写操作,从而提高了存储系统的存取速度. 2.扩容

Here’s just a fraction of what you can do with linear algebra

Here’s just a fraction of what you can do with linear algebra The next time someone wonders what the point of linear algebra is, send them here. I write a blog on math and programming and I see linear algebra applied to computer science all the time.

1.4 非数值信息及编码

1. 十进制数常用代码 十进制数常用代码有 8421BCD 码.余 3 码.格雷码等.编码原则是将十进制的 0-9 这 10 个基数字,每个都用 4 位的二进制码来代替所形成的代码,见表 1-30. (1)8421BCD 码的形成 8421BCD 码是一种有权码,它将 4 位二进制码由左至右,即由高位到低位依次赋予 8.4.2.1,即 为权. 从一位的基数字与 8421BCD 码的对应关系看,与十进制数转换成二进制数是一样的.但是,若是两位的基数字就不是这种关系了.例如,32 所对应的编码为 0

Linux学习笔记——RAID

RAID 独立硬盘冗余阵列(RAID, Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列(Redundant Array of Inexpensive Disks),简称磁盘阵列. 分为RAID-0,RAID-1,RAID-2,RAID-3,RAID-4,RAID-5,RAID-6,RAID-7,RAID-10,RAID-50,RAID-60.其中RAID-0,RAID-1,RAID-2,RAID-3,RAID-4,RAID-5,RAID-6为标准

RAID简介

作者:Danbo 时间:2015-7-28 RAID是Redundant Array Inexpensive of Disks RAID(磁盘阵列,Redundant Arrays of Inexpensive Disks)容错式廉价磁盘阵列.RAID可以透过软件或硬件将较小的磁盘整合成为一个较大的磁盘装置.RAID0RAID0又称为strpping(条带)它将两个以上的并联起来,成为一个大容量的磁盘.当存取数据时,分段后分散存储在这些磁盘当中,RAID0的读取速度是最快的,但是RAID0没有提