Accurate and High-speed FBG Demodulator Using STM32 and DOG Algorithm


 A multi-channel and high-speed FBG demodulator based STM32 is designed in this paper. The wavelength detection accuracy is improved using a difference of Gaussian (DoG) peak detection algorithm. The 16-channel FBG wavelengths are demodulated simultaneously and that the demodulation frequency can reach 1kHz. The experimental results show that the temperature sensitivity is 13.17 pm/ ºC. And meanwhile, the standard deviation and the average error of the FBG wavelength demodulated at the same temperature is 1.9 pm and 2.1 pm respectively.


Introduction
Fiber Bragg Grating (FBG), as a new type of sensor, has the advantages of small size, light quality, corrosion resistance, immunity to electromagnetic interference and high sensitivity. It is widely used in various fields, such as petroleum, electric power, civil engineering [1,2]. In the above application fields, most of the physical quantities detected are static or quasi-static. Therefore, the demodulation speed of the FBG demodulator is moderate. However, rapid demodulation is required by dynamic quantity measurement in ocean and aerospace applications etc [3,4]. Many demodulation schemes for wavelength-shift-based FBG sensors have been developed [5], where the tunable F-P filter scheme is widely applied due to its advantages, such as the strong dynamic measurement capability, large measurement range, and high demodulation accuracy [6]. In the sensing process, the sensing information is received by the wavelength encoding. The change of the sensing signal is obtained by wavelength demodulation. So tracking and analysis of the central reflection wavelength of FBG is the core of the demodulation system. Though the tunable-FP-filter-based demodulation has offered a variety of potential advantages, their widespread practical use has been plagued by low demodulation speed, large volume and inaccurate peak wavelength detection due to Gaussian white noise and quantization noise in the data acquisition process.

FBG sensing principle
According to the fiber coupling mode theory [7], the center wavelength of the FBG reflection spectrum can be expressed as: Where λ b is the central wavelength of FBG, n ef f is the effective refractive index, and Λ is the grating period. Any changes in the refractive index or the grating period which in turn causes a the Bragg wavelength shift. So we only need to measure the shift in λ b to know the external physical parameters like strain or temperature. Therefore, how to accurately and quickly detect the shift in λ b is the key to demodulation technology. In an FBG sensor systems, the FBG reflection spectrum output [8] approximately satisfies: Where, A is the amplitude of the reflection spectrum, λ is the wavelength of FBG, λ b is the center wavelength of FBG and ∆λ is the 3 dB bandwidth. In this equation, the characteristic of FBG reflection spectrum is similar to the Gaussian curve, and its center wavelength λ b is the position of the peak point. Therefore, the demodulation accuracy is determined by the peak detection accuracy.

System design
The schematic of high-speed FBG demodulator based on STM32 is drawn in Fig 1. It contains three parts: optical part, electrical part, and power part. The broadband light from the Amplified Spontaneous Emission Light Source (ASE) is turned into a narrowband light with a line width of 0.0375nm after a tunable Fabry-Perot filter (TFPF). The light from TFPF is split into two channels-"sensing channel (SC)" and "reference channel (RC)". The SC light launched into testing FBG sensors by optical circulators (OCs), and the RC light launched into a Fabry-Perot etalon (FPE). And they are converted to electrical signal by photodetectors (PDs). The STM32 generates the triangular wave used to drive the TFPF by an amplifier circuit (AC) before it collects the serial data from the PDs. The demodulation results are displayed and stored in real-time. 3.1 Hardware design of the system The system uses an STM32H7 series ARM chip as the main controller to collect and process the FBG reflected spectra, display and store the demodulation results in real-time. Simultaneously, the DAC outputs the triangular wave to drive the TFPF. From the hardware design of the system, the main controller is based on the ARM Cortex M7 kernel processor, and its main frequency is up to 400MHz. It has 1060KB of SRAM and SDRAM, 16-bit ADC, and 12-bit DAC.

System software design
Since the main controller deals with too many tasks, which leads to low demodulation speed and system instability. Thus the RTOS µC/OS-III is applied to make full use of the CPU and ensure the implementation of high-speed demodulation of FBG.

