# Flickering-Free Distance-Independent Modulation Scheme for OCC
## 4 Modulation/Demodulation Scheme  
As was detailed in Section 3.2, depending on the switching signal's frequency value there is a specific correlation between consecutive frames, with three main cases:  
1. If the frequency is a multiple of the camera's frame rate (\(f_{\text{SW}}=\alpha f_{\text{CAM}}\)), the consecutive frames are highly correlated. Therefore, as stated in Section 3.1, the PCC is close to one. 2. If the frequency is perfectly uncoupled (\(f_{\text{SW}}=(\alpha+0.5)f_{\text{CAM}}\)), the consecutive frames are almost anti-correlated, therefore the PCC is almost minus one. 3. For the frequencies between these two cases (\(\alpha f_{\text{CAM}}<f_{\text{SW}}<(\alpha+0.5)f_{\text{CAM}}\)), the resulting images of consecutive frames vary from highly correlated to almost anti-correlated in a quasi linear relation, in other words, the PCC is between minus one and one. These correlation situations are the flickering free distance independent of modulation's basis. During the data transmission state, the emitter is switched on and off by applying a square signal with 50% duty cycle. This signal's frequency varies depending on the corresponding data symbol. Since each frequency generates specific correlation between consecutive frames, the symbol can be identified by calculating the PCC value. The PCC represents the linear correlation between two images using Equation (1). These values vary from \(-1\) (opposite images) to \(1\) (equal images). The correct frequency selection assures four possible outcomes from the consecutive frames' comparison and therefore a 2 bits per symbol codification:  
1. Consecutive frames highly correlated (\(PCC>0.7\)), when the frequency is a multiple of the camera's frame rate (\(f_{\text{SW}}=\alpha f_{\text{CAM}}\)). 2. Consecutive frames highly anti-correlated (\(PCC<-0.7\)), when the frequency is perfectly uncoupled (\(f_{\text{SW}}=(\alpha+0.5)f_{\text{CAM}}\)). 3. Consecutive frames moderately correlated (\(0<PCC<0.65\)), when the frequency is greater than but close to a multiple of the camera's frame rate. 4. Consecutive frames moderately anti-correlated (\(-0.65<PCC<0\)), when the frequency is lower than but close to the uncoupled frequency. Each two-bits symbol is emitted for a multiple of the frame's time (\(t_{symbol}=mT_{\text{CAM}}\)). For assuring the data extraction accuracy even when the transmission starts during the emitter's acquisition process, the emission should last at least three frames (\(m\geq 3\)). When the system is in the \"Transmitting\" state, from each frame the rectangular ROI containing only the light and dark bands from the emitter is obtained and stored. During the data extraction process, as shown in Figure 7, these frames' ROI is normalized using the \"max-min\" technique. In this way, the pixel values of consecutive frames are in the same range (from 0 to 1). Therefore, any possible effect of an environmental light change is mitigated. Then the PCC is calculated from the adequate consecutive frames' ROI. As stated in the previous section, if the transmission started during the acquisition of the emitter's pixel rows, the frame's ROI, which contains the transition between symbols, is eliminated from the frame's group. In this case, the PCC calculation is done \(m-2\) times. Otherwise, when the emission began before or after the emitter acquisition, this process is done \(m-1\) times (\(PCC(F_{1},F_{2}),...,PCC(F_{m-1},F_{m})\)). Then the average PCC (\(\overline{PCC}\)) of the frame's group is determined from those PCC values. Finally, based on that \(\overline{PCC}\) value, the data are decoded using Equation (4). \[DATA= \begin{cases}10&\overline{PCC}>0.7\\ 11&0<\overline{PCC}<0.65\\ 01&-0.65<\overline{PCC}<0\\ 00&\overline{PCC}<-0.7\end{cases}  \tag{4}\]  
Since each PCC value is obtained from the consecutive frames' comparison, there is no need of a thresholding techniques for identifying the light state. Moreover, the pixel's intensity value by itself is irrelevant so an initial calibration is not required.