%!PS-Adobe-2.0
%%Pages: 0 1
%%BoundingBox: 0 0 612 792
%%EndComments
% Shannon's Random Codes, P = 0.75, blocksize = 5, 10, 15, 20
1 setlinewidth
/Red{0 1 1 0 setcmykcolor}def
/Blue{.6 .6 0 0 setcmykcolor}def
/Green{1 0 1 0 setcmykcolor}def
/Black{0 0 0 1 setcmykcolor}def

/inch { 72 mul } def

/p20 {
[ 0.0 -99.99   0.4 -99.99   0.8 -99.99   1.2 -99.99 
  1.6 -99.99   2.0  97.60   2.4  93.60   2.8  89.00 
  3.2  81.30   3.6  75.60   4.0  65.80   4.4  56.30 
  4.8  49.10   5.2  38.8    5.6  32.7    6.0  24.5 
  6.4  19.76   6.8  15.25   7.2  10.7    7.6   7.76 
  8.0   5.62   8.4   3.9    8.8   2.4    9.2   1.70 
  9.6   1.20  10.0   0.70  10.4 -99.99  10.8 -99.99 
 11.2 -99.99  11.6 -99.99  12.0 -99.99  12.4 -99.99 
 12.8 -99.99  13.2 -99.99  13.6 -99.99  14.0 -99.99
 14.4 -99.99  14.8 -99.99  15.2 -99.99  15.6 -99.99
 16.0 -99.99  16.4 -99.99  16.8 -99.99  17.2 -99.99
 17.6 -99.99  18.0 -99.99  18.4 -99.99  18.8 -99.99
 19.2 -99.99] 
} def

/p15 {
[ 0.0000 -99.99   0.5333 100.00 
  1.0667  99.375  1.6000  97.43
  2.1333  92.82   2.6667  86.36 
  3.2000  77.15   3.7333  67.41 
  4.2667  56.08   4.8000  46.05 
  5.3333  36.26   5.8667  28.18 
  6.4000  21.00   6.9333  15.47 
  7.4667  11.036  8.0000   7.935 
  8.5333   5.7    9.0667   3.743 
  9.6000   2.549 10.1333   1.711 
 10.6667   1.128 11.2000   0.716 
 11.7333   0.443 12.2667   0.275
 12.8000   0.177 13.3333   0.105 
 13.8667   0.08  14.4000   0.06 
 14.9333   0.04  16.4667   0.02
 17.0000   0.009 17.5333 -99.99] 
} def

%%% below pdd is data for blocksize = dd
/p10 {
[ 0.0 -99.99   0.8  99.83   1.6  93.30   2.4  82.99 
  3.2  69.93   4.0  56.30   4.8  43.41   5.6  32.22 
  6.4  23.16   7.2  16.29   8.0  11.11   8.8   7.435 
  9.6   4.85  10.4   3.13  11.2   1.99  12.0   1.25 
 12.8   0.764 13.6   0.49  14.4   0.29  15.2   0.17 
 16.0   0.104 16.8   0.062 17.6   0.0376 18.4   0.0217 
 19.2   0.0127 20.0 -99.99  20.8 -99.99  21.6 -99.99 
 22.4 -99.99]
} def

/p5 {
[ 0.0 -99.99   1.6  81.89   3.2  59.09   4.8  40.53 
  6.4  26.63   8.0  16.09   9.6  10.22  11.2   6.17 
 12.8   3.66  14.4   2.13  16.0   1.303 17.6   0.72 
 19.2   0.414 20.8   0.246 22.4   0.13  24.0 -99.99 
 25.6 -99.99  27.2 -99.99  28.8 -99.99]
} def 

%% fetch for the array and push two successive points on graph
/plotpts { % stack: array startindex endindex
  /endindex exch def
  /startindex exch def
  /arr exch def
  startindex 2 endindex {
     /ind exch def
     arr ind get
     arr ind 1 add get
     arr ind 2 add get
     arr ind 3 add get
     plotline
  } for
} def

/xscale {
   6.5 inch mul 24 div
} def

/yscale {
   9 inch mul 100 div
} def

%% plot the line joining two successive points
/plotline { % stack: x1 y1 x2 y2  (coordinates to plot)
    /y2 exch def
    /x2 exch def
    /y1 exch def
    /x1 exch def
    newpath
    x1 xscale y1 yscale moveto
    x2 xscale y2 yscale lineto
    stroke
} def

