The formation of dunes and antidunes on the erodible bed of an open channel is studied analytically as a problem of stability of the erodible bed. The phase lag existing between the local sediment-transport rate and the local velocity on the bed plays an essential role in the formation of the sand waves. A physical model for the transport of sediment over a wavy bed is presented and a quantitative explanation of this phase lag is developed. The regions of occurrence of dunes of those bed configurations are compared with experimental results previously summarized by Kennedy, the comparison showing a good agreement.