The refractive index measurement of seawater has proven significance in oceanography, while an optical heterodyne interferometer is an important, highly accurate, tool used for seawater refractive index measurement. However, for practical seawater refractive index measurement, the refractive index of seawater needs to be monitored for long periods of time, and the influence of drift error on the measurement results for these cases cannot be ignored. This paper proposes a drift error compensation algorithm based on wavelet decomposition, which can adaptively separate the background from the signal, and then calculate the frequency difference to compensate for the drift error. It is suitable for unstable signals, especially signals with large differences between the beginning and the end, which is common in actual seawater refractive index monitoring. The authors identify that the primary cause of drift error is the frequency instability of the acousto-optic frequency shifter (AOFS), and the actual frequency difference was measured through experimentation. The frequency difference was around 0.1 Hz. Simulation experiments were designed to verify the effectiveness of the algorithm, and the standard deviation of the optical length of the results was on the scale of 10-8 m. Liquid refractive index measurement experiments were carried out in a laboratory, and the measurement error was reduced from 36.942% to 0.592% after algorithm processing. Field experiments were carried out regarding seawater refractive index monitoring, and the algorithm-processing results are able to match the motion of the target vehicle. The experimental data were processed with different algorithms, and, according to the comparison of the results, the proposed algorithm performs better than other existing drift error elimination algorithms.