zzw_rst 发表于 2023-3-21 18:39

看不懂这个汉明码 解码器代码?

<p>疑惑如<span style="color:#c0392b;">红色字体</span>注释,非常需要大家的帮助,谢谢了。</p>

<p>&nbsp;</p>

<p>module Vrhamcorr64(DU, DC, NOERROR, UCERR);<br />
&nbsp; input DU;<br />
&nbsp; output reg DC;<br />
&nbsp; output reg NOERROR, UCERR;<br />
&nbsp; integer syndrome ;<br />
&nbsp;&nbsp;<br />
&nbsp; reg C ; &nbsp; &nbsp;// Constants for parity-check matrix<br />
&nbsp; integer b, e, i, col;<br />
&nbsp; reg syn;<br />
&nbsp; reg SYND;</p>

<p>initial begin<br />
&nbsp; C = 72&#39;h80000000000000007f; C = 72&#39;h400000003fffffff80;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:#c0392b;">C应该是校验矩阵</span><br />
&nbsp; C = 72&#39;h20001fffc0007fff80; C = 72&#39;h100fe03fc07f807f80;<br />
&nbsp; C = 72&#39;h0871e3c3c78787878f; C = 72&#39;h04b66cccd9999999b3;<br />
&nbsp; C = 72&#39;h02dab5556aaaaaaad5; C = 72&#39;hffffffffffffffffff;<br />
&nbsp; for (i=0; i&lt;=255; i=i+1) syndrome = -1; // Initialize syndrome array to invalid&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#c0392b;">syndrome是一个变量么?比如说和输入A,B差不多,但是syndrome有syndrome,syndrome,syndrome,一般来说变量位数是固定的,不懂为什么syndrome有3种?=-1也不是很理解。</span><br />
&nbsp; for (col=0; col&lt;=71; col=col+1) begin // Populate valid syndromes&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#c0392b;">不是很懂initial语句,定义常数矩阵如上面那样列出来应该可以了吧,而且涉及的变量也很多,不知道这两个for语句是拿来干嘛的?</span><br />
&nbsp; &nbsp; for (e=1; e&lt;=8; e=e+1) syn = C;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#c0392b;">没见过变量后面跟两个[],不知道是什么东东?</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br />
&nbsp; &nbsp; syndrome = col;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#c0392b;">syndrome和syndrome有什么关系么,下面的语句好像没用到syndrome?<br />
&nbsp;</span> end<br />
end</p>

<p>always @ (DU) begin<br />
&nbsp; DC = DU;<br />
&nbsp; for (b=0; b&lt;=7; b=b+1) SYND = ^(C &amp; DU); &nbsp;// Calculate received syndrome&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#c0392b;">应该是输出码字*校验矩阵,然后异或,得出8个等于0的等式</span><br />
&nbsp; &nbsp; NOERROR = 1&#39;b1; UCERR = 1&#39;b0; &nbsp; &nbsp; &nbsp; &nbsp; // Default values, no errors<br />
&nbsp; &nbsp; if (SYND==8&#39;b0) ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // No errors<br />
&nbsp; &nbsp; else if (syndrome&lt;0) begin NOERROR = 1&#39;b0; UCERR = 1&#39;b1; end &nbsp; &nbsp; &nbsp; &nbsp; // Uncorrectable&nbsp; &nbsp; &nbsp;<span style="color:#c0392b;">对syndrome已经懵圈,二进制计算怎么会&lt;0呢?虽然说上面那个是定义=-1。如果纠不了错,应该是出现2位以上的错,SYND[]出现了和1位出错一样的数(或者说是SYND[]还是等于0),这条语句是怎么分辨出是1位出错还是多位出错的?</span><br />
&nbsp; &nbsp; else if (SYND!=1&#39;b1) begin NOERROR = 1&#39;b0; UCERR = 1&#39;b1; end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Uncorrectable&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color:#c0392b;">SYND应该是全奇偶校验位,=1的时候只能指示每一位都可能是出错位,但不能纠错</span><br />
&nbsp; &nbsp; else begin NOERROR = 1&#39;b0; &nbsp;DC] = ~DU]; end &nbsp;// Correctable<span style="color:#c0392b;">剩下应该是其他1位出错的,找到出错位然后按位取反纠错。</span><br />
&nbsp; end<br />
endmodule</p>

huo_hu 发表于 2023-3-22 13:36

<p>汉明码很久以前明白过</p>

<p>verlong稍微懂一点</p>

zzw_rst 发表于 2023-3-22 14:24

huo_hu 发表于 2023-3-22 13:36
汉明码很久以前明白过

verlong稍微懂一点

<p>纠一位出错可以理解,else if (syndrome&lt;0) begin NOERROR = 1&#39;b0; UCERR = 1&#39;b1; end &nbsp; &nbsp; &nbsp; &nbsp; // Uncorrectable你帮忙看一下这条语句是怎么分辨出是非1位出错的,因为SYND计算我觉得是不可能=-1的,说一下具体流程。</p>
页: [1]
查看完整版本: 看不懂这个汉明码 解码器代码?