MATLAB Code of NBS implementation