/*******************************************************************************************
MAP decoder Simulation in C
Note :
-------
This program is used to simulate the Maximum A-Posteriori Probability algorithm in C.
Since this program is used only for simulation, I have not done much of code optimization (as
well as memory optimization). So this program might run a bit slower. I'll try to optimize the
code and memory requirements and update this program as soon as possible.
Parameters :
---------------
Thus MAP algorithm will decode a single convolutional code. The parameters of the convolutional
code can be easily set by modifying the N_STATES, POSSIBLE_INPUTS, NextStates[] and ActualOutputs[][]
in accordance with the code that you have used.
Documentation :
----------------
Detailed comments are provided throughout this Code. There will not be much problems in reading it.
For some good explanation about this algorithm, please visit this page.
http://www.redrival.com/rvc/faq/map.htm
This page is a FAQ on this algorithm that I have prepared. It is better to read that FAQ first before
going thro' this code.
For comments and suggestion drop me line at vc@lucent.com.
Important Notes :
------------------
1. I have used Likehood ratios instead of Log-Likehood ratios currently, because of some numerical
instability problems. I will correct the code later.
2. The trellis is assumed to be terminated. If this is not the case, the funtion InitializeBetas()
has to be modified. (A general purpose function can also be provided.. but unnecessary 'cause
the trellis is normally terminated in most cases).
********************************************************************************************/
#include <stdio.h>
#include <math.h>
#include "intleave.h"
/* Some global Constants */
/* Defines the possible no of inputs for a given state. It will be 2^(input block length).*/
#define POSSIBLE_INPUTS 2
#define N_STATES 4 /* Total no of states in the state machine */
#define BLOCK_LENGTH 18 /* Length of the block to be decoded */
#define NUM_OUTPUTS 2 /* No of outputs in the Convolutional Encoder. */
/* List of Global Variables and Arrays used */
/* ======================================== */
/* This table holds the values of the next states */
/* This table can also be calculated dynamically using the static variables and bit shifts.*/
int NextStates[N_STATES*POSSIBLE_INPUTS] = {0,2,2,0,3,1,1,3};
/* This array holds the actual outputs of the channel encoder */
int ActualOutputs[N_STATES*POSSIBLE_INPUTS][NUM_OUTPUTS] = {{0,0},{1,1},{0,0},{1,1},{0,1},{1,0},{0,1},{1,0}};
/* This array holds tha outputs that were received from the demodulator (Corrupted Outputs) */
//int NoisyOutputs[NUM_OUTPUTS][BLOCK_LENGTH] = {{0,0},{1,1},{0,1},{1,0},{0,1},{1,1},{0,0},{1,1},{0,1},{1,0},{0,1},{1,1},{0,0},{1,1},{0,1},{1,0},{0,1},{1,1}};
int NormalOutputs[BLOCK_LENGTH][NUM_OUTPUTS] = {{0,0},{1,1},{0,1},{1,0},{0,1},{1,1},{0,0},{1,1},{0,1},{1,0},{0,1},{1,1},{0,0},{1,1},{0,1},{1,0},{0,1},{1,1}};
/* This table will hold the values of alpha */
double Alpha[N_STATES][BLOCK_LENGTH+1];
/* This table will hold the values of beta */
double Beta[N_STATES][BLOCK_LENGTH+1];
/* This array will hold the outputs of the Channel Demodulator */
/* Since they are declared as 'int', they can be configured for soft-decision */
int Outputs[BLOCK_LENGTH][NUM_OUTPUTS];
/* This array will hold the resultant LLR's after the decoding process. */
/* These LLR's will constitute the input to the next stage */
/* Please note that, I am currently using just LR's instead of LLR's */
double LLR[BLOCK_LENGTH];
/* This table holds the apriori probabilities (from the previous decoder or demodulator) */
/* Remember that this probabilities are Log-Likelihood ratios in the case of iterative decoding */
double aPrioriProbs[BLOCK_LENGTH] = {.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,.5,0.5,0.5};
/* Function Declarations. -- You won't see all the declarations here */
/* Please see the function implementation for details of its execution and interfaces */
int GetNextState(int PresentState,int EncoderInputs);
double GetAprioriProbability(int TimeIndex);
//-----------------------------------------------------------------------------------------//
// GetNextState(..) - Function
//==============================
// This function gets the next state for a given present state..
// currently uses table look-up... can be converted such that the corresponding
// values can be calculated using bit-shifts.
//
// Inputs:
// =======
// PresentState -- This is the present state bit vector of the state machine.
// EncoderInputs -- This is the input bit vector to the encoder state machine
//
// Output:
// =======
// The Next State bit vector of the state machine.
//-----------------------------------------------------------------------------------------//
int GetNextState(int PresentState, int EncoderInputs)
{
return NextStates[PresentState*POSSIBLE_INPUTS+EncoderInputs];
}
//-----------------------------------------------------------------------------------------//
// GetAprioriProbability(..) - Function
// =====================================
// This function returns the apriori probabilities of the input at the given
// time index. The LLR's are converted into probabilities in this function. The
// Probability of being a '0' is returned. The other prob can be found by subtracting
// it from 1.
//
// Note :: Currently I am using just the Likelihood ratios, rather than log-likelihood
// ratios (LLR's gave some math instability problems..).
//
// Inputs
// -------
// int TimeIndex -- The time index at which these probabilities are needed.
//
// Outputs
// --------
// double -- The apriori probability of the input at the given time index being a '0'
//-----------------------------------------------------------------------------------------//
double GetAprioriProbability(int TimeIndex)
{
return aPrioriProbs[TimeIndex];
// return ((double)1.0/(1+exp(aPrioriProbs[TimeIndex])));
}
//-----------------------------------------------------------------------------------------//
// IntializeAlphas() - Function
// ============================
// This function Initializes the values of the alpha array in the time index '0'.
// During this intialization we assume that we start in the state number '0'.
//-----------------------------------------------------------------------------------------//
void InitializeAlphas()
{
int j=0;
Alpha[0][0] = 1;
for(j=1 ; j<N_STATES ; j++)
Alpha[j][0] = 0;
}
//-----------------------------------------------------------------------------------------//
// CalculateEuclideanDistance(..) - Function
// ==========================================
// This function calculates the EuclideanDistance between the DecoderInputs and the
// actual outputs.
//
// Inputs :
// --------
// TimeIndex -- The Decoder Output Index.
// StateNumber, InputOfThatState -- Uniquely identify the actual output that must be
// compared with the decoder output.
//-----------------------------------------------------------------------------------------//
int CalculateEuclideanDistance(int TimeIndex, int StateNumber, int InputOfThatState)
{
int Sum = 0,i,Value;
for(i=0;i<NUM_OUTPUTS;i++)
{
Value = (NormalOutputs[TimeIndex][i] - ActualOutputs[StateNumber*POSSIBLE_INPUTS+InputOfThatState][i]);
Sum = Sum + Value*Value;
}
return Sum;
}
//-----------------------------------------------------------------------------------------//
// CalcGamma(..) -- Function
// ===========================
// Calculates the value of gamma for the given state transition s(i)->s(i+1).
// This function does the following things :
// -- Get the Apriori probability of the message bit at the given time instant.
// -- Calculate the Euclidean Channel Metric between the inputs and outputs of the channel.
// -- Using these, finds the value of Gamma for the given state transition.
//
// Inputs :
// ---------
// TimeIndex -- The value of 'i'
c语言写的图像插值算法
5星 · 超过95%的资源 需积分: 36 88 浏览量
2011-10-22
14:57:10
上传
评论 1
收藏 6KB ZIP 举报
sdqixr
- 粉丝: 0
- 资源: 3
最新资源
- 人工智能实验四 感知器算法的设计实现
- java小项目多线程多线程 复制文件 冒泡排序 群聊
- 四数之和(java代码).docx
- 701837906919458TapScanner v3.0.10 (Pro).apk
- 青岛大学人工智能实验二 利用α-β搜索的博弈树算法编写一字棋游戏
- ### 1、项目介绍 本项目Scrapy进行数据爬取,并使用Django框架+PyEcharts实现可视化大屏 效果如下:
- # 微信小程序-健康菜谱 基于微信小程序的一个查找检索菜谱的应用 ### 效果 !动态图(./res/gif/demo
- zabbix-get命令包资源
- 289ssm-mysql-jsp 计算机课程实验管理系统.zip(可运行源码+数据库文件+文档)
- 毕业设计,基于PyQt5实现的可视化界面的Python车牌自动识别系统源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页