Source: https://www-optica.inaoep.mx/~gurcid/pdi/PDI2ed-MatlabC4.pdf