code: public static void computeResidual(int[] data, int dataLen, int order, int[] residual) {
          int idataLen = (int) dataLen;
          
          switch (order) {
              case 0 :
                  for (int i = 0; i < idataLen; i++) {
                      residual[i] = data[i];
                  }
                  break;
              case 1 :
                  for (int i = 0; i < idataLen; i++) {
                      residual[i] = data[i] - data[i - 1];
                  }
                  break;
              case 2 :
                  for (int i = 0; i < idataLen; i++) {
                      /* == data[i] - 2*data[i-1] + data[i-2] */
                      residual[i] = data[i] - (data[i - 1] << 1) + data[i - 2];
                  }
                  break;
              case 3 :
                  for (int i = 0; i < idataLen; i++) {
                      /* == data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3] */
                      residual[i] = data[i] - (((data[i - 1] - data[i - 2]) << 1) + (data[i - 1] - data[i - 2])) - data[i - 3];
                  }
                  break;
              case 4 :
                  for (int i = 0; i < idataLen; i++) {
                      /* == data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4] */
                      residual[i] = data[i] - ((data[i - 1] + data[i - 3]) << 2) + ((data[i - 2] << 2) + (data[i - 2] << 1)) + data[i - 4];
                  }
                  break;
              default :
          }
      }
docs: Compute the residual from the compressed signal.
  @param data
  @param dataLen
  @param order
  @param residual