Rigorous 3-D finite-difference time-domain computer simulations are used to investigate the electromagnetic characteristics of the diffraction output of a millimeter (mm)-wave-band relativistic magnetron. In the simulations, the diffraction output is outfitted with a dielectric grating that can be tuned in either reflection or transmission mode at definite operation wavelengths. This grating acts as a tunable filter of high-power oscillations generated by the magnetron and is similar to gratings widely used in optics to control ultrashort power optical pulses. Specifically, computer simulations establish a relation between the generation wavelength of the magnetron and the configuration of the grating, as well as predict that the grating provides the field reduction of up to -40 dB. The application of the grating suggests an approach to spectral measurements of mm-wave-band relativistic magnetrons with a measurement accuracy of better than 0.3 mm. The implementation of the approach solves a series of engineering and metrological problems arising during spectral measurements of a variety of high-power vacuum microwave devices.