A change of the electron and hole densities n and p and of the lattice temperature T modulates the real optical refractive index nopt of the device under test. In the forward conducting state the electron and hole distributions n(x) and p(x) in the i-region of the device are generated by the action of carrier injection from the n- and p-emitters. The device is locally heated by Joule and recombination heat, leading to a temperature distribution T(x). The gradients of temperature and charge carrier densities cause a spatial modulation of the real refractive index nopt(x). A laser beam transmitted orthogonally to the direction of current flow of the device is deflected by the gradient of nopt(x). Concurrent deflections caused simultaneously by the carrier gradients on the one side and by the temperature gradient on the other side can be discriminated by their different time constants.