服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C/C++ - 利用c语言实现卷积码编码器示例

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

2021-01-18 10:22C语言程序设计 C/C++

这篇文章主要介绍了利用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++C语言实现双人五子棋游戏

    C语言实现双人五子棋游戏

    这篇文章主要为大家详细介绍了C语言实现双人五子棋游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    两片空白7312021-11-12
  • C/C++OpenCV实现拼接图像的简单方法

    OpenCV实现拼接图像的简单方法

    这篇文章主要为大家详细介绍了OpenCV实现拼接图像的简单方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    iteye_183805102021-07-29
  • C/C++c/c++内存分配大小实例讲解

    c/c++内存分配大小实例讲解

    在本篇文章里小编给大家整理了一篇关于c/c++内存分配大小实例讲解内容,有需要的朋友们可以跟着学习参考下。...

    jihite5172022-02-22
  • C/C++c/c++实现获取域名的IP地址

    c/c++实现获取域名的IP地址

    本文给大家汇总介绍了使用c/c++实现获取域名的IP地址的几种方法以及这些方法的核心函数gethostbyname的详细用法,非常的实用,有需要的小伙伴可以参考下...

    C++教程网10262021-03-16
  • C/C++使用C++制作简单的web服务器(续)

    使用C++制作简单的web服务器(续)

    本文承接上文《使用C++制作简单的web服务器》,把web服务器做的功能稍微强大些,主要增加的功能是从文件中读取网页并返回给客户端,而不是把网页代码...

    C++教程网5492021-02-22
  • C/C++C语言main函数的三种形式实例详解

    C语言main函数的三种形式实例详解

    这篇文章主要介绍了 C语言main函数的三种形式实例详解的相关资料,需要的朋友可以参考下...

    ieearth6912021-05-16
  • C/C++关于C语言中E-R图的详解

    关于C语言中E-R图的详解

    今天小编就为大家分享一篇关于关于C语言中E-R图的详解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看...

    Struggler095962021-07-12
  • C/C++深入C++拷贝构造函数的总结详解

    深入C++拷贝构造函数的总结详解

    本篇文章是对C++中拷贝构造函数进行了总结与介绍。需要的朋友参考下...

    C++教程网5182020-11-30