A Bragg grating has a local reflection strength which varies with position along the length of the grating so as to generate a non-uniform wavelength reflection spectrum, enabling compensation for a non-uniform gain profile of the gain section of a tunable laser. In another aspect, a Bragg comb grating is modulated by an envelope function which can also compensate for a non-uniform gain profile. The comb grating may be a phase change grating, with the envelope function shape being controlled by the length between phase changes and/or size of the phase changes.