added depth averaging to normal matlab code