利用c語(yǔ)言實(shí)現(xiàn)卷積碼編碼器示例
實(shí)現(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語(yǔ)言隨機(jī)數(shù)函數(shù)示例
欄 目:C語(yǔ)言
下一篇:vc6.0中c語(yǔ)言控制臺(tái)程序中的定時(shí)技術(shù)(定時(shí)器)
本文標(biāo)題:利用c語(yǔ)言實(shí)現(xiàn)卷積碼編碼器示例
本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/3706.html
您可能感興趣的文章
- 04-02c語(yǔ)言函數(shù)調(diào)用后清空內(nèi)存 c語(yǔ)言調(diào)用函數(shù)刪除字符
- 04-02c語(yǔ)言的正則匹配函數(shù) c語(yǔ)言正則表達(dá)式函數(shù)庫(kù)
- 04-02func函數(shù)+在C語(yǔ)言 func函數(shù)在c語(yǔ)言中
- 04-02c語(yǔ)言中對(duì)數(shù)函數(shù)的表達(dá)式 c語(yǔ)言中對(duì)數(shù)怎么表達(dá)
- 04-02c語(yǔ)言用函數(shù)寫(xiě)分段 用c語(yǔ)言表示分段函數(shù)
- 04-02c語(yǔ)言編寫(xiě)函數(shù)冒泡排序 c語(yǔ)言冒泡排序法函數(shù)
- 04-02c語(yǔ)言沒(méi)有round函數(shù) round c語(yǔ)言
- 04-02c語(yǔ)言分段函數(shù)怎么求 用c語(yǔ)言求分段函數(shù)
- 04-02C語(yǔ)言中怎么打出三角函數(shù) c語(yǔ)言中怎么打出三角函數(shù)的值
- 04-02c語(yǔ)言調(diào)用函數(shù)求fibo C語(yǔ)言調(diào)用函數(shù)求階乘


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 04-02c語(yǔ)言函數(shù)調(diào)用后清空內(nèi)存 c語(yǔ)言調(diào)用
- 04-02func函數(shù)+在C語(yǔ)言 func函數(shù)在c語(yǔ)言中
- 04-02c語(yǔ)言的正則匹配函數(shù) c語(yǔ)言正則表達(dá)
- 04-02c語(yǔ)言用函數(shù)寫(xiě)分段 用c語(yǔ)言表示分段
- 04-02c語(yǔ)言中對(duì)數(shù)函數(shù)的表達(dá)式 c語(yǔ)言中對(duì)
- 04-02c語(yǔ)言編寫(xiě)函數(shù)冒泡排序 c語(yǔ)言冒泡排
- 04-02c語(yǔ)言沒(méi)有round函數(shù) round c語(yǔ)言
- 04-02c語(yǔ)言分段函數(shù)怎么求 用c語(yǔ)言求分段
- 04-02C語(yǔ)言中怎么打出三角函數(shù) c語(yǔ)言中怎
- 04-02c語(yǔ)言調(diào)用函數(shù)求fibo C語(yǔ)言調(diào)用函數(shù)求
隨機(jī)閱讀
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 01-11Mac OSX 打開(kāi)原生自帶讀寫(xiě)NTFS功能(圖文
- 04-02jquery與jsp,用jquery
- 01-10delphi制作wav文件的方法
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?
- 01-10C#中split用法實(shí)例總結(jié)
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載
- 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什