# FPGA-Based Manchester Decoder for IEEE 802.15.7 Visible Light Communications
## 2 Architecture of the Receiver
### The Bit Decision  
The slices are processed to detect the bit value and to extract the information necessary to maintain the synchronization. In the proposed approach, the signal is processed like it was modulated according to a BPSK modulation, and Manchester code is indeed a specific case of BPSK. Thus, the phase \(\varphi\) of the signal actually present in each slice \(sl_{h}\) is calculated.  
Figure 1: The “Sync.” block cuts the signal in slices of \(N\) samples; the “Proc.” block processes the slices for detecting the bits, and produces a feedback to Sync. which maintains the correct synchronism with respect to the bit boundaries.  
The slice represents a square wave (see Figure 1) at frequency \(f_{s}\), when the communication rate is \(f_{s}\) bit/s. The square wave, in the frequency domain, is characterized by the fundamental frequency at \(f_{s}\) with harmonics at multiple frequencies. The amplitude of the harmonics decreases with the increasing frequency, being the component at \(f_{s}\) characterized by the highest amplitude. Thus, it is reasonable to suppose that the component at\(f_{s}\) features the highest SNR. We will extract the phase \(\varphi\) from this component (see Equation (7)).  
Let us start by calculating the complex spectrum of the slice \(sl_{h}\) composed by the \(N\) samples as given in (3), by exploiting the discrete Fourier transform (DFT) [33]:  
\[\begin{split} I_{k}=\sum\limits_{i=0}^{N-1}s_{h\cdot N+\sigma f +i}\text{-}\cos\Bigl{(}2\pi\frac{k}{N}i\Bigr{)};& Q_{k}=-\sum \limits_{i=0}^{N-1}s_{h\cdot N+\sigma f+i}\text{-}\sin\Bigl{(}2\pi\frac{k}{N}i \Bigr{)};\\ 0\leq k\leq N-1\end{split} \tag{4}\]  
In (4), \(I_{k}\) and \(Q_{k}\) represent the In-phase and Quadrature-phase (IQ) components of the spectrum for the generic frequency \(f_{k}=k\cdot f_{c}/N\), where \(f_{c}\) is the sampling frequency. Since \(N=T_{b}\cdot f_{c}=f_{c}/f_{s}\), the component of our interest at frequency \(f_{s}\) has the index:  
\[k=\frac{f_{s}}{f_{c}}N=\frac{f_{s}}{f_{c}}\ T_{b}f_{c}=\frac{f_{s}}{f_{c}}\ \frac{f_{c}}{f_{s}}=1. \tag{5}\]  
Equation (4), rewritten for \(k=1\), is:  
\[I_{1}=\sum\limits_{i=0}^{N-1}s_{h\cdot N+\sigma f+i}\text{-}\cos\Bigl{(}2\pi \frac{i}{N}\Bigr{)};\ \ Q_{1}=-\sum\limits_{i=0}^{N-1}s_{h\cdot N+\sigma f+i}\text{-}\sin\Bigl{(}2 \pi\frac{i}{N}\Bigr{)} \tag{6}\]  
From here on \(I_{1}\) and \(Q_{1}\) are named I and Q for brevity. In the next step, the phase \(\varphi\) is calculated through the four-quadrant arctangent function atan2(Q, I) that can be defined as:  
\[\varphi=\text{atan2(Q,I)}=\begin{cases}\quad\text{atan}\Bigl{(}\frac{Q}{T} \Bigr{)}&I>0\\ \pi-\text{atan}\Bigl{(}-\frac{Q}{T}\Bigr{)}&I<0\\ \frac{\pi}{T}&I=0;Q>0\\ -\frac{\pi}{2}&I=0;Q<0\end{cases} \tag{7}\]  
where \(\text{atan}(x)\) is the inverse tangent of \(x\). In case of an ideal signal coded according to Manchester modulation of amplitude \(\pm\)A, the slice holding bit '0' (transition from symbol 0 to symbol 1) has \(I=0\), \(Q=2\)A, and \(\varphi\)=\(\frac{\pi}{2}\); and the slice holding the bit '1' (transition from symbol 1 to symbol 0) has \(I=0\), \(Q=-2\)A, and \(\varphi=-\frac{\pi}{2}\), as summarized in Table 1.  
The decision on the value of the bit can be easily taken by considering the sign of the phase \(\varphi\). However, it is apparent that the same decision can be obtained by looking at the sign of \(Q\), without the need of calculating \(I\) or the phase \(\varphi\). However, the calculation of the phase is required for the synchronization of the receiver, as it will be discovered in the next section.