by Neal R. Wagner
Copyright © 2001 by Neal R. Wagner. All rights reserved.
NOTE: This site is obsolete. See book draft (in PDF):
Here is a Java program that prints a table of channel capacities and corresponding channel probabilities. (The function calculating the inverse of the channel capacity function is given in boldface.)
// CapInv2.java: print table of inverse capacities
// p: the channel probability for a binary symmetric channel
import java.text.DecimalFormat;
public class CapInv2 {
static final int TABLE_SIZE = 20;
static DecimalFormat eightDigits = new DecimalFormat("0.00000000");
// main function to do calculation
public static void main (String[] args) {
double p; // channel probability
double c; // channel capacity
System.out.println("<table border>");
System.out.println("<tr align=center><td><b>Channel<br>Capacity</b></td>");
System.out.println("<td><b>Probability<br>p</b></td>");
System.out.println("<td><b>Probability<br>1 - p</b></td></tr>");
System.out.println("<tr><td></td><td></td></tr>");
for (int i = 0; i <= TABLE_SIZE; i++) {
c = (double)i/TABLE_SIZE;
System.out.print("<tr><td>" + c);
if ((int)(10*c) == 10*c) System.out.print("0");
System.out.print("</td><td>" +
eightDigits.format(capacityInverse(c)) + "</td>");
System.out.println("</td><td>" +
eightDigits.format(1 - capacityInverse(c)) + "</td></tr>");
}
System.out.println("</table>");
} // end of main
// capacity: the capacity of the binary symmetric channel
private static double capacity(double p) {
if (p == 0 || p == 1) return 1;
return 1 + p*log2(p) + (1 - p)*log2(1 - p);
}
// capacityInverse: the inverse of the capacity function
// uses simple bisection method
private static double capacityInverse(double c) {
if (c < 0 || c > 1) return -1;
double lo = 0, hi = 0.5, mid, cLo, cHi, cMid;
do {
mid = (lo + hi)/2;
cLo = capacity(lo); cHi = capacity(hi); cMid = capacity(mid);
if (c > cMid) hi = mid;
else lo = mid;
} while (hi - lo > 1.0E-15);
return mid;
}
// log2: Logarithm base 2
public static double log2(double d) {
return Math.log(d)/Math.log(2.0);
}
}
| Channel Capacity |
Probability p |
Probability 1 - p |
| 0.00 | 0.50000000 | 0.50000000 |
| 0.05 | 0.36912775 | 0.63087225 |
| 0.10 | 0.31601935 | 0.68398065 |
| 0.15 | 0.27604089 | 0.72395911 |
| 0.20 | 0.24300385 | 0.75699615 |
| 0.25 | 0.21450174 | 0.78549826 |
| 0.30 | 0.18929771 | 0.81070229 |
| 0.35 | 0.16665701 | 0.83334299 |
| 0.40 | 0.14610240 | 0.85389760 |
| 0.45 | 0.12730481 | 0.87269519 |
| 0.50 | 0.11002786 | 0.88997214 |
| 0.55 | 0.09409724 | 0.90590276 |
| 0.60 | 0.07938260 | 0.92061740 |
| 0.65 | 0.06578671 | 0.93421329 |
| 0.70 | 0.05323904 | 0.94676096 |
| 0.75 | 0.04169269 | 0.95830731 |
| 0.80 | 0.03112446 | 0.96887554 |
| 0.85 | 0.02153963 | 0.97846037 |
| 0.90 | 0.01298686 | 0.98701314 |
| 0.95 | 0.00560717 | 0.99439283 |
| 1.00 | 0.00000000 | 1.00000000 |