Carbon encapsulation of magnetic metal nanoparticles: correlation between nanoscale structure of carbon matrix and electromagnetic properties