欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

利用c語言實現(xiàn)卷積碼編碼器示例

 更新時間:2014年03月29日 09:32:08   作者:  
這篇文章主要介紹了利用c語言實現(xiàn)卷積碼編碼器示例,需要的朋友可以參考下

實現(xiàn)(2, 1, 7)卷積碼編碼
信息序列1001 1010 1111 1100
生成序列g(shù)1 = 1011011;g2 = 1111001
初始狀態(tài)全0.
以上參數(shù)可自行在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++超詳細講解隱藏私有屬性和方法的兩種實現(xiàn)方式

    C++超詳細講解隱藏私有屬性和方法的兩種實現(xiàn)方式

    為了避免因為將類庫中的私有成員開放給類的使用方而導致的軟件邏輯外泄,因此需要將對外代碼中的私有成員隱藏起來,下面我們來了解一下隱藏私有屬性和方法的兩種實現(xiàn)方式
    2022-05-05
  • C++二維數(shù)組中數(shù)組元素存儲地址的計算疑問講解

    C++二維數(shù)組中數(shù)組元素存儲地址的計算疑問講解

    今天小編就為大家分享一篇關于C++二維數(shù)組中數(shù)組元素存儲地址的計算疑問講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-02-02
  • C語言實現(xiàn)貪吃蛇游戲(單人版)

    C語言實現(xiàn)貪吃蛇游戲(單人版)

    這篇文章主要為大家詳細介紹了C語言實現(xiàn)貪吃蛇游戲單人版,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • 一篇文章帶你入門C語言:函數(shù)

    一篇文章帶你入門C語言:函數(shù)

    這篇文章主要介紹了C語言中函數(shù)的聲明、定義及使用的入門教程,重點講述了main函數(shù)的相關知識,需要的朋友可以參考下,希望能給你帶來幫助
    2021-08-08
  • VS2019如何創(chuàng)建C++項目的實現(xiàn)示例

    VS2019如何創(chuàng)建C++項目的實現(xiàn)示例

    這篇文章主要介紹了VS2019如何創(chuàng)建C++項目的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-08-08
  • C++操作MySQL的實現(xiàn)示例

    C++操作MySQL的實現(xiàn)示例

    這篇文章主要介紹了C++操作MySQL的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-04-04
  • C\C++ 獲取當前路徑實例詳解

    C\C++ 獲取當前路徑實例詳解

    這篇文章主要介紹了C\C++ 獲取當前路徑實例詳解的相關資料,需要的朋友可以參考下
    2017-06-06
  • 詳解C++循環(huán)創(chuàng)建多級目錄及判斷目錄是否存在的方法

    詳解C++循環(huán)創(chuàng)建多級目錄及判斷目錄是否存在的方法

    這篇文章主要介紹了C++循環(huán)創(chuàng)建多級目錄及判斷目錄是否存在的方法,文中代碼有一個針對各種系統(tǒng)進行判斷來加載不同頭文件的方法,需要的朋友可以參考下
    2016-03-03
  • 冒泡排序的三種實現(xiàn)方法

    冒泡排序的三種實現(xiàn)方法

    本篇文章是對冒泡排序的三種實現(xiàn)方法進行了詳細的介紹,需要的朋友可以過來參考下。希望對大家有所幫助
    2013-10-10
  • 詳解C++?OpenCV實現(xiàn)圖像拼接的原理及方法

    詳解C++?OpenCV實現(xiàn)圖像拼接的原理及方法

    本文以實現(xiàn)圖像拼接為目標,把分割開的圖像進行拼接還原,核心的內(nèi)容包括:OpenCV圖像拼接相關原理以及OpenCV圖像拼接案例的實現(xiàn),感興趣的可以了解一下
    2022-07-07

最新評論