converted some of the matlab code to python, incomplete