Due to the rapid attenuation of the millimeter wave, it is necessary to use very large-scale antenna arrays in millimeter wave communications to get ultra-high directivity which improves the transmission distance and the signal-to-noise ratio. Considering the cost of large-scale RF links, analog beamforming plays an important role in large-scale MIMO communications. This paper discusses the calculation method of the antenna pattern that best matches the instantaneous MIMO channel in analog beamforming. By giving piecewise modeling on the antenna pattern, singular value decomposition and the water-filling algorithm are used to obtain the antenna pattern and the power distribution among antennas. The optimal antenna pattern can provide the target pattern for antenna synthesis to get the maximum capacity. The simulation results show that the method is effective.