matlab code from the jcp paper