ENH: Completed translating matlab code, not yet debugged.