## 3 General Encoding and Decoding Algorithm
Each state point in the trellis diagram represents a possible encoder state, and the branches emanating from each state point represent the possible output bits. The trellis diagram is arranged in such a way that the transitions between the state points correspond to the sequence of input bits being encoded. To demonstrate the process of encoding using Convolutional codes through the Trellis Diagram, consider a scenario where the circuit is employed to encode the message (11011) and (\(k=1\), \(n=2\) and \(\mathbf{K}=2\)). Figure 2 shows a Convolutional Trellis Diagram encoder with \(k=1\), \(n=2\) and \(\mathbf{K}=2\). By utilizing the Convolutional Trellis Diagram encoder, the resulting codeword is depicted in Figures 3 and 4. This example has been selected due to its ability to clearly demonstrate the underlying principles of the aforementioned concept. Figure 2: Convolutional Trellis Diagram encoder. So, the codeword that the sender will send is equal to 11,01,01,00,01,01,11, and the last zero bits are to flush the Flip flop shift registers and make their value equal to zero to prepare the encoder circuit for the next encoding operation. * **Viterbi Algorithm** The trellis diagram is an essential tool for decoding Convolutional codes using the Viterbi algorithm. In the Viterbi algorithm, the trellis diagram is also used to determine the most likely sequence of input bits that produced a particular output sequence, based on the concept of finding the path with the minimum Hamming distance. In this paper, definitions have been established for two metrics, namely the branch metric (BM) and the path metric (PM). The branch metrics are the Hamming distances/Euclidean distances/probabilities depending  
Figure 4: Convolutional encoding message operation. Figure 3: Convolutional Trellis Encoder circuit and the state translation table. on the type of encoding. The path metric is a value associated with a state in the trellis. The equation used to update the path metric in the Viterbi algorithm is as follows [17]:  
\[PM[s,i+1]=min(\forall\alpha,PM[\alpha,i]+B[\alpha,i]) \tag{1}\]  
It is used to calculate the new path metric for each state in the trellis diagram, based on the previous path metrics and the branch metrics, where  
* PM \([s,i+1]\) is the new path metric for state (s) at time i + 1. It represents the likelihood of the most likely path through the trellis diagram that ends in state (s) at time i + 1. * PM \([\alpha,i]\) is the previous path metric for state \(\alpha\) at time i. It represents the likelihood of the most likely path through the trellis diagram that ends in state \(\alpha\) at time i. * B \([\alpha,i]\) is the branch metric for transitioning from state \(\alpha\) at time i to state (s) at time i + 1. It represents the similarity between the received signal and the expected signal for this state transition. As mentioned, the equation calculates the new path metric for each state in the trellis diagram, based on the previous path metrics and the branch metrics. This process is repeated for each time step in the trellis diagram, until the final state is reached. The path metric for the final state represents the likelihood of the most likely path through the trellis diagram, and is used to determine the decoded sequence of bits. The efficiency of this code is evaluated within the following conditions:  
1. **There is no error in the received codeword. ** In this case, the decoding operation at the receiver point will be as shown in the Figure 5.  
The receiver, depending on Viterbi algorithm, found the correct code depending on the survival path (the path with the minimum hamming distance value; here, it is equal to \(\mathbf{0}\)). 2. **There is one error in the received codeword. ** Figure 6 shows that the receiver received a codeword with a one-bit error. The receiver, depending on Viterbi algorithm, found the error bit and corrected the code depending on the survival path (the path with the minimum hamming distance value; here, it is \(\mathbf{1}\)).