ebike Motor stuttering and jerking from time to time

My ebike motor is stuttering and jerking, I'm wondering if there is any way to tell if it is the motor or the motor controller causing this problem?
It could be a loss of connection. I have seen an ebike bottle battery that broke internally and caused the same problem whenever the connection was lost.