#!/usr/local/bin/perl -w # modified from extract_ebno.p (NOT FINISHED) # --- shouldbe used with the seed as part of the code name so as to # make graphs comparable. # reads data files and works out confidence interval for MNC performance and makes graph # of p versus EbNo # March 22 96 # $directory = "/home/mackay/_doc/code/rmncN" ; $fudge="0"; # set fudge=0.90 to get it to look for fudge files $read_directory = "/home/mackay/code/rFGC" ; $write_directory = "/home/mackay/_doc/code/rFGC" ; $codename = "15000.10000.3.0.1523" ; $indivsymbol = "# " ; $finalsymbol = "" ; $latex_print_C = 1 ; $latex_printt = 0 ; $latex_printlower = 0 ; $latex_print_fn = 0 ; $lowerbound = 1e-06; $findmean = 1 ; $z_score = 2.0 ; $sigma = 1.0; $small_number_loops = 100 ; $verbose = 0 ; $clobber = 1 ; eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; if ( $fudge == 0 ) { $thiscodefile = $write_directory."/".$codename ; } else { $thiscodefile = $write_directory."/".$codename.".".$fudge ; } print STDERR "# writing $thiscodefile\n" ; if ( $clobber ) { open ( OUT , "> $thiscodefile" ) || print STDERR "failed\n" ; } else { open ( OUT , ">> $thiscodefile" ) || print STDERR "failed\n" ; } close ( OUT ) ; $very_first_time = 1 ; foreach $x (@ARGV) { # now $x has the role of an ASSUMED $mncfile = $thiscodefile.".".$x ; print STDERR "# writing $mncfile\n" ; open ( OUT , "> $mncfile " ) || print STDERR "failed\n" ; $first_time = 1 ; # # search for files with relevant reports # if ( $fudge == 0 ) { open ( IN , "ls $read_directory/$codename.*.$x | " ) ; } else { open ( IN , "ls $read_directory/$codename.*.$fudge.$x | " ) ; } # pipes us the names of files ; $numpoints = 0 ; $totbitswrong = 0 ; $toterrors = 0 ; $tot_undetected_errors = 0 ; $tot_undetected_bits = 0 ; $tottrials = 0 ; $totsumloops = 0 ; # for combining results (on assumption that it's appropriate) # - i.e. same N and t and maxloops while ( $r = ) { $numpoints ++ ; print STDERR "# reading $r" ; open ( R , "< $r" ) ; $dont_know_maxloops = 1 ; $maxloops = 0 ; $sumloops = 0 ; $bitswrong = 0 ; $undetected_bits = 0 ; $undetected_errors = 0 ; $line = 0 ; while ( ) { $last = $_ ; $line ++ ; if ( $dont_know_maxloops || $findmean ) { s/^\s*// ; if ( !/^#/ ) { @a = split ; if ( $dont_know_maxloops ) { if ( $maxloops < $a[23] - 1 ) { $maxloops = $a[23] - 1 ; # } # } if ( $a[0] != "0" ) { # it is a failure $bitswrong += $a[0] ; # used for finding mean bit error rate if ( $a[3] != "0" ) { # then this was a flagged error (viols detected) $dont_know_maxloops = 0 ; # and we do know maxloops now. if ( $a[23] < $small_number_loops ) { print STDERR "warning, $a[23] loops only! line $line\n" ; } } else { # an undetected error - bad! $undetected_errors ++ ; $undetected_bits += $a[0] ; } } else { $sumloops += $a[23] - 1 ; # for mean number of loops } } } } $_ = $last ; s/^\s*// ; @a = split ; $errors = $a[25] ; $trials = $a[24] ; $toterrors += $errors ; $tottrials += $trials ; $totbitswrong += $bitswrong ; $totsumloops += $sumloops ; $tot_undetected_bits += $undetected_bits ; $tot_undetected_errors += $undetected_errors ; $t = $a[6] ; $Nnmn = $a[5] ; $Knmn = $a[4] ; $N = $Nnmn + $Knmn ; # "L" $K = $N - $Nnmn ; # $f = $a[7] ; $R = sprintf ( "%6.4g" , $K / $N ) ; &find_ebs_and_print ( 0 ) ; $first_time = 0 ; } if ($numpoints>0 ) { # last time round, aggregate all info together: $undetected_errors = $tot_undetected_errors ; $undetected_bits = $tot_undetected_bits ; $bitswrong = $totbitswrong ; $trials = $tottrials ; $errors = $toterrors ; $sumloops = $totsumloops ; &find_ebs_and_print ( 1 ) ; close ( OUT ) ; open ( OUT , ">> $thiscodefile" ) || print STDERR "failed\n" ; &find_ebs_and_print ( 2 ) ; $very_first_time = 0 ; } } # sub find_ebs_and_print { # this routine looks at the global variables $errors and $trials # and computes a confidence interval and maximum likelihood value. # these are called $blep_lower and $blep_upper, and $blep_point (ML value) # the size of the interval is dictated by $zscore, e.g. 2.0 # # [a value called $blockep is also computed, which is the point to plot # if one wants a plot which just shows point estimates. # this is not currently used in the paper, Sep 30 95] # # a bit error probability is also computed, $bitep, by looking at the # global variables $bitswrong and $N # local ( $arg ) = @_ ; # typesetting $symbol = $arg ? $finalsymbol : $indivsymbol ; # $Neff = ( $errors == 0 ) ? 1 : $errors ; # make the point $blockep = $Neff / $trials ; # estimate $blockep # # Confidence interval # if ( $errors == 0 ) { $blep_point = $lowerbound ; $blep_lower = $lowerbound ; $blep_upper = 1.0 - exp( - 2.0 / $trials ) ; $factor = $blep_upper / $blep_point ; } else { $blep_point = $errors / $trials ; # factor corresponding z sd's in log p $factor = exp ( $z_score * sqrt( ($trials - $errors ) / ( $errors * $trials ) ) ) ; # this is a lot like sqrt( $errors ) $blep_upper = $blep_point * $factor ; $blep_lower = $blep_point / $factor ; } # # end of confidence interval bit # $bitep = $bitswrong / ( $trials * $N ) ; $biep_lower = $bitep / $factor ; $biep_upper = $bitep * $factor ; $R = $K / $N ; $ebno = $x * $x / ( 2.0 * $R * $sigma * $sigma ) ; $logEb = 10.0 * log ( $ebno ) / log (10.0) ; $C = 0.5 * log ( 1.0 + $x * $x / ( $sigma * $sigma ) ) / log ( 2.0 ) ; # limitting value of x^2/sigma^2 $x2s_lim = exp ( 2 * $R * log (2.0)) - 1 ; $ebno_lim = $x2s_lim / ( 2.0 * $R ) ; $logEbno_lim = 10.0 * log ( $ebno_lim ) / log (10.0) ; $d = $logEb - $logEbno_lim ; if ( $verbose ) { printf "# x2s_lim = %9.4g\n" , $x2s_lim ; printf "# ebno_lim = %9.4g\n" , $ebno_lim ; printf "# logEbno_lim = %9.4g\n" , $logEbno_lim ; } # the above is from bernebno.p if ( ( $arg == 2 && $very_first_time == 1 ) || $first_time == 1 || $arg == 1 ) { print OUT "# ebno (dB) distance C R x errors trials undet blep point upper lower bitsw undet bitep:point upper lower maxloops mean_lps K N\n" ; } printf OUT "%s%-7.4g %7.4g %7.4g %7.4g %7.4g %5.4g " , $symbol, $ebno, $logEb , $d , $C , $R , $x ; # printf OUT "%-4s %6s %4s " , $errors, $trials , $undetected_errors ; printf OUT "%9.4g %9.4g %9.4g %9.4g ", $blockep, $blep_point , $blep_upper , $blep_lower ; printf OUT " %6d %5d %9.4g %9.4g %9.4g %4d " , $bitswrong, $undetected_bits , $bitep , $biep_upper , $biep_lower , $maxloops ; if ( $findmean && ( $trials - $errors > 1 ) ) { $factory = 1 / ($trials - $errors) ; } else { $factory = 1 ; } printf OUT "%8.4g " , $sumloops * $factory ; printf OUT "%6d " , $K ; printf OUT "%6d " , $N ; print OUT "\n" ; if ( $arg == 1 ) { # print some latex stuff too printf STDERR # "%s%5s/%5s & %7.4g " , # " ", $K,$N, $R ; if ( $latex_printt ) { # printf STDERR "& %s " , $t ; # } if ( $latex_print_fn ) { # printf STDERR "& %s " , $x ; # } if ( $latex_print_C ) { printf STDERR "& %8.3g " , $C ; } printf STDERR "& %4s & %4s " , $errors, $trials ; if ( $findmean ) { printf STDERR "& %8.3g " , $sumloops * $factory ; } printf STDERR "& %8.3g & %8.3g " , $blep_point , $blep_upper ; if ( $latex_printlower ) { printf STDERR "& %8.3g ", $blep_lower ; } printf STDERR "& %8.3g & %8.3g " , $bitep , $biep_upper ; if ( $latex_printlower ) { printf STDERR "& %8.3g ", $biep_lower ; } print STDERR "\\\\ \n" ; } } #