restart; with(plots):
<Text-field layout="Heading 1" style="Heading 1">Understanding the binomial expansion </Text-field>term := (n, t, lp) -> log[10] (binomial(n,t)*10^(lp*t)*(1-10^lp)^(n-t));
<Text-field layout="Heading 2" style="Heading 2">Fix n vary t</Text-field>n := 10; t1 := 3; f1 := lp -> term(n, t1 , -lp); G1 := plot(f1(x), x = 0..5, y=0..-14, color=blue): f2 := lp -> term(n, t1 + 1, -lp); G2 := plot(f2(x), x = 0..5, y=0..-14, color=green): f3 := lp -> term(n, t1 + 2, -lp); G3 := plot(f3(x), x = 0..5, y=0..-14,color=yellow): display(G1,G2,G3);n := 1000; t1 := 10; xl := 0; xh := 5; yl := 0; yh := -15; f1 := lp -> term(n, t1 , -lp); G1 := plot(f1(x), x = xl..xh, y=yl..yh, color=blue): f2 := lp -> term(n, t1 + 1, -lp); G2 := plot(f2(x), x = xl..xh, y=yl..yh, color=green): f3 := lp -> term(n, t1 + 2, -lp); G3 := plot(f3(x), x = xl..xh, y=yl..yh,color=yellow): f4 := lp -> log[10]( sum( 10^ (term(n, t1 + j, -lp)) , j=0..10) ); G4 := plot(f4(x), x = xl..xh, y=yl..yh,color=red): display(G1,G2,G3, G4);
<Text-field layout="Heading 2" style="Heading 2">Fix t vary n</Text-field>t := 3; n1 := 10; f1 := lp -> term(n1 , t,-lp); G1 := plot(f1(x), x = 0..5, y=0..-14, color=blue): f2 := lp -> term(10*n1, t,-lp); G2 := plot(f2(x), x = 0..5, y=0..-14, color=green): f3 := lp -> term(100*n1, t,-lp); G3 := plot(f3(x), x = 0..5, y=0..-14, color=yellow): display(G1,G2,G3);
<Text-field layout="Heading 2" style="Heading 2">Fix t/n vary n</Text-field>tau := 1/10; n := [10, 100, 1000]; f1 := lp -> term(n[1],floor(tau*n[1]), -lp); G1 := plot(f1(x), x = 0..5, y=0..-14, color=blue): f2 := lp -> term(n[2],floor(tau*n[2]), -lp); G2 := plot(f2(x), x = 0..5, y=0..-14, color=green): f3 := lp -> term(n[3],floor(tau*n[3]), -lp); G3 := plot(f3(x), x = 0..5, y=0..-14, color=yellow): display(G1,G2,G3);
<Text-field layout="Heading 1" style="Heading 1">Performance of repetition codes</Text-field> A repetition code has generator matrix [1,1,...,1]. We use the majority-vote decoding algorithm. Provided more than half of the received symbols are unchanged, we can correct the errors. The correction capability grows linearly with the length, but the rate of the code is 1/n. We'll use odd length, n= 2t+1. We can correct t errors. t := [1,2,3,4,5,6]; num := nops(t); n := [seq(2*t[i] + 1, i= 1..num) ]; f := [seq(lp -> term(n[i], t[i] +1, -lp), i = 1..num) ]; col := [blue, green, yellow, blue, green, yellow]; G := [seq(plot(f[i](x), x = 0..5, y=0..-14, color=col[i]), i= 1..num )]: display(G); t := [1,4, 16, 64, 256]; num := nops(t); n := [seq(2*t[i] + 1, i= 1..num) ]; f := [seq(lp -> term(n[i], t[i], -lp), i = 1..num) ]; col := [blue, green, yellow, blue, green, yellow]; G := [seq(plot(f[i](x), x = 0..5, y=0..-14, color=col[i]), i= 1..num )]: display(G);
<Text-field layout="Heading 1" style="Heading 1">Performance of Hamming codes</Text-field>Hamming codes have parameters [2^r -1, 2^r - 1 - r, 3]. They correct only one error, and the rate approaches 1 as r increases.t := 1; r := [3, 4, 5, 6, 7, 8]; num := nops(r); n := [seq(2^ r[i] - 1, i= 1..num) ]; f := [seq(lp -> term(n[i], 2, -lp), i = 1..num) ]; col := [blue, green, yellow, blue, green, yellow]; G := [seq(plot(f[i](x), x = 0..5, y=0..-14, color=col[i]), i= 1..num )]: display(G);
<Text-field layout="Heading 1" style="Heading 1">Reed-Muller codes of rate 1/2</Text-field>Reed-Muller codes are another large family of codes. The length of the binary codes are a power of 2 (though one can shorten, puncture etc.)Here we compare three codes of rate 1/2 and parameters [ 2^m, 2^(m-1), 2^((m+1)/2) ]so it corrects 2^((m-1)/2) errors num := 6; m := [seq ( 2*i+1, i = 1..num)]; n := [seq ( 2^m[i], i = 1..num)]; d := [seq ( 2^((m[i]+1)/2), i = 1..num)]; t := [seq ( 2^((m[i]-1)/2), i = 1..num)]; f := [seq(lp -> term(n[i], t[i], -lp), i = 1..num) ]; col := [blue, green, yellow, blue, green, yellow]; G := [seq(plot(f[i](x), x = 0..5, y=0..-14, color=col[i]), i= 1..num )]: display(G);
<Text-field layout="Heading 1" style="Heading 1">Performance of BCH codes</Text-field>Here we look at the performance of four BCH codes of rates roughly 3/4 and of varying lengths.r := [5, 6, 7, 8];n := [seq( 2^r[i] -1, i = 1..4)]; k := [21, 45, 92, 191]; rate := [seq( evalf(k[j]/n[j]), j= 1..4) ]; d := [5, 7, 11, 17]; t := [2, 3, 5, 8];num := nops(t); f := [seq(lp -> term(n[i], t[i] +1, -lp), i = 1..num) ]; col := [blue, green, yellow, orange, green, yellow]; G := [seq(plot(f[i](x), x = 0..5, y=0..-14, color=col[i]), i= 1..num )]: display(G);
<Text-field layout="Heading 1" style="Heading 1">Reed-Solomon codes</Text-field>
<Text-field layout="Heading 2" style="Heading 2">Symbol error probability</Text-field>We compute the symbol error from the bit error probability, pb and the mumber of bits in a symbol, s. psymb := proc(pb, s) local ps; ps := sum(binomial(s, j) * pb^j * (1-pb) ^ (s-j) , j = 1..s ); return(ps); end proc;psymb(.01, 5);lpsymb := (lpb, s) -> lpb + log[10](s); F:= [lpb -> log[10]( psymb(10^lpb, 8) ), lpb -> lpsymb(lpb, 8) ];psymb(.001, 8);G := [seq(plot (F[i](-lpb), lpb = 1..5 ), i=1..2 )]:display(G);
<Text-field layout="Heading 2" style="Heading 2">Comparison of two Reed-Solomon codes of different lengths but the same rate</Text-field>We compare tgwo codes of the same rate with the same alphabet, but of different lengths: The [255, 127, 129] RS code over F_256 which corrects 64 errors; The [32,15,17] shortened RS code over F_256 which corrects8 errorsn := [32, 255]; t := [9, 65]; num := 2; f := [seq(lp -> term(n[i], t[i], lpsymb(-lp,8)), i = 1..num) ]; #lpsymb(lp,8)), i = 1..num) ]; col := [blue, green, yellow, blue, green, yellow]; G := [seq(plot(f[i](x), x = 1..5, y=-1..-14, color=col[i]), i= 1..2 )]: display(G);
<Text-field layout="Heading 2" style="Heading 2">Comparison with the same correction capability</Text-field>Two codes both correcting 9 errors The [255, 239, 17] RS code over F_256 which corrects 64 errors; The [32,15,17] shortened RS code over F_256 which corrects8 errorsn := [32, 255]; t := [9, 9]; num := 2; f := [seq(lp -> term(n[i], t[i], lpsymb(-lp,8)), i = 1..num) ]; #lpsymb(lp,8)), i = 1..num) ]; col := [blue, green, yellow, blue, green, yellow]; G := [seq(plot(f[i](x), x = 1..5, y=-1..-14, color=col[i]), i= 1..2 )]: display(G);
<Text-field layout="Heading 2" style="Heading 2">Comparison with a binary code of the same rate</Text-field>