利用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)方式
為了避免因為將類庫中的私有成員開放給類的使用方而導致的軟件邏輯外泄,因此需要將對外代碼中的私有成員隱藏起來,下面我們來了解一下隱藏私有屬性和方法的兩種實現(xiàn)方式2022-05-05C++二維數(shù)組中數(shù)組元素存儲地址的計算疑問講解
今天小編就為大家分享一篇關于C++二維數(shù)組中數(shù)組元素存儲地址的計算疑問講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-02-02VS2019如何創(chuàng)建C++項目的實現(xiàn)示例
這篇文章主要介紹了VS2019如何創(chuàng)建C++項目的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-08-08詳解C++循環(huán)創(chuàng)建多級目錄及判斷目錄是否存在的方法
這篇文章主要介紹了C++循環(huán)創(chuàng)建多級目錄及判斷目錄是否存在的方法,文中代碼有一個針對各種系統(tǒng)進行判斷來加載不同頭文件的方法,需要的朋友可以參考下2016-03-03詳解C++?OpenCV實現(xiàn)圖像拼接的原理及方法
本文以實現(xiàn)圖像拼接為目標,把分割開的圖像進行拼接還原,核心的內(nèi)容包括:OpenCV圖像拼接相關原理以及OpenCV圖像拼接案例的實現(xiàn),感興趣的可以了解一下2022-07-07