Synthesis of magnetic nanoparticles