A/D data acquisition design
Most demodulation systems use software demodulation methods. If this method is applied in high-speed demodulation systems, the demodulation frequency will be limited by the rate limit of the analog-to-digital converter. Thus how to improve the sampling frequency is the key to high-speed demodulation.
We design the triangle wave by the DAC in the ARM processor to drive the TFPF and provide the frame synchronous signal (FS) to ADC. The FS is set as 2ms. Because the TFPF has 2000 sampling points per scanning cycle, the sampling frequency of each channel requires 1MHz. ADC has 16 channels and simultaneous parallel collection, so we set the total sampling frequency to 16MHz.However, the ARM processor has three ADCs, and the maximum sampling frequency of each of them is 4.3MHz. To improve the sampling frequency, we proposed to employ the three-fold ADC alternated mode, so that three ADCs for cross-sampling on every sampling channel and utilizes the conversion stage of each of them to improve the sampling frequency. We set the ADC clock to 32MHz, so the conversion time of each ADCs is 6 clock cycles. When we adopt the three-fold ADC alternated mode, the total conversion time is 2 clock cycles. Therefore, the total ADC sampling frequency can reach 16MHz.
The FBG demodulation system has 16 demodulation channels, each of which has 2000 sampling points per scanning cycle. So the amount of data increase exponentially, increasing the communication burden. Aiming at this contradiction, we adopt Direct Memory Access(DMA), which does not require CPU control during high-speed data transmission and is independent of the ARM processor kernel. When the ADC receives the DAC's synchronization signal, it will request DMA to transfer the data saved in the ADC DR register directly to the custom ADC ConvertedValue target address until 32,000 sample points are collected. The data saved in ADC ConvertedValu will die after it processes, packages, and uploads the data to the main process. Then the task will start the next round of sampling. The flow diagram of ADC is shown in

Software design of signal demodulation algorithm
The demodulation system is based on the TFPF method. An F-P etalon (FPE) is used to calibrate the FBG reflection wavelength. Then an interpolation fitting algorithm is used to achieve real-time high-precision demodulation of the center wavelength of the FBG reflected spectra.
From Fig. 3, in the process of signal demodulation algorithm, firstly, we assign array A[i] to the data of the reference channel and sensing channel and set the threshold M. We save the ones larger than T into the array B[i], and the ones smaller than M will also be saved into B[i] after setting 0. Secondly, the peak value is detected to find the peak subscript. Finally, the center wavelength of the FBG reflected spectra is demodulated by the interpolation fitting algorithm. The flow diagram of the signal demodulation algorithm is shown in Fig. 3.  The role of the DoG algorithm [9] is to accurately and quickly detect spots in the image. The spots mainly refer to areas whose gray value changes drastically compared with other surrounding areas. The reflection spectrum of the FBG can be detected as spots because the FBG reflection spectrum's optical power is quite different from other areas which is similar to the spot signal.

Spot detection algorithm
The spot detection algorithm finds a suitable scale to identify areas with sharp changes in gray value and realizes image spot extraction by convolving the spot detection function of different scales with the image spot signal. The ideal onedimensional spot signal is a rectangular pulse signal with a certain width and two step edges In one-dimensional space. The rectangular pulse signal with width s and height h can be expressed as: The step function with height h can be expressed as When the second derivative of Gaussian is convolved with the signal F s,h (x), the step edges on both sides will first produce two maxima. The convolution of spot signal and second derivative of Gaussian is shown in Fig. 4.  Known the one-dimensional Gaussian function is: In this equation, σ is the scale, x is input. The derivative of equation (5) can be obtained: The second derivative of equation (5) can be expressed as: By equation (6) & (7), we can obtain: Where k is proportional coefficient of adjacent scale. According to equation Where σ 2 ∆ 2 G is the second derivative of Gaussian. The spot signal is expressed in Gaussian scale space as: So the convolution of spot signal and second derivative of Gaussian can be expressed as: In this equation, σ 2 ∆ 2 G * F sh (x) is the LoG response value, L(x, kσ) − L(x, σ) is the DoG response value, k − 1 is the proportional coefficient of the LoG response values and does not affect the center position of the signal. Therefore, the DoG algorithm can be instead of the LoG algorithm to detect spots. The LoG algorithm is formed by the second derivative of Gaussian and signal convolution, which is similar to Gaussian function and signal convolution. So the LoG algorithm's noise sensitivity is high. The DoG algorithm is the difference between the two Gaussian functions and the signal convolution result, thus it has strong noise resistance and its convolution kernel is simpler than the LoG algorithm. Through the above analysis, the DoG algorithm has a simple calculation process, strong noise resistance, and good stability. So it has a wide range of application prospects.

