Added an envelope detector