MATLAB code for apstv2 project