FBG peak detection algorithm based on DoG
Since the DoG algorithm can be represented by the LoG algorithm, the DoG algorithm's scale range can be obtained through the LOG algorithm. The equation (3) can be expressed by equation (4): And the convolution of G2 σ (x) and S h (x) can be expressed as Where G1 σ (x) is first derivative of Gaussian. Therefore, the spot detection of LoG can be expressed as As shown in Fig. 6, when the first derivative of this equation at x = 0 is 0 and the second derivative of this equation is less than 0, we can find When s = 2σ, the detected local maximum value is the largest. When the detected signal's width is within the range of (0.8σ, 2 √ 3σ), a local maximum is generated at the center of the signal, and the maximum value after the convolution of the two step edges disappears.
After G σ1 (x) is convolved with the signal F s,h (x), the first derivative of G1 σ (x) * F s,h (x) at x = 0 is 0 and the second derivative of G1 σ (x) * F s,h (x) is less than 0, we can find that when the signal F s,h (x) width is less than 6σ 1 , the center of the convolved signal F s,h (x) will generate a local maximum.
Suppose that in the convolution result of D σ1,σ2 (x) and signal F s,h (x), the signal F s,h (x) width that can generate a local maximum at the center of the signal is W . Through the above analysis, the width W ∈ 2 √ 3σ 1 , 6σ 1 . Therefore, the detection width of the DoG algorithm can be simply expressed as the following equation: When When Through the above analysis, the convolution results of the DoG algorithm and the LoG algorithm can generate a local maximum at the center of the signal F s,h (x).
In practical applications, the external environment and the system can easily introduce noise, which will cause jitter and waveform distortion for the center wavelength of the FBG reflection spectrum. Thus, it will reduce the accuracy of FBG demodulation. At present, when most FBG peak detection algorithm processes the reflection spectrum signal with a lot of noise, it will cause the peak detection accuracy to decrease and the error increase. The peak detection algorithm based on the DoG is the difference between the two Gaussian functions and the signal convolution result, which can significantly reduce the noise influence on the peak detection accuracy. Besides, the peak-detection algorithm based on the DoG does not need to denoise the original signal of the FBG reflection spectrum, which can prevent the original signal from causing its waveform distortion due to denoising. The peak detection algorithm based on the DoG process is shown in Fig. 6. When the FBG reflection spectrum signal is obtained, the reflection spectrum's width is defined as the 3dB bandwidth of the FBG reflection spectrum. According to the relationship between the reflection spectrum width and the DoG algorithm scale, a suitable one is found. The position of maximum generated after convolution is the peak wavelength of the reflection spectrum.

System stability and demodulation accuracy test
The experimental platform was constructed and debugged, according to Figure  1. The physical diagram of the experimental platform is shown in Fig. 7. The optical signal on the sensing channel and reference channel is shown in Fig. 8, the FBG reflection spectrum signal on the sensing channel is shown in Fig 8 (a). The transmission spectrum signal of the F-P etalon on the reference channel is shown in Fig. 8 (b). To verify the stability and demodulation accuracy of the high-speed FBG demodulation system based on STM32, firstly, we put an FBG sensor into a waterbath with a constant temperature 30 • C constant temperature trough, and the center wavelength of the FBG is 1550.418nm at this temperature. Secondly, the designed FBG demodulation system detects the center wavelength of the FBG sensor and sent the detected center wavelength to the computer per second. The center wavelength of the detected FBG sensor is shown in Fig.  9. Finally, we calculated the average value, standard deviation, and average error value of the detected center wavelength. The results are shown in Table  1. Fig. 9 The center wavelength of the detected FBG sensor Through the analysis of Fig. 9 and Table. 1, we can find that the number of central wavelengths of the FBG sensor detected in 1s is 1000, the detected wavelength value fluctuates at the average central wavelength of 1550.421nm, and the standard deviation is 1.9pm, and the average error is 2.1pm at the same temperature. Therefore, the demodulation system has a demodulation accuracy of 1KHz, and its system is stable.

Temperature test
The experiment was repeated for a range of temperatures ranging from 30 • C-100 • C with a step change of 10 • C.And we record the corresponding center wavelength after the temperature is constant and take the average value as the final experimental data. Finally, the measured temperature and the corresponding center wavelength are linearly fitted by MATLAB, and the result is shown in Fig. 10.
Where λ c is the center wavelength of the reflection spectrum and T 0 is the measured temperature. According to equation (4), if the temperature rises by 1 • C, the center wavelength of the reflection spectrum will shift by 13.17 pm. Therefore, the high-speed FBG demodulation system based on STM32 has good temperature demodulation linearity, and its temperature sensitivity is 13.17 pm/ • C.

Perspective and conclusions
We utilize the ARM processor's advantages in high-speed data acquisition, processing, transmission and display to a miniaturized high-speed FBG demodulation system. The demodulation system has as many as 16 demodulation channels, the demodulation frequency is up to 1 KHz, and the temperature sensitivity is 13.17 pm/ • C. And at the same temperature, the FBG demodulation system's standard deviation is 1.9 pm and the average error is 2.1 pm. So it has good system stability and demodulation accuracy.

Disclosures
All the authors have no conflict of interest.