An Application of Simulated Annealing in Compensation of Nonlinearity of Scanners

Galvo scanners are popular devices for fast transversal scanning. A triangular signal is usually employed to drive galvo scanners at scanning rates close to the inverse of their response time where scanning deflection becomes a nonlinear function of applied voltage. To address this, the triangular signal is synthesized from several short ramps with different slopes. An optimization algorithm similar to a simulated annealing algorithm is used for finding the optimal signal shape to drive the galvo scanners. As a result, a significant reduction in the nonlinearity of the galvo scanning is obtained.


Introduction
Two orthogonal scanners are generally required in the implementation of any optical system based on flying spot for transversal scanning [1][2][3].Galvo scanners are made of high-speed, current sensitive, limited rotation electrical motors which spin mounted mirrors [2,4,5].The amount of rotation is determined by the current or voltage applied [6,7].A galvo-scanner is composed of a small coil of wire wound on an armature that is suspended in the gap of a moving permanent magnetic field by means of pivots and bearings [2,8].When the coil is flown by a current, it develops a magnetic field that acts against the static field in the gap, causing the coil to rotate [7].Such scanners can be operated in open or closed loops [4].To operate in a closed loop, the galvo scanner is equipped with a position sensing device and a position correction device.Feedback signals are sent from a driver to stabilise and linearize the angular deviation.A position detection device can be constructed using a vane that occludes the light from a light emitting diode (LED) falling onto a photodetector [9].The algorithm implemented in the driver circuit compares the actual position of the mirror with the expected position for the given applied voltage [10,11].The driver generates an error correction signal which is combined with the input signal.Despite this correction, at high rates, the angular deviation becomes nonlinear [12].Galvo-scanners are mainly driven by triangular or saw-tooth signals.The frequency range of the signal is limited by the mechanical design of the galvo-scanner [13].One common problem with galvo-scanners, when driven at high rates, is that they are not able to follow the shape of the input signal perfectly.Therefore, they do not perform as expected (see Figure 1), and create artefacts in the acquired signal [14][15][16][17][18]. Several procedures are known to correct for such nonlinearities, the most popular one being to alter the image depending on the position signal.This however requires a specialized frame grabber, complex software, and expensive galvo-scanners, equipped with position sensors.Alternatively, if the shape of the voltage signal sent to the galvo scanner can be amended to slightly deviate from that of a ramp, it becomes possible to reduce the artefacts [19].In this study, an optimization algorithm, based on a simulated annealing (SA) algorithm [20][21][22][23][24][25][26], is developed to synthesize the optimal shape of the signal applied to the fast galvo-scanner in the scanning head.The reconstructed signal is composed of many small linear signals with different slopes.The algorithm finds the best set of slopes.However, while the resultant shape of the input voltage to the galvo-scanner is not saw-tooth or triangular anymore, a significant reduction in the nonlinearity of the scanner is obtained.

Materials and Methods
The optical setup is composed of a Mach-Zehnder fiber interferometer that uses a super luminescent diode (SLD) with a central wavelength of 1300 nm and a spectral bandwidth of 25 nm.Both the reference and sample were in the same arm in this configuration of interferometer.To avoid light being sent back into the source, the coupling was performed via an optical isolator (ISO).The light was sent to a directional optical fiber coupler.It was then collimated and sent to a scanning head made of two galvo-scanners (#6110, Cambridge Technology CO., Bedford, MA, USA).The light reflected off the mirrors are focused on the sample using a microscope objective (LSM02, Thorlabs, Newton, NJ, USA); the effective focal length of the lens is 18 mm and the working distance is 7.5 mm.The sample is a metal plate consisting of a regular pattern of equidistant hexagonal holes, with the size of 100 microns.The plate is placed 3 mm in front of the sample mirror.The spot size of the light on the sample mirror is much smaller than the size of the hexagonal hole in the plate.
The distance between the metal grid and the mirror helped separate, by depth, the reflections of the mirror from the reflections of the metal grid.Both the mirrors are PF-10-03 (Thorlabs, Newton, NJ, USA).The back-reflected light from the sample and mirror is detected using a balanced photodetector (Newfocus, 80 MHz electronic bandwidth, Newport, Irvine, CA, USA), with internal adjustable gain.More details of the design of this system are described in [27].The hardware configuration of the compensation/optimization system is shown in Figure 2.
The galvo-mirror is driven by a triangular signal of 5-volt peak-to-peak.Although the pattern of the holes is periodic, the spikes did not look equidistant due to the nonlinearity of the scanning.As a result, the peak produced by a fast Fourier transform (FFT) of the photodetected signal is not narrow around the frequency component given by 2n/T, where T is the period of the input triangular signal and n is the number of slits in the metal plate.Our aim is to alter the shape of each ramp in the triangular signal, using an optimization algorithm [22,[28][29][30][31][32][33][34], until the photodetected signal presented maximum regularity in the succession of peaks corresponding to the beam being scanned over regularly placed empty spaces, to produce equidistant spikes, and narrow the FFT peak.The optimization procedure is as follows: An initial triangular signal is sent to the galvo-scanner driver through a PCI-6229 (PCI output card, National Instrument, Austin, TX, USA).The photodetector signal is then acquired into a computer by a PXI-6133 (PCI input card, National Instrument, Austin, TX, USA).A LabVIEW ® program is specially developed for data acquisition.The sampling rate for the output and input cards are 800,000 S/s and 50,000 S/s, respectively.The photodetector signal passed through a high pass filter and then is subject to a fast Fourier transformed (FFT).The high pass filter filtered out the strong low frequency components close to the repetition frequency.The peak of the FFT, corresponding to the fundamental frequency of the scan over the regular pattern of holes, is then considered as the cost function of the optimization algorithm.The frequency is calculated as twice the frequency of the triangular signal times the number of holes scanned.The optimization algorithm is written in LabVIEW using MathScript.The optimization algorithm produces a curved triangular signal composed of n ramps.A slope is evaluated for each two samples to create a short ramp (in total n/2 short lines).The short ramps with different slopes are connected to each other to build the curved triangular signal.The algorithm then reconstructs the driving signal (that approximates a triangular signal) using a combination of a positive right ramp with a negative left ramp.The first (growing) ramp is generated using the optimization algorithm, and the next (decreasing) ramp is obtained by mirroring the left ramp with respect to the y-axis.
The initial normalized value of all tiny slopes is 1.This means that the initial signal to drive the scanners was a triangular signal.The optimization algorithm alters the slopes of the short ramps and hence the shape of the driving signal iteratively in such a way that the FFT spectrum of the photodetected signal became narrower and the peak of the main component in the spectrum taller.There are two main loops in the optimization algorithm as explained in Algorithm 1: A local search loop (LSL) alters the slope of each short ramp randomly in the range of +0.01 to +0.3 with steps of 0.01; A global search loop (GSL) alters the slope of each short ramp randomly in the range of +1 to +3 with a step of 0.01.As explained in [35,36], the use of the global search in the optimization algorithm is necessary to find an optimum around which the global optimum can be found through the local search loop.The algorithm continues until a certain number of iterations is reached or until the rate of improvement becomes too slow (<1%).In the optimization algorithm, attention is paid to: (1) the range of the perturbation of the slopes in the local and global search loops and (2) the appropriate length of the signal that FFT is applied to.In this study, the algorithm stopped after 10,000 iterations, however, in most cases it has converged after around 4000 iterations.For 10,000 iterations, the algorithm took about 5 s using a quad core 3 GHz PC with 16 GB RAM.
In general, if a computing task is well-suited to single instruction multiple data (SIMD) parallelization then it will be well-suited to computation on a GPU.The data-parallel computations with high arithmetic intensity exist in our algorithm were able to attain maximum performance from a GPU.This was because the volume of very fast arithmetic instruction can 'hide' the relatively slow memory accesses.We are in the process of implementing the code in a GPU (XFX-AMD Radeon RX 580 GTS, Advanced Micro Devices, Austin, TX, USA) following the method described in [37].Based on the initial preview, for 100,000 iterations, the algorithm takes about 400 ms.

Start:
Initialization Send an initial slope vector (1)

Results
The optimization algorithm was implemented in LabVIEW on a quad core computer with 16 GB memory.We used 100 short ramps to reconstruct the triangular signal; each ramp was constructed using 2 samples.The typical frequency of the triangular signal input to the fast galvo-scanner was around 500 Hz.Therefore, we tested our optimization method at three frequencies: 862 Hz, 697 Hz, and 308 Hz.The reference shape of the triangular signal sent to the galvo scanner is shown in Figure 3a.The amplitude of the signal is 5-volt peak to peak.In the first attempt, the frequency of the triangular signal was 862 Hz.The triangular signals before and after the optimization are given in Figure 3a  The optimization algorithm improved the peak of the FFT signal during 10,000 iterations from 0.0035 to 0.029 V (~10 times).The peak amplitude of the FFT during the optimization was significantly improved, and the spectral width of the optimized signal became narrower.The graph showing the peak of FFT recorded during the optimization process as well as the improvement profile of the peak of the FFT, are given in Figure 5a,b, respectively.As shown in Figure 5a, during the global search loop of the optimization algorithm, the algorithm occasionally generates signals with low FFT signal amplitude.This part of the algorithm is similar to the Boltzmann loop [35,36]   The compensation system was tested on two more triangular signals with frequencies of 697 Hz, and 308 Hz.The results are shown in Figures 6 and 7.
We also tested using several ramps to reconstruct the triangular signal.The preliminary results showed an approximately two-fold increase when we used two samples per ramp instead of 10 (the number used in all the above experiments).The computation, however, became more expensive (it took four times longer).

Discussion and Conclusions
In this study, we demonstrated an approach to compensate for the nonlinearity of the galvo scanners in optical imaging/sensing setups with a transversal scanning.We used an optimization algorithm based on a simulated annealing method by altering the shape of the signal using connected small ramps with different slopes, iteratively, until the equidistant structures in a calibration target produced equidistant features in the image.The compensation technique was evaluated at different frequencies of the triangular signal, one below the typical frequency, i.e., 500 Hz, and two above it, i.e., 697 Hz and 862 Hz.As expected, the nonlinearity was more apparent at larger frequencies, using more samples to synthesize the short ramps, which increased the total number of samples in the driving signal.This required an output card with a higher rate, i.e., a more expensive card.
An immediate correction would have consisted of maintaining the linearity of the signal in the middle and accelerating the variation close to the turnaround point.The method presented can be applied to open loop scanners, allowing for lower cost systems to be implemented.For each galvo-scanner, the optimum voltage shape can be found and then the shape can be stored in a register or, a nonlinear analogue signal generator can be used.
Compared to other methods proposed for compensation of nonlinearity of galvo-scanners [10][11][12][13]18], this method is inexpensive, fast, does not require a sophisticated theoretical analysis, and it is easy to perform.
The proposed method can be easily used in optical coherence tomography (OCT) and photoacoustic microscopy imaging techniques to acquire a more accurate images from the tissue microstructures [38][39][40][41][42][43].

Figure 1 .
Figure 1.A Triangular signal (solid black) and the response function of a typical galvo (so Figure 1.A Triangular signal (solid black) and the response function of a typical galvo (solid red).The scanner smooths the shape of the triangular signal as it cannot follow the abrupt slope changes.

Figure 2 .
Figure 2. The experimental setup of the compensation/optimization system.Metal plate with Figure 2. The experimental setup of the compensation/optimization system.Metal plate with hexagonal holes in front of the scanning probe head (outlined with red broken line).

Figure 3 .Figure 3 .
Figure 3.The reconstructed triangular signal with a frequency of 862 Hz (a) before optimization, ( Figure 3.The reconstructed triangular signal with a frequency of 862 Hz (a) before optimization, (b) after optimization.
,b, respectively.The corresponding FFT of these signals are shown in Figure 4a,b.

Figure 4 .Figure 4 .
Figure 4. FFT of the photodetector signal while imaging the metal plate object, (a) before optimization, Figure 4. FFT of the photodetector signal while imaging the metal plate object, (a) before optimization, (b) after optimization.The frequency of the triangular signal was 862 Hz.
in the simulated annealing algorithm which prevents the algorithm from being trapped into a local optimum.

Figure 5 .Figure 5 .
Figure 5. Improvement in the amplitude of the FFT signal during the optimization process.( Figure 5. Improvement in the amplitude of the FFT signal during the optimization process.(a) Variation of the FFT amplitude during the optimization process, (b) improvement profile of only "the improved FFT amplitudes" during the optimization process.The frequency of the triangular signal was 862 Hz.

Figure 6 .Figure 6 .Figure 7 .Figure 7 .
Figure 6.FFT of the photodetector signal while imaging the metal plate object, (a) before optimizationFigure 6. FFT of the photodetector signal while imaging the metal plate object, (a) before optimization and (b) after optimization.(c) The reconstructed triangular signal after the optimization process, (d) improvement profiles of only "the selected FFT component" during the optimization process.The frequency of the triangular signal was 697 Hz.