An optical apparatus is disclosed for processing light that based on a pair of diffraction gratings operating in tandem, with one of the gratings being a fixed diffraction grating and with the other grating being electrically programmable. The combination of the fixed and electrically-programmable diffraction gratings provides a spectral resolution and dispersion higher than that of either diffraction grating when used alone. These two diffraction gratings can be formed on different substrates, or alternately be combined to form a composite diffraction grating. The electrically-programmable diffraction grating can be operated in either a singly-periodic mode or a multi-periodic mode to select particular wavelengths of the incident light for analysis and detection, or for transferring between optical fibers (e.g. wavelength division multiplexing or demultiplexing). In some cases, a prism can be substituted for the fixed diffraction grating or used in addition to the fixed grating. The optical apparatus has applications for use in remote spectral analysis, spectrometry, and optical fiber communications.