implemented and documented Detrend function