Fixed calculation of envelope grating.