KSL scheme, MATLAB version 0.1