#!/usr/local/bin/perl -w # concatenates hamming codes together and reports the error probability # usage # concath.p f=0.001 fmax=0.2 fsteps=10 > itp/hamming/concath # !concath.p f=0.02 fmax=0.08 fsteps=10 > concath $mmin = 2 ; # 2 means start with repetition code. 3 means (7,4) first $mmax = 12 ; $f=0.01; $fmax=0.1; $fsteps=2; $spacer = "" ; $endline = "\n" ; $comment = "#" ; $bitfraction = 1.0 ; # fraction of bits that are wrong in an error block # (about 3/7 for (7,4)) $bit3fraction = 1.0 ; # fraction of bits that are wrong when R3 makes # an error. eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; if ( $f < 0 ) { print STDERR "You must supply f\n" ; &print_usage (); exit(0); } sub print_usage { print STDERR " concath.p f=0.001 fmax=0.2 fsteps=10\n" ; } if ($fsteps > 1 ) { # $ffactor = exp ( log($fmax/$f) / ($fsteps-1) ) ; } else { $ffactor = 1 ; } for ( ; $fsteps >= 1 ; $fsteps -- , $f *= $ffactor ) { $pb = $f ; $R = 1.0 ; $dmin = 1 ; $N = 1.0 ; $dfrac = $dmin/$N ; $A = 1.0 ; # number of lowest weight codewords. printf "%s \n" , $comment ; printf "%s f = %10.4g\n" , $comment , $f ; printf "%s \n" , $comment ; printf "%s its m n k R f pb dmin N dmin/N\n" , $comment ; printf "%s \n" , $comment ; $steps = 0 ; $n=1;$k=1; for ($m = $mmin ; $m <= $mmax+1 ; $m ++ ) { printf "%3d %s", $steps , $spacer ; printf "%3d %s", $m , $spacer ; printf "%4d %s", $n , $spacer ; printf "%4d %s", $k , $spacer ; printf "%8.5f %s", $R , $spacer ; printf "%10.4g %s", $f , $spacer ; # printf "%10.4g %s", log($f) , $spacer ; printf "%10.4g %s", $pb , $spacer ; # printf "%10.4g %s", $pb , $spacer ; printf "%10.4g %s", $dmin , $spacer ; printf "%10.4g %s", $N , $spacer ; printf "%10.4g %s", $A , $spacer ; printf "%10.4g %s", $dfrac , $spacer ; printf "%s" , $endline ; # printf "%10.4g %s", log($pb) , $endline ; $steps ++ ; # if ( $m <= $mmax ) { $n = 2**$m - 1 ; $k = $n - $m ; $t = 1 ; $r = $k/$n ; $R = $R * $r ; $dmin *= 3 ; # minimum distance $A *= $m * ($m-1) / 2 ; $N *= $n ; # overall concatenated block length $dfrac = $dmin/$N ; if ( $n == 3 ) { $bitf = $bit3fraction ; } else { $bitf = $bitfraction ; } $pb = $bitf * &say_pe( $pb , $n , $k , $t ) ; } } printf "\n" , $comment ; } sub say_pe { # usage ( p , n , k , t ) local($p,$n,$k,$t) = @_ ; # returns the prob of block error, i.e. # prob(more than t errors | n , p) # $printp=0 ; # $brief = 0 ; # $latex=1; $v = 0 ; # verbose $cum = 0.0 ; $q = 1.0 - $p ; $factor = 1 ; for ( $i = $n , $j = 0 ; $i > $t ; $i-- , $j++ ) { $pr = $factor * $p**$i * $q**$j ; $cum += $pr ; if ($v) { printf "%4d %4d %9.3g %9.4g %9.4g\n", $i , $j, $factor, $pr , $cum ; } $factor *= $i / ($j+1) ; } # # if ( !$brief ) { printf "%4d " , $n ; } # if ( !$brief ) { printf "$spacer %3d " , $k ; } # if ( !$brief ) { printf "$spacer %3d " , $t ; } # if ( $printp ) { printf "$spacer %9.5f ", $p ; } # printf "$spacer %13.4g ", $cum ; # if ( !$brief ) { printf "$spacer %9.5f ", ($k/$n) ; } # print "\\\\ " if ( $latex ) ; # print " \n" ; return $cum ; # }