Visual Basic for Applications/Viterbi Simulator in VBA 2

Summary
''' It has been noted that some calculate trellis metrics in different ways. So, this page includes an identical convolutional coding function to that in Viterbi Simulator in VBA. The main difference is that whereas that page displays its metrics in terms of CLOSENESS, this page does so in HAMMING DISTANCE. The code layout differs slightly between the two but the error correction remains the same'''.

This code is made for Excel. It simulates the behavior of a data channel's convolutional coding, though by necessity it concentrates on simple examples. Two rate 1/2 systems are provided; both with three stages, one for generator polynomial (111,110), and the other for (111,101). The code was written to improve understanding of the Wikibooks page A Basic Convolutional Coding Example, but might also be of elementary use for students without other software. The code concentrates on random errors of the type caused by Gaussian noise sources. Blank work sheets can be found in the drop-box below:

The Simulator
For each of the two configurations, rudimentary options have been provided. No user form has been included here, the author preferring to modify the settings directly in the top procedure's code. The branch metrics make use of HAMMING DISTANCE as opposed to CLOSENESS. A version using CLOSENESS can be found on an adjacent page.
 * User mode settings allow various combinations of inputs and errors to be applied.
 * Both coders produce two bits of output for every one bit of input.  The message input (display stream m) can be specified by the user, manually or generated randomly to any given length.   The decoder output message is distinguished from the original as m*.
 * The user can run one cycle or many.  Long cycle averaging is often useful.   A message box summarizes the BER (bit error rate) results across all cycles.   The user can output the metrics and basic streams for one chosen cycle to the worksheet.
 * The coder output is modified to include errors. This simulates the effect of random noise in a transmission channel.   The user can set specific errors in exact positions or apply random errors throughout to a specified bit error rate.   Recall that error bit positions apply to the output of the coder and that the number of bits there will be double that of the message input.
 * The display streams are labeled. The user can display the metrics and streams for a cycle. The streams are:
 * m is the original message input to the coder.
 * c is the coded output from the coder without any errors.
 * r is the received version of the coder output with the applied errors.
 * m* is the decoder output, the recovered message.

The VBA Code
The code is provided below in one complete module. Copy the code into a standard module. Set options in the top procedure RunCoding, then run that procedure to obtain a summary of error correcting results. The process will clear Sheet1, so be sure that no other essential work is located there. As an example of setting the options, assume that the intention is to test the performance of the 7,5 configuration with both random inputs and random errors to BER 0.01. Proceed as follows:
 * Set nCodePolyGen= 75 to select the 111,101 configuration,
 * nModeNumber = 8 for random inputs with random errors,
 * nAutoCycles = 100 for the average of 100 blocks,
 * nLenAutoInput = 500 to use five hundred bits in each input block,
 * nNumCdrFlushBits = 3 to add flushing bits at end of each input block,
 * sngBER = 0.01 to apply one percent errors,
 * Other options can be ignored for this task.
 * Run the procedure RunCoding. Output for the first cycle will be displayed on sheet one, and a summary for the changed BER across the decoder will appear on a message box when the run is complete.  Re-save the code or press the editor's reset button between runs with new parameters.

The Module
Modification 14/Aug/18; removed column numbers restriction. User responsibility now. Code Functional 11/Aug/18. Modification 11/Aug/18; corrected accumulated errors and procedure ColourTheErrors. Modification 10/Jan/18; corrected error in name of procedure to run. Modification 03/Nov/17; added back path edge values stream to sheet display. Modification 01/Nov/17; corrected errors in coding. Modification 31/Oct/17; added back path coloring.