We propose a deterministic method to generate an arbitrary (pure or mi
xed) density matrix of a harmonic oscillator. The general density matr
ices are achieved by manipulating quantum entanglement between the osc
illator and an auxiliary oscillator. We discuss how our preparation sc
heme can be realized by cavity quantum electrodynamics interactions so
that a general density matrix of a single-mode electromagnetic field
can be created.