#!/usr/local/bin/perl -w # reads BD (block detected error) # from command line and returns the dB credit that the code needs # in order to become a perfect channel # computes the credit assuming God's coding abilities to get rid # of the remaining errors, and using other models $bd = 0.0 ; # frequency with which blocks are labelled as "?". $fd = 0.5 ; # fraction of bits in a 'detected error (?)' that are bad. $fu = 0.0 ; # fraction of bits in the passed stream that are bad. # eg Gallager code # credit.p fu=0.0 fd=0.1 bd=0.001 # turbo code # credit.p fu=0.0001 bd=0 # # Gallager code # credit.p fu=0.0 fd=0.0129 bd=0.000367 # turbo code # credit.p fu=0.00001 bd=0 eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; $Capacity = 1.0 - ( (1.0-$bd) * &H2($fu) + $bd * &H2($fd) ) ; $pb = $fu * (1.0-$bd) + $fd * $bd ; $logC = - 10.0 * log( $Capacity ) / log ( 10.0 ) ; printf "# prob(bit) = %9.4g\n" , $pb ; printf "# Capacity = %9.4g\n" , $Capacity ; printf "# dB cost: %9.4g\n" , $logC ; print "\n" ; sub H2 { # binary entropy # usage ( $f ) local ( $f ) = @_ ; local ( $ans ) = - ( $f * &safelog ( $f ) + (1.0 - $f) * &safelog (1.0 - $f ) ) ; return $ans / log(2.0); } sub safelog { local ($f) = @_ ; if ( $f < 0 ) { print STDERR "Can't take log of $f\n" ; } return ( $f > 0 ? log ( $f) : 0.0 ) ; }