The study of the movements of microscopic phase objects, as biological cells, is of high interest in the scientific community. Digital Holographic Microscopy (DHM) is a technique widely used for analysis of phase objects. It can record, in one shot, the sample complex field and then the complex field is refocused in several planes for the 3D sample reconstruction. However, when in the view field there are several cells at different distances from the hologram plane, the correct location of each cell is critical for the analysis of the sample. There are diverse approaches to find the optimal focusing distance of a phase object; however, most of them depend on the input of the cell location in the view field as parameter. This condition restrings their application to cells in movement. We present the analysis of moving phase objects, using an alternative focusing criterion based on the analysis of different sized windows. With this criterion, it is possible to create a depth map of the objects in the sample, and at the same time finds its location in the view field and discriminate them from the background. The depth map is segmented with the clustering K-means method and each cluster is analyzed to determine the optimal object focusing distance. Then an extended focus image of the sample is created and displayed for the user. The method can detect autonomously when a new cell enters in the view field and calculates its focusing distance. The resulting images present all the cells in the sample well focused, and can be used for counting or tracking purposes. We present simulated and experimental results.