Emission of terahertz electromagnetic wave in intrinsic Josephson junction stacks