利用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++ STL之list双向链表容器方式

    C++ STL之list双向链表容器方式

    这篇文章主要介绍了C++ STL之list双向链表容器方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-04-04
  • VS2019安装cbd调试器的实现步骤

    VS2019安装cbd调试器的实现步骤

    本文主要介绍了VS2019安装cbd调试器的实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-12-12
  • Qt利用QPainter实现基本绘图的示例详解

    Qt利用QPainter实现基本绘图的示例详解

    Qt 中提供了强大的 2D 绘图系统,可以使用相同的 API 在屏幕和绘图设备上进行绘制,它主要基于QPainter、QPaintDevice 和 QPaintEngine 这三个类。本文主要和大家介绍一下QPainter实现的基本绘图,感兴趣的可以了解一下
    2022-12-12
  • C语言实现通讯录功能

    C语言实现通讯录功能

    这篇文章主要为大家详细介绍了C语言实现通讯录功能,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-02-02
  • Windows环境给FFmpeg集成AVS3解码器

    Windows环境给FFmpeg集成AVS3解码器

    libuavs3d是AVS3标准的解码器,支持windows/linux/arm/ios等所有常用平台,在移动端最高支持4K/30fps视频实时解码,解码速度大幅领先AV1开源解码器dav1d和aomdec,由于FFmpeg默认未启用libuavs3d,因此需要重新配置FFmpeg,标明启用libuavs3d,然后重新编译安装FFmpeg
    2024-05-05
  • C语言实现图书管理系统

    C语言实现图书管理系统

    这篇文章主要为大家详细介绍了C语言实现图书管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-01-01
  • C++教程(超长最全入门)

    C++教程(超长最全入门)

    这篇文章主要介绍了C++教程(超长最全),需要的朋友可以参考下
    2023-05-05
  • C语言中动态内存管理初学者容易犯的6个错误分享

    C语言中动态内存管理初学者容易犯的6个错误分享

    本篇文章主要介绍了初学者使用C语言中动态内存管理的4个函数时最容易犯的6个错误,以及如何避免这些错误,文中的示例代码讲解详细,感兴趣的可以了解一下
    2023-04-04
  • 浅谈C++中派生类对象的内存布局

    浅谈C++中派生类对象的内存布局

    下面小编就为大家带来一篇浅谈C++中派生类对象的内存布局。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-12-12
  • 全局变量与局部变量在内存中的区别详细解析

    全局变量与局部变量在内存中的区别详细解析

    以下是对全局变量与局部变量在内存中的区别进行了详细的总结介绍,需要的朋友可以过来参考下,希望对大家有所帮助
    2013-10-10

最新评论