/Str3 3 string def % string for conversions (see BlueBook, pp. 71-2)

/PlotAxes {
  % faint horizontal and vertical lines
  % first the faint horizontal lines
  0.8 setgray
  0 6.5 inch 12 div 6.5 inch { 0 moveto 0 9 inch rlineto stroke} for

  % then the faint vertical lines
  0 9 inch 10 div 9 inch { 0 exch moveto 6.5 inch 0 rlineto stroke} for
  0 setgray

  % x and y axes, tick marks along axes
  -5 0 moveto 6.5 inch 0 lineto stroke  % x axis
  0 -5 moveto 0 9 inch lineto stroke 5 % y axis
  0 6.5 inch 12 div 6.5 inch { -5 moveto 0 5 rlineto stroke} for
  0 9 inch 10 div 9 inch { -5 exch moveto 5 0 rlineto stroke} for

  /Helvetica findfont 12 scalefont setfont

  % numbers along x (horizontal) axis
  0 6.5 inch 12 div 6.5 inch {
     /forvar exch def
     forvar  -10 add -16 moveto
     forvar 6.5 inch div 24 mul cvi
     %% next line: ugly patch to center horizontal numbers
     dup Str3 cvs stringwidth pop 2 div neg 10 add 0 rmoveto  
     Str3 cvs show
  } for

  % along y (vertical) axis
  0 9 inch 10 div 9 inch {
     /forvar exch def
     -27 forvar -5 add moveto
     forvar 9 inch div 100 mul 0.01 add cvi
     %% next line: ugly patch to right justify vertical numbers
     dup Str3 cvs stringwidth pop neg 20 add 0 rmoveto
     Str3 cvs show
  } for

  % labels on axes
  150 -30 moveto (Codeword Size (1 = Source Size)) show

  /Helvetica-Bold findfont 11 scalefont setfont
  115 -45 moveto
  Red
  (Figure 4.1 ) show
  /Helvetica findfont 11 scalefont setfont
  (Simulation of Shannon's Random Codes) show
  /Helvetica findfont 12 scalefont setfont
  Black
  gsave 90 rotate 200 40 moveto (Error Rate (%)) show grestore

  % dashed line for channel capacity
  newpath 6.5 inch 24 div 0.18872 div 0 moveto
  0 9 inch 0.8 mul rlineto 
  gsave [2 8] 0 setdash stroke grestore

  % header for table
  /Helvetica-Bold findfont 18 scalefont setfont
  0.15 inch 9.35 inch moveto (Figure 4.1.  Simulation of Shannon's Random Codes) show
  /Helvetica-Bold findfont 14 scalefont setfont
  2 inch 9.1 inch moveto ((Error Probability = 0.25)) show

  % legend at upper right of graph
  /Helvetica-Bold findfont 12 scalefont setfont
  Red 1 inch 8 inch moveto (Blocksize = 20,) show
  Red 2.3 inch 8 inch moveto (Tablesize = 1048576,) show
  Red 4.3 inch 8 inch moveto (Trials = 10000 @ 30 points) show
  Blue 1 inch 8.2 inch moveto (Blocksize = 15,) show
  Blue 2.3 inch 8.2 inch moveto (Tablesize = 32768,) show
  Blue 4.2 inch 8.2 inch moveto (Trials = 100000 @ 26 points) show
  Green 1 inch 8.4 inch moveto (Blocksize = 10,) show
  Green 2.3 inch 8.4 inch moveto (Tablesize = 1024,) show
  Green 4.1 inch 8.4 inch moveto (Trials = 1000000 @ 24 points) show
  Black 1 inch 8.6 inch moveto (Blocksize = 5,) show
  Black 2.3 inch 8.6 inch moveto (Tablesize = 32,) show
  Black 4.0 inch 8.6 inch moveto (Trials = 10000000 @ 14 points) show

  Black 1 inch 7.7 inch moveto
    (Dashed vertical line: channel capacity = 0.18872 18755) show
  Black 1.3 inch 7.5 inch moveto
    ((as codeword size, equals 1/0.18872 = 5.2988)) show
} def % plotaxes

1 inch 1 inch translate
PlotAxes
Red   p20 10 48 plotpts % blocksize 20
Blue  p15 2  58 plotpts % blocksize 15
Green p10 2  46 plotpts % blocksize 10
Black p5  2  26 plotpts % blocksize 5

showpage