added mex files and pure Matlab implementation