A grating is any regularly spaced collection of essentially identical, parallel, elongated elements. Gratings usually consist of a single set of elongated elements, but can consist of two sets, in which case the second set is usually perpendicular to the first (as illustrated). When the two sets are perpendicular, this is also known as a grid.
A grating covering a drain (as illustrated) can be a collection of iron bars (the identical, elongated elements) held together (to ensure the bars are parallel and regularly spaced) by a lighter iron frame. Gratings over drains and air vents are used as filters, to block movement of large particles (such as leaves) and to allow movement of small particles (such as water or air).
A grating can also be a picture having the characteristics of a grating. For example, a picture might be of a collection of parallel black bars separated by equal-sized white bars. These sorts of gratings are described by a graph (illustrated). On the y-axis of the graph is the luminance obtained by moving a light meter over the grating perpendicular to the orientation of the grating. On the x-axis of the graph is the distance the light meter moved. The example is a square-wave grating (see second panel of the illustration); the graph consists of flat, low lines (corresponding to the black bars), with abrupt corners leading to flat high lines (corresponding to the white bars). One period (or cycle) of such a grating consists of one black bar and one adjacent white bar. Gratings where the black bars have a different width from the white bars are rectangular and are described by the duty cycle. The duty cycle is the ratio of width of the black bar to period (or pitch, i.e. the sum of the widths of one black and one white bar).
Gratings are usually specified by four parameters. Spatial frequency is the number of cycles occupying a particular distance (e.g., 10 lines [or cycles] per millimeter). Contrast is a measure of the difference in luminance between the light parts of the grating and the dark parts. It is usually expressed as Michelson contrast: the maximum luminance minus the minimum luminance divided by the maximum luminance plus the minimum luminance. Phase is the position of the graph relative to some standard position. It is usually measured in degrees (from 0 to 360 for one complete cycle) or in radians (2π for one complete cycle). Orientation is the angle the grating makes with some standard orientation (such as the y-axis in a picture). It is also usually measured in degree or in radians.
Grating elements can have luminances other than that of sharp-edged bars. If the graph of a grating is sinusoidal (see top panel in the illustration), the grating looks like a set of blurry light and dark bars and it is called a sine-wave grating.
Sine-wave gratings are used extensively in optics to determine the transfer functions of lenses. A lens will form an image of a sine-wave grating that is still sinusoidal, but with some reduction in its contrast depending on the spatial frequency and possibly some change in phase. The branch of mathematics dealing with this part of optics is Fourier analysis.
Gratings are also used extensively in research into visual perception. Campbell and Robson promoted using sine-wave gratings by arguing that the human visual performs a Fourier analysis on retinal images.