code: function applyPhaseCorrection (mag, offset) {
    // Move ahead 16 to skip preamble.
    for (let j = 16; j < (msgLen.LONG_MSG_BITS - 1) * 2; j += 2) {
      if (mag[offset + j] > mag[offset + j + 1]) {
        // One
        mag[offset + j + 2] = (mag[offset + j + 2] * 5) / 4
      } else {
        // Zero
        mag[offset + j + 2] = (mag[offset + j + 2] * 4) / 5
      }
    }
  }
docs: This function does not really correct the phase of the message, it just applies a transformation to the first sample representing a given bit:  If the previous bit was one, we amplify it a bit. If the previous bit was zero, we decrease it a bit.  This simple transformation makes the message a bit more likely to be correctly decoded for out of phase messages:  When messages are out of phase there is more uncertainty in sequences of the same bit multiple times, since 11111 will be transmitted as continuously altering magnitude (high, low, high, low...)  However because the message is out of phase some part of the high is mixed in the low part, so that it is hard to distinguish if it is a zero or a one.  However when the message is out of phase passing from 0 to 1 or from 1 to 0 happens in a very recognizable way, for instance in the 0 -> 1 transition, magnitude goes low, high, high, low, and one of of the two middle samples the high will be *very* high as part of the previous or next high signal will be mixed there.  Applying our simple transformation we make more likely if the current bit is a zero, to detect another zero. Symmetrically if it is a one it will be more likely to detect a one because of the transformation. In this way similar levels will be interpreted more likely in the correct way.