int CurrentCounter; // Current output counter public VitDecoder(ConvEncoderType encType, int convRate, int polyDegree, int[] polynomArray, int punctureMask, int punctureMaskSize, int rWindowSize) { if (convRate > MAX_RATE) { throw new ArgumentException(string.Format("The rate cannot be more than : {0}", MAX_RATE)); } this.Rate = convRate; this.MAXWORDCOUNT = BITSPERSYMBOL * this.Rate; this.K = polyDegree; this.Polynomial = new int[Rate]; Array.Copy(polynomArray, Polynomial, Rate); this.PunctureMask = punctureMask; this.PunctureSize = Math.Min(punctureMaskSize, 32); this.PuncturePass = Math.Min(this.PunctureSize, ConvEncoder.Bitcount(PunctureMask)); /* ************************************************************************** */ /* little degradation in performance achieved by limiting trellis depth * to K * 5 ... K * 6 --interesting to experiment with smaller values and measure * the resulting degradation. */ // If we use puncturing, then the size of the backtrack depth should be doubled this.BACKTRACKDEPTH = 6 * (PuncturePass < PunctureSize ? 2 : 1); // In order to release RW bits we have to train for at least BT + RW this.TrainingWindowSize = K * BACKTRACKDEPTH + rWindowSize; this.ReleaseWindowSize = (rWindowSize == 0) ? TrainingWindowSize : rWindowSize; /* m (memory length) = K - 1 */ this.m = K - 1; this.highbit = m - 1; // the position of the high bit in the state this.NumberOfStates = 1 << m; // Number of possible states 2^m this.NumberOfOutputs = (1 << Rate); this.encoderType = encType; /* n is 2^1 = 2 for the rate 1/Rate */ this.n = 1 << 1; // Number of possible inputs ( 0 or 1) for 1/Rate convolutional codec this.output = new byte[NumberOfStates, n]; /* gives conv. encoder output */ this.accum_prob_metric = new int[NumberOfStates, 2]; /* accumulated error metrics - current and next */ this.state_history = new int[NumberOfStates, TrainingWindowSize]; /* state history table */ // Use the Convolutional Encoder for pre-filling output table ConvEncoder encGen = new ConvEncoder(ConvEncoderType.Truncate, Rate, K, Polynomial, -1, 32); for (int state = 0; state < NumberOfStates; state++) { for (int bit = 0; bit < n; bit++) { /* output , given current state and input */ output[state, bit] = encGen.Output(state, (byte)bit); } /* end of bit for loop */ } /* end of state for loop */ this.DepuncturedData = new List <int>(); this.TempStack = new byte[TrainingWindowSize]; this.OutputData = new Queue <byte>(); Init(); }
/// <summary> /// Constructor for Rate R convolutional encoder. /// </summary> /// <param name="convRate">The number of bits sent out for each input bit.</param> /// <param name="polyDegree">The number of bits (including current symbol) to use in calculations. Equal to Constraint + 1.</param> /// <param name="polynomArray">The array of size [Rate] that has polynomial coefficients.</param> /// <param name="punctureMask">The puncture mask. 1 in position means output bit. 0 means do not output.</param> /// <param name="punctureMaskSize">Total size of the puncture mask.</param> public ConvEncoder(ConvEncoderType encType, int convRate, int polyDegree, int[] polynomArray, int punctureMask, int punctureMaskSize) { this.Rate = convRate; this.K = polyDegree; this.m = K - 1; this.Polynomial = new int[Rate]; Array.Copy(polynomArray, this.Polynomial, Rate); this.PunctureSize = punctureMaskSize; this.PunctureMask = punctureMask; this.EncoderType = encType; FirstBits = new byte[m]; OutputData = new Queue <byte>(); Init(); }