Generation of terahertz radiation by optical rectification in presence of resonance impurities