Error Correction

Multi-layer redundancy system combining majority voting, IQR outlier rejection, parity validation, and XOR checksum verification for robust pattern extraction under noise and compression.

16×
Redundancy
4-bit
XOR Checksum
1-bit
Parity Check
IQR
Outlier Filter

Error Correction Pipeline

  1. Redundant Embedding
    Each 48-bit payload (4 pixels × 12 bits) is repeated 16× throughout the image at configurable stride intervals.
  2. Extraction Sweep
    All redundant payload instances are extracted from image pixels. Each instance yields: regionId, z, token1, token2, checksum, version.
  3. Majority Voting
    Discrete values (region ID, tokens, checksum) are determined by frequency-based majority vote across all samples.
  4. IQR Outlier Rejection
    Continuous values (z-coordinate) use IQR-based filtering: reject samples outside [Q1 - 1.5×IQR, Q3 + 1.5×IQR], then average.
  5. Parity Validation
    Region ID parity bit (popcount mod 2) validates the 7-bit region encoding.
  6. Checksum Verification
    4-bit XOR-folded checksum validates token pair integrity: checksum = fold1 ⊕ fold2 ⊕ fold3 ⊕ fold4.
  7. Confidence Calculation
    Final confidence = consensusRatio × (tokensValid ? 1.0 : 0.5). Measures extraction reliability.

Region ID Parity Check

The region ID (1-100) is encoded with an error-detecting parity bit:

// Encode: add parity bit to 7-bit region ID
function encodeRegionId(regionId) {
  const id = regionId - 1;              // 0-indexed (0-99)
  const primary = id & 0x0F;            // Lower 4 bits → R channel
  const upper = (id >> 4) & 0x07;       // Upper 3 bits
  const parity = popcount(id) & 0x01;   // Parity = count of 1-bits mod 2
  const secondary = (upper << 1) | parity;  // 3 bits + 1 parity → R channel
  return { primary, secondary };
}

// Decode: verify parity matches
function decodeRegionId(primary, secondary) {
  const lower = primary & 0x0F;
  const upper = (secondary >> 1) & 0x07;
  const id = (upper << 4) | lower;

  const expectedParity = popcount(id) & 0x01;
  const actualParity = secondary & 0x01;

  return {
    regionId: id + 1,
    parityValid: expectedParity === actualParity  // Error detection!
  };
}

4-bit XOR Checksum

Token integrity is verified using a folded XOR checksum:

// Generate 4-bit checksum from two 15-bit tokens
function generateChecksum(token1, token2) {
  const combined = token1 ^ token2;      // XOR the tokens

  // Fold 15 bits into 4 bits
  const fold1 = combined & 0x0F;         // Bits 0-3
  const fold2 = (combined >> 4) & 0x0F;  // Bits 4-7
  const fold3 = (combined >> 8) & 0x0F;  // Bits 8-11
  const fold4 = (combined >> 12) & 0x07; // Bits 12-14

  return fold1 ^ fold2 ^ fold3 ^ fold4;  // Final 4-bit checksum
}

// Verification: recompute and compare
const decoded = extractPattern(imageData);
const expectedChecksum = generateChecksum(decoded.token1, decoded.token2);
decoded.tokensValid = (decoded.checksum === expectedChecksum);

Majority Voting

// Discrete values: frequency-based majority vote
function majorityVote(values) {
  const counts = new Map();
  values.forEach(v => counts.set(v, (counts.get(v) || 0) + 1));

  let maxCount = 0, result = values[0];
  counts.forEach((count, value) => {
    if (count > maxCount) {
      maxCount = count;
      result = value;
    }
  });
  return result;
}

// Applied to: regionId, token1, token2, checksum, version

IQR Outlier Rejection

Continuous values (z-coordinate) use statistical filtering:

function averageWithOutlierRejection(values) {
  if (values.length === 0) return 0;

  // Sort and compute quartiles
  const sorted = [...values].sort((a, b) => a - b);
  const q1 = sorted[Math.floor(sorted.length * 0.25)];
  const q3 = sorted[Math.floor(sorted.length * 0.75)];
  const iqr = q3 - q1;

  // Reject outliers outside [Q1 - 1.5×IQR, Q3 + 1.5×IQR]
  const filtered = values.filter(v =>
    v >= q1 - 1.5 * iqr && v <= q3 + 1.5 * iqr
  );

  // Average remaining samples
  if (filtered.length === 0) return values[0];
  return filtered.reduce((a, b) => a + b, 0) / filtered.length;
}

Consensus Ratio Calculation

// Count how many samples match the final decoded values
const matchingPayloads = payloads.filter(p =>
  p.regionId === finalRegionId &&
  Math.abs(p.z - finalZ) < 0.02 &&      // z tolerance
  p.token1 === finalToken1 &&
  p.token2 === finalToken2
);
const consensusRatio = matchingPayloads.length / payloads.length;

// Confidence calculation
const confidence = tokensValid ? consensusRatio : consensusRatio * 0.5;

Confidence Scoring

Consensus Ratio — Percentage of samples matching final decoded values

92% consensus × valid checksum = 0.92 confidence

Confidence Thresholds

API Reference

const decoded = WumboMRP.decode(imageData, { stride: 4 });

// Result includes error correction metrics
console.log(decoded.regionId);       // 47
console.log(decoded.z);              // 0.866
console.log(decoded.tokensValid);    // true (checksum passed)
console.log(decoded.confidence);     // 0.92
console.log(decoded.sampleCount);    // 16
console.log(decoded.consensusRatio); // 0.92
console.log(decoded.errors);         // [] or ['Checksum mismatch']

Explore More Modules