The embodiment of the invention discloses a
harmonic compensation method for an angle error of a magnetic
encoder, and the method comprises the steps: enabling the magnetic
encoder to rotate at a
constant speed in a setting mode, collecting sine and cosine signals outputted by the magnetic
encoder, and carrying out the calculation through
CORDIC, thereby obtaining an initial angle sequence containing a fundamental wave error and a
harmonic wave error; extracting each
harmonic component through an adaptive wave trap, constructing a harmonic compensation polynomial, and storing each coefficient; in an application mode, a magnetic encoder
signal is collected in real time, a current initial angle value is solved, a harmonic compensation amount is calculated according to a current fundamental wave
angular frequency and a stored coefficient, and an accurate angle value is obtained by subtracting the compensation amount from the initial angle value. According to the method,
external reference signals and a large amount of storage space are not needed, each harmonic error is directly eliminated through a harmonic compensation polynomial, and approximate errors caused by traditional linear interpolation are avoided; and the compensation precision can be improved only by increasing polynomial terms, and the storage requirement is not obviously increased.