Gain optimization for arbitrary antenna arrays