A linear analysis of 3D dunes and bars