The Helioseismic and Magnetic Imager (HMI) onboard the Solar Dynamics Observatory (SDO) is designed to study oscillations and the mag- netic field in the solar photosphere. It observes the full solar disk in the Fe I absorption line at 6173AA . We use the output of a high-resolution 3D, time- dependent, radiation-hydrodynamic simulation based on the CO5BOLD code to calculate profiles F({lambda},x,y,t) for the Fe I 6173{AA} line. The emerging profiles F({lambda},x,y,t) are multiplied by a representative set of HMI filter transmission profiles R_i({lambda},1 leq i leq 6) and filtergrams I_i(x,y,t;1 leq i leq 6) are constructed for six wavelengths. Doppler velocities V_HMI(x,y,t) are determined from these filtergrams using a simplified version of the HMI pipeline. The Doppler velocities are correlated with the original velocities in the simulated atmosphere. The cross- correlation peaks near 100 km, suggesting that the HMI Doppler velocity signal is formed rather low in the solar atmosphere. The same analysis is performed for the SOHO/MDI Ni I line at 6768AA . The MDI Doppler signal is formed slightly higher at around 125 km. Taking into account the limited spatial resolution of the instruments, the apparent formation height of both the HMI and MDI Doppler signal increases by 40 to 50 km. We also study how uncertainties in the HMI filter-transmission profiles affect the calculated velocities.