The precision of the electromagnetic flowmeter (EMF) suffers from the impact of the flow profiles. The typical idea is to construct an ideal magnetic field, in order to make the sensitivity of measurement area to be a constant. In the case of the ideal magnetic field, the potential difference between the two picking-up electrodes is linearly related to the mean velocity of the flow in the pipe, i.e. the flow rate. The necessary and sufficient conditions for the ideal magnetic field in the electromagnetic flowmeters were established in the paper. The EMF with ideal magnetic field is immune to the impact of the profiles. However, in the case of typical electrode configurations, e.g. point electrodes, the ideal magnetic field does not exist. As the alternative to the ideal magnetic field, the excitation coils were optimized to minimize the non-uniform of the sensitivity distribution in the measurement area. Numerical simulations were used to optimize the excitation coils in three dimensional cases. Two parameters of the excitation coils were optimized. Phantoms of the EMF with optimized excitation coils were constructed. Experimental results validated the performance the optimized excitation coils. Compared with the EMFs with commercially available coils, the EMF with optimum excitation coils was less sensitive to the flow profiles, especially in the cases of flows nearby a U-shaped pipe.