#!/usr/local/bin/perl -w # # for a code with minimum distance d, computes a lower bound on the # error probability for a BSC or for a GC # # derived from # say_pe2.p # see also _doc/code/say_pe.p # and _doc/code/perl.bch # and _doc/code/perl.tmp # # General: # # This reads n,t,k from command line and writes a file # with # # x Eb/No p_bit(raw) p_block(out) and maybe Berlekamp's p_bit also. # # usage: # /home/mackay/code/EN: ~/_doc/code/perl.com0 # NB: all performance curves assume hard output from BSC from gaussian channel $prefix="dist/" ; $d = 11 ; $n = 63 ; $k = 3 ; # only used to compute the rate $t = 5 ; $A = 1 ; # number of words of smallest weight # $ffrom=0.0001; $fto =0.4; $xfrom=0.3; $xto=12.0; $num=50; $xfactor=1; $spacer="&"; $latex=0; $gnu = 0 ; # whether to write stuff to the gnu files $v = 0 ; # verbose $headings = 1 ; #! say_peBound.p n=3 k=1 d=3 #! say_peBound.p n=1 k=1 d=1 # agrees just fine with the AHA curves. #! say_peBound.p n=7 k=4 d=3 #! say_peBound.p n=32000 k=27200 d=9 gnu=1 # aha code: (TPC) #! say_peBound.p n=4096 k=3249 d=9 gnu=1 # # How to override min and max values with command line eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=([^\s]+)/ && shift; ##################################### if ( !$latex ) { $spacer = "\t" ; } ############# code properties $t = int(($d+1)/2.0) ; print STDERR "d=$d -> t=$t\n" ; # value computed is not used # if ($A==1) { # overwrite this with a sensible guess, the Hamming code $A = $n * ($n-1) ; # this overcounts because every word is made 6 times $A = $n * ($n-1)/6 ; # $nn = sqrt($n) ; if (($d==9) || ($d==16)) { # or maybe go for the product code version! $A = $nn * ($nn-1) / 6 ; $A = $A * $A ; } # elseif ($d==16) { # extended hamming code print STDERR "A($d) = $A\n" ; } $R = sprintf "%.5f", ($k*1.0/$n) ; $Rshort = sprintf "%.2f", ($k*1.0/$n) ; # $Rvshort = sprintf "%.1f", ($k*1.0/$n) ; ############# $filename = "$prefix$n.$k.$d.$Rshort" ; $filename =~ s/\s*//g ; print STDERR "# writing to $filename\n" ; open ( O , "> $filename" ) ; ############# if ( $headings ) { printf O "\# Lower bound on Error versus channel noise for (n=$n, k=$k, t=$t, d=$d, R=$R) code \n" ; printf O "\# assuming optimal decoding and errors caused by one word at distance d only\n"; if ( 1 ) { printf O "\# x $spacer (Eb/No)/dB " ; } if ( 1 ) { printf O " $spacer BoundPB-Block " ; } if ( 1 ) { printf O " $spacer BoundPb-bit " ; } if ( 1 ) { printf O " $spacer BoundPB-union " ; } if ( 1 ) { printf O " $spacer BoundPb-union " ; } printf O "\n" ; } ########################################## # create list of tail areas using erftail if ( $num == 1 ) { $xfrom = $x ; } else { $xfactor=exp( (log ( $xto / $xfrom ) )/ ($num-1.0) ) ; } $x = $xfrom ; for ( $a = 1 ; $a <= $num ; $a++ , $x *= $xfactor ) { $x = sprintf("%10.4g",$x) ; $xx = sprintf("%10.4g",$x*sqrt($d)) ; # get p from x $command = "cd /home/mackay/itp/octave ; erftail $xx" ; open ( E , "$command |" ) ; $_ = ; $p = $_ ; print "x = $x -> p_B >= $p\n" if ( $v ) ; $pbiterrorbound = $p * $d / $n ; $ebno = $x * $x / ( 2.0 * $R ) ; $ebno = 10.0 * ( log ( $ebno ) / log (10.0) ) ; $ebno = sprintf("%10.4g",$ebno) ; if ( 1 ) { printf O "%s ", $x ; } if ( 1 ) { printf O "$spacer %s ", $ebno ; } printf O "$spacer %9.5g ", $p ; printf O "$spacer %9.5g ", ( $pbiterrorbound ) ; printf O "$spacer %9.5g ", $p*$A ; printf O "$spacer %9.5g ", ( $A * $pbiterrorbound ) ; printf O "\n" ; } # if ( $gnu ) { print STDERR "writing to gnu/textbook/pB.dist.R$Rshort\n" ; open ( G , ">> gnu/textbook/pB.dist.R$Rshort" ) ; print G "# pblock vs ebno " ; print G "# gnuplot\n set logs y\n" ; print G "plot '$filename' u 2:3 t 'pBlock bound $n,$k,$d' w l \\\n" ; print G ", '$filename' u 2:4 t 'pbit bound $n,$k,$d' w l\n" ; close(G) ; } sub safelog { local($x)=@_; if ($x>0.0) { return log($x) ; } else { print STDERR "SL: can't take log of $x\n" ; return 0.0 ; } }