transcribed a buncha matlab to python