Generalized scattering-matrix method for the analysis of two-dimensional photonic bandgap devices