Tried to implement that stuff in matlab, but failed.