Is the plug/unplug sound playing when it flags? Something else to try is turn on the developer options and then set it to keep the screen on when charging. Then watch to see if the charging indicator is acting up (this may show via the LED as well). It's possible the cable, charger, or even the phone port has a bad connection making it think the phone is being plugged and unplugged.