Using C language to realize convolutional Code Encoder sample _c language

Source: Internet
Author: User
Tags extend

Implementation (2, 1, 7) convolutional code
Information Series 1001 1010 1111 1100
Generate sequence G1 = 1011011;G2 = 1111001
The initial state is all 0.
The above parameters can be modified by yourself in main.

Copy Code code as follows:

/***this is a simple example program of convolutional encoder.
*the information sequence, the register initial states and the generation sequence
* Can all is modified in the main function.
*/
#include <stdio.h>

#define LEN (array, len) {len=sizeof (array)/sizeof (array[0]); Size of Array

int encoder (int **gen, int n, int L, int reg[], int m, int inf[], int inf_len, int output[])
/*encoder (int **gen, int n, int L, int reg[], int m, int inf[], int inf_len, int output[])
*this function is a convolutional encoder.
*gen is the generation sequence, which is a two-dimension array,
And it is a two-dimension pointer,
*n is the number of bits out the encoder in each clock cycle,
*l is for the constraight length,
*reg is for the shift registers,
*m is for the number of registers,
*inf is for the information sequence,
*inf_len is for the INF length,
*output is for the output code.
*/
{
int Inf_ex[inf_len + M];

int I,j;//index

 for (I=0;i < Inf_len + m;i++)//extend The information sequence to include the last M bits
 {
   if (i < Inf_len)
   inf_ex[i] = inf[i];
  else
   inf_ex[i] = 0;
&NBSP}
 for (I=0;i < Inf_len + m;i++)//foreach bit in extend information
 {
  for (j=0; J < n;j++)//output n bits at each clock cycle
  {
      int out_tem=0;//temp Number
   if (* (gen + l*j) = 1)//judge Whether the next information bit should paticipate in the Mod op
                Out_tem + + inf_ex[ I];

int k;
For (K=0;k < m;k++)//foreach registers
{
if (* (Gen + l*j + k + 1) = = 1)
Out_tem = Reg[k];//mod OP According to the generation sequence
}
Out_tem%= 2;//mod 2
Output[i*n + j] = Out_tem;
}

for (J=m-1;j > 0;j--)//register shift
{
REG[J] = reg[j-1];
}
REG[0] = Inf_ex[i];//input information bits into register
}

return 1;
}

Main ()
{
int inf[]={1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0};//information sequence
int inf_len;//information Length
LEN (INF, Inf_len);

int gen[2][7]={{1, 0, 1, 1, 0, 1, 1}, {1, 1, 1, 1, 0, 0, 1}};//generation sequence
int n;//the number of bits out the encoder in each clock cycle
int l;//constraight Length
LEN (gen, N);
LEN (Gen[0], L);
int m=l-1;//the number of shift registers

int init_s[]={0, 0, 0, 0, 0, 0}; Initial states are all zero

int Reg[m];//register

int I;//index

For (I=0;i < m;i++)
{
Reg[i] = init_s[i];
}

int output_len= (Inf_len + m) *n;//output length, every bit of input can generate n bits of output sequence
int output[(Inf_len + m) *n];//output sequence
Encoder (gen, N, L, Reg, M, INF, Inf_len, output);//encoder

For (I=0;i < output_len;i++)
{
printf ("%d", output[i]);
}
System ("pause");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.