The spectral purity of a ridge waveguide Fabry-Perot laser can be improved by patterning the effective refractive index seen by an optical mode propagating in the cavity. Here we present a transmission matrix calculation to first order in the effective index step from which we derive the threshold condition as a function of cavity mode index. This approach enables us to solve the inverse problem relating the index pattern along the cavity to the threshold gain modulation in wavenumber space. Quasiperiodic index patterns are constructed, which lead to improved spectral purity at a predetermined wavelength. (c) 2005 American Institute of Physics.