implementation of the optimal nl filter