I want to write a RCWA matlab code for calculating reflectance and transmission of TM polarization wave from a simple binary grating. the attached code is based on the paper by Moharam ''Formulation for stable and efficient implementation of rigorous coupled-wave analysis of binary gratings,''. I don't know what is the problem that I get the absorption about 50% for an arbitrary grating that is wrong.
I would greatly appreciate it if someone help me or send me an m file if has worked before.