Analysis of Waveguide Grating Devices