# Zeroes: Robust Derivative-Based Demodulation Method for Optical Camera Communication
## 3 Method Description
### Detection of Peaks and Valleys  
Due to the square-shaped waveform of the emitted signal, the first-order derivative \(x_{n}^{\prime}\) is supposed to present alternating positive and negative lobes, respectively, indicating the rising and falling edges of the signal. Thus, a consecutive series of positive derivative values represents a positive lobe whose maximum value is a peak, while a consecutive series of negative derivative values represents a negative lobe whose minimum value is a valley (Figure 8). However, when the extracted signal \(x\) does not present sufficiently sharp edges due to a low contrast between strips, noise, or distortion, the detected peaks and valleys \(PV\) are not all necessarily valid, leading to demodulation errors if not taken into account. This is indeed the case for the peak surrounded by the blue circle in Figure 8.  
Fortunately, these wrong peaks and valleys can be detected through two different criteria:  
* The amplitude difference between a successive peak/valley.
* The alternating peak/valley pattern.  
Figure 8: Representation of the positive and negative lobes of the first-order derivative (_only a part of \({x_{n}}^{\prime}\) is plotted for better readability_).  
Figure 7: Representation of the first-order derivative after filtering.  
Thus, the validity of each peak and valley is checked by considering the \(PV\) value with the greatest amplitude \(max\_PV\) as being valid. Then, from \(max\_PV\), \(prev\_PV\) and \(next\_PV\) are determined, which are defined as the first peak/valley before and after \(max\_PV\), respectively, with an absolute amplitude greater than or equal half \(|PV\_max|\) (Figure 9). Hence, the validity of each peak/valley is firstly checked with \(PV\) before \(prev\_PV\), followed by those after \(next\_PV\) (Figure 9). A peak/valley is only considered as valid if  
\[PV(i)\geq\frac{|PV(i+1)+PV(i+2)|}{2+T_{h}} \tag{5}\]  
\(\forall i\in[prev\_PV-1,2]\) for \(prev\_PV\) validation; otherwise, \(\forall i\in[next\_PV+1,N_{PV}-2]\) for \(next\_PV\), while checking whether \(N_{PV}\) is the number of \(PV\) that was previously detected. If a peak or valley does not satisfy this condition, it is not considered as a peak or valley anymore in order to prevent any false detection; otherwise, it is recorded in \(PV\_left\) or \(PV\_right\) (Figure 9). Now that all the peaks and valleys are valid in terms of amplitude, the alternating peak/valley pattern must henceforth be checked. Indeed, in order to prevent these errors from happening, if two consecutive peaks or valleys are detected, only the portion of the derivative containing the most valid peak and valley is retained for further processing, as illustrated with the red area in Figure 9.  
As clearly seen in Figure 9, only peaks and valleys corresponding to the actual rising/falling edges of the extracted signal are taken into account (red crosses), with the peaks and valleys with too low of an amplitude being left out. Moreover, in order to prevent transmission errors, the largest series including the alternating peak and valley pattern is retained, deliberately ignoring parts of the derivative that would cause errors (red zone).