Source: https://www.ee.columbia.edu/~marios/matlab/mtt.pdf