利用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(array0);//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_exinf_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 = inf;
else
inf_ex = 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;
int k;
for (k=0;k < m;k++)//Foreach registers
if (*(gen + L*j + k + 1) == 1)
out_tem += reg;//Mod op according to the generation sequence
out_tem %= 2;//Mod 2
outputi*n + j = out_tem;
for (j=m - 1;j > 0;j--)//Register shift
reg = regj - 1;
reg0 = inf_ex;//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 gen27=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(gen0, 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;//Register
int i;//Index
for (i=0;i < m;i++)
reg = init_s;
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);
system("pause");
您可能感兴趣的文章
- 04-02c语言函数调用后清空内存 c语言调用函数删除字符
- 04-02c语言的正则匹配函数 c语言正则表达式函数库
- 04-02func函数+在C语言 func函数在c语言中
- 04-02c语言中对数函数的表达式 c语言中对数怎么表达
- 04-02c语言用函数写分段 用c语言表示分段函数
- 04-02c语言编写函数冒泡排序 c语言冒泡排序法函数
- 04-02c语言没有round函数 round c语言
- 04-02c语言分段函数怎么求 用c语言求分段函数
- 04-02C语言中怎么打出三角函数 c语言中怎么打出三角函数的值
- 04-02c语言调用函数求fibo C语言调用函数求阶乘


阅读排行
本栏相关
- 04-02c语言函数调用后清空内存 c语言调用
- 04-02func函数+在C语言 func函数在c语言中
- 04-02c语言的正则匹配函数 c语言正则表达
- 04-02c语言用函数写分段 用c语言表示分段
- 04-02c语言中对数函数的表达式 c语言中对
- 04-02c语言编写函数冒泡排序 c语言冒泡排
- 04-02c语言没有round函数 round c语言
- 04-02c语言分段函数怎么求 用c语言求分段
- 04-02C语言中怎么打出三角函数 c语言中怎
- 04-02c语言调用函数求fibo C语言调用函数求
随机阅读
- 08-05dedecms(织梦)副栏目数量限制代码修改
- 01-11Mac OSX 打开原生自带读写NTFS功能(图文
- 04-02jquery与jsp,用jquery
- 01-10delphi制作wav文件的方法
- 08-05织梦dedecms什么时候用栏目交叉功能?
- 01-10C#中split用法实例总结
- 01-11ajax实现页面的局部加载
- 01-10SublimeText编译C开发环境设置
- 01-10使用C语言求解扑克牌的顺子及n个骰子
- 08-05DEDE织梦data目录下的sessions文件夹有什