The present invention provides an undulator, wherein the undulator includes at least: M permanent magnet periods arranged in sequence along the electron beam transmission direction, each of the permanent magnet periods includes four rows of permanent magnet structures, and each row of permanent magnets The magnet structure includes N rows of permanent magnet groups, and each row of permanent magnet groups includes K permanent magnet units, wherein M, N, and K are all natural numbers greater than or equal to 1; the permanent magnet structures of the four rows are paired and opposite It is arranged on both sides of the electron beam transmission direction, and can form at least one composite magnetic field through relative displacement, so that when the electron beam passes through the composite magnetic field, it can generate elliptically polarized light, circularly polarized light, or any polarization angle from 0° to 360° direction of linearly polarized light, and make the direction of electron velocity deviate from the axis direction of the undulator. The invention can generate not only linearly polarized light, but also elliptical and circularly polarized light, and can make the direction of electron velocity never along the axial direction of the undulator, thereby greatly reducing the thermal load of the synchrotron radiation beamline.