A hierarchical control scheme for compensating voltage distortions in an inverter based microgrid