利用c語言實現(xiàn)卷積碼編碼器示例
實現(xiàn)(2, 1, 7)卷積碼編碼
信息序列1001 1010 1111 1100
生成序列g1 = 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語言
本文地址:http://www.jygsgssxh.com/a1/Cyuyan/3706.html
您可能感興趣的文章
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用函數(shù)刪除字符
- 04-02c語言的正則匹配函數(shù) c語言正則表達式函數(shù)庫
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言中對數(shù)函數(shù)的表達式 c語言中對數(shù)怎么表達
- 04-02c語言用函數(shù)寫分段 用c語言表示分段函數(shù)
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排序法函數(shù)
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段函數(shù)
- 04-02C語言中怎么打出三角函數(shù) c語言中怎么打出三角函數(shù)的值
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求階乘


閱讀排行
本欄相關
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言的正則匹配函數(shù) c語言正則表達
- 04-02c語言用函數(shù)寫分段 用c語言表示分段
- 04-02c語言中對數(shù)函數(shù)的表達式 c語言中對
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段
- 04-02C語言中怎么打出三角函數(shù) c語言中怎
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求
隨機閱讀
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 04-02jquery與jsp,用jquery
- 01-10delphi制作wav文件的方法
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-10C#中split用法實例總結(jié)
- 01-11ajax實現(xiàn)頁面的局部加載
- 01-10SublimeText編譯C開發(fā)環(huán)境設置
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 08-05DEDE織夢data目錄下的sessions文件夾有什


