If you want to rectify a sinus you have to use abs(sin...) in your case -abs since you want to invert it.