Python translation of Matlab AAFT code