Wayne Madsen made a defiant half-century but late wickets put Sussex in charge of their LV= County Championship match at Derby.