利用c语言实现卷积码编码器示例

 更新时间:2014年03月29日 09:32:08   作者:  
这篇文章主要介绍了利用c语言实现卷积码编码器示例,需要的朋友可以参考下

实现(2, 1, 7)卷积码编码
信息序列1001 1010 1111 1100
生成序列g1 = 1011011;g2 = 1111001
初始状态全0.
以上参数可自行在main中修改。

复制代码 代码如下:

/***This is an simple example program of convolutional encoder.
   *The information sequence, the register initial states and the generation sequence
   *    can all be 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 at 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;
 }
 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 at 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");
}

相关文章

  • C++超详细讲解隐藏私有属性和方法的两种实现方式

    C++超详细讲解隐藏私有属性和方法的两种实现方式

    为了避免因为将类库中的私有成员开放给类的使用方而导致的软件逻辑外泄,因此需要将对外代码中的私有成员隐藏起来,下面我们来了解一下隐藏私有属性和方法的两种实现方式
    2022-05-05
  • C++二维数组中数组元素存储地址的计算疑问讲解

    C++二维数组中数组元素存储地址的计算疑问讲解

    今天小编就为大家分享一篇关于C++二维数组中数组元素存储地址的计算疑问讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
    2019-02-02
  • C语言实现贪吃蛇游戏(单人版)

    C语言实现贪吃蛇游戏(单人版)

    这篇文章主要为大家详细介绍了C语言实现贪吃蛇游戏单人版,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2020-06-06
  • 一篇文章带你入门C语言:函数

    一篇文章带你入门C语言:函数

    这篇文章主要介绍了C语言中函数的声明、定义及使用的入门教程,重点讲述了main函数的相关知识,需要的朋友可以参考下,希望能给你带来帮助
    2021-08-08
  • VS2019如何创建C++项目的实现示例

    VS2019如何创建C++项目的实现示例

    这篇文章主要介绍了VS2019如何创建C++项目的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-08-08
  • C++操作MySQL的实现示例

    C++操作MySQL的实现示例

    这篇文章主要介绍了C++操作MySQL的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-04-04
  • C\C++ 获取当前路径实例详解

    C\C++ 获取当前路径实例详解

    这篇文章主要介绍了C\C++ 获取当前路径实例详解的相关资料,需要的朋友可以参考下
    2017-06-06
  • 详解C++循环创建多级目录及判断目录是否存在的方法

    详解C++循环创建多级目录及判断目录是否存在的方法

    这篇文章主要介绍了C++循环创建多级目录及判断目录是否存在的方法,文中代码有一个针对各种系统进行判断来加载不同头文件的方法,需要的朋友可以参考下
    2016-03-03
  • 冒泡排序的三种实现方法

    冒泡排序的三种实现方法

    本篇文章是对冒泡排序的三种实现方法进行了详细的介绍,需要的朋友可以过来参考下。希望对大家有所帮助
    2013-10-10
  • 详解C++ OpenCV实现图像拼接的原理及方法

    详解C++ OpenCV实现图像拼接的原理及方法

    本文以实现图像拼接为目标,把分割开的图像进行拼接还原,核心的内容包括:OpenCV图像拼接相关原理以及OpenCV图像拼接案例的实现,感兴趣的可以了解一下
    2022-07-07

最新评论