Exact analytic expressions for electromagnetic propagation and optical nonlinear generation in finite one-dimensional periodic multilayers