We present an analytical treatment of the undulator radiation (UR), accounting for major sources of the spectral-line broadening, for example, the beam energy spread, the emittance, and a constant magnetic field, additional to the ideal periodic fields. The examples of high harmonic generation in one-and two-frequency undulators are considered with account for homogeneous and inhomogeneous broadening in real devices. Qualitative estimations are given as well as the exact analytical expressions for the UR spectrum, and intensity are obtained and simplified in the case of high-energy electrons. The compensation of the divergency by the constant magnetic field is demonstrated in the analytical form. The application for free-electron lasers (FEL) is demonstrated and compared with the radiation of a FEL on the supposition of an ideal undulator.