img  := 
        Import["testbild.jpg", 
          Path -> {"C:\\Dokumente und \
Einstellungen\\zell\\Desktop"}];

Show[img]

d = img[[1,1]];

Dimensions[d]

d[[1, 1]]

Max[d]
Min[d]

digdata = 
        Table[Floor[d[[x, y]]/8], {x, 1, 480, 1}, {y, 1, 640, 
            1}];

original = 
        ListDensityPlot[digdata, AspectRatio  -> 3/4, 
          Frame -> False, Mesh -> False];

Export["original.jpg", original, 
      ConversionOptions
 -> {"Quality" -> 
            100}, ImageSize -> {667, 502}]

Simulation der unkodierte Uebertragung mit Rauschen

<<Statistics`DiscreteDistributions`

bdist = BernoulliDistribution[0.1];
noise1 = 
        Table[FromDigits[Table[Random[bdist], {i, 1, 5}], 
            2]
, {x, 1, 480}, {y, 1, 640}];

noisedata = 
        Table[Mod[digdata[[x, y]] + noise1[[x, y]], 32], {x, 1, 
            480}, {y, 1, 640}];
uncoded = 
        ListDensityPlot[noisedata, AspectRatio  -> 3/4, 
          Mesh -> False, Frame -> False];

Export["uncoded.jpg", uncoded, 
      ConversionOptions
 -> {"Quality" -> 
            100}, ImageSize -> {667, 502}]

Codewoerter

Der duale Code zum Hamming-Code der Laenge 15 hat Minimaldistanz 8;
wir fuegen das konstante 1-Wort dazu und erhalten einen Code mit Minimaldistanz 7 und folgender
Generatormatrix.

G = 
        Transpose[{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
              1}, 
   {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
              1, 1, 1, 1}, 
   {0, 0, 0, 1, 1, 1, 1, 0, 
              0, 0, 0, 1, 1, 1, 1}, 
   {0, 1, 1, 0, 0, 
              1, 1, 0, 0, 1, 1, 0, 0, 1, 1}, 
   {1, 0, 
              1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1}}];

Ein Wort x={x1,x2,x3,x4,x5} mit 5 Bits wird zum Codewort G.x mit 15 Bits codiert.

code = 
        Table[Mod[G . IntegerDigits[i, 2, 5], 2], {i, 0, 31}];

code[[2]]

Weight[w_] := Sum[w[[i]], {i, 1, 15}]

unknown = Table[1, {15}];
NearestNeighbor[w_] := (i = 1; 
 
          While[i < 33, 
            If[Weight[Mod[w + code[[i]], 2]] < 4, Return[code[[i]]], 
              i = i + 1]]; 
Return[
            unknown];);

w = 
      Mod[code[[4]] + {1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0}, 
        2]
NearestNeighbor[w]

error = Table[Random[bdist], {i, 1, 15}]

w = Mod[code[[4]] + error, 2]

NearestNeighbor[w]

Simulation der kodierten Uebertragung mit Rauschen

codeddata = 
        Table[Mod[G . IntegerDigits[digdata[[x]][[y]], 2, 5], 
            2], {x, 1, 480}, {y, 1, 640}];

noise = 
        Table[Table[Random[bdist], {i, 1, 15}], {x, 1, 480}, {y, 1, 
            640}];

receiveddata = 
        Table[Mod[codeddata[[x, y]] + noise[[x, y]], 2], {x, 1, 
            480}, {y, 1, 640}];

decodeddata = 
        Table[NearestNeighbor[receiveddata[[x, y]]], {x, 1, 480}, {y, 1, 
            640}];

finaldata = 
        Table[FromDigits[
            LinearSolve[G, decodeddata[[x, y]], Modulus -> 2], 
            2], {x, 1, 480}, {y, 1, 640}];

final = 
        ListDensityPlot[finaldata, AspectRatio  -> 3/4, 
          Mesh -> False, Frame -> False];

Export["final.jpg", final, 
      ConversionOptions
 -> {"Quality" -> 
            100}, ImageSize -> {667, 502}]

Fehler bei kodierter Uebertragung

diff = 
        Table[Mod[digdata[[x]][[y]] - finaldata[[x]][[y]] + 31, 32], {x, 480}, {y, 
            640}];
Count[diff, 31, 2]/(480*640) // N
wrong = 
        ListDensityPlot[diff, AspectRatio  -> 3/4, 
          Mesh -> False];