MRI simulation using the k-space formalism