Kate's Matlab codes that I'll be working on translating into Python and (hopefully) improving on