📄 viterbi_decode.c
字号:
/*
* MATLAB Compiler: 2.2
* Date: Fri May 24 10:57:35 2002
* Arguments: "-B" "macro_default" "-O" "all" "-O" "fold_scalar_mxarrays:on"
* "-O" "fold_non_scalar_mxarrays:on" "-O" "optimize_integer_for_loops:on" "-O"
* "array_indexing:on" "-O" "optimize_conditionals:on" "-x" "-W" "mex" "-L" "C"
* "-t" "-T" "link:mexlibrary" "libmatlbmx.mlib" "viterbi_decode.m"
*/
#include "viterbi_decode.h"
#include "libmatlbm.h"
static mxChar _array1_[146] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
'l', 'e', ':', ' ', 'v', 'i', 't', 'e', 'r',
'b', 'i', '_', 'd', 'e', 'c', 'o', 'd', 'e',
' ', 'L', 'i', 'n', 'e', ':', ' ', '5', ' ',
'C', 'o', 'l', 'u', 'm', 'n', ':', ' ', '1',
' ', 'T', 'h', 'e', ' ', 'f', 'u', 'n', 'c',
't', 'i', 'o', 'n', ' ', '"', 'v', 'i', 't',
'e', 'r', 'b', 'i', '_', 'd', 'e', 'c', 'o',
'd', 'e', '"', ' ', 'w', 'a', 's', ' ', 'c',
'a', 'l', 'l', 'e', 'd', ' ', 'w', 'i', 't',
'h', ' ', 'm', 'o', 'r', 'e', ' ', 't', 'h',
'a', 'n', ' ', 't', 'h', 'e', ' ', 'd', 'e',
'c', 'l', 'a', 'r', 'e', 'd', ' ', 'n', 'u',
'm', 'b', 'e', 'r', ' ', 'o', 'f', ' ', 'o',
'u', 't', 'p', 'u', 't', 's', ' ', '(', '1',
')', '.' };
static mxArray * _mxarray0_;
static mxChar _array3_[145] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
'l', 'e', ':', ' ', 'v', 'i', 't', 'e', 'r',
'b', 'i', '_', 'd', 'e', 'c', 'o', 'd', 'e',
' ', 'L', 'i', 'n', 'e', ':', ' ', '5', ' ',
'C', 'o', 'l', 'u', 'm', 'n', ':', ' ', '1',
' ', 'T', 'h', 'e', ' ', 'f', 'u', 'n', 'c',
't', 'i', 'o', 'n', ' ', '"', 'v', 'i', 't',
'e', 'r', 'b', 'i', '_', 'd', 'e', 'c', 'o',
'd', 'e', '"', ' ', 'w', 'a', 's', ' ', 'c',
'a', 'l', 'l', 'e', 'd', ' ', 'w', 'i', 't',
'h', ' ', 'm', 'o', 'r', 'e', ' ', 't', 'h',
'a', 'n', ' ', 't', 'h', 'e', ' ', 'd', 'e',
'c', 'l', 'a', 'r', 'e', 'd', ' ', 'n', 'u',
'm', 'b', 'e', 'r', ' ', 'o', 'f', ' ', 'i',
'n', 'p', 'u', 't', 's', ' ', '(', '6', ')',
'.' };
static mxArray * _mxarray2_;
static mxArray * _mxarray4_;
static mxArray * _mxarray5_;
static mxArray * _mxarray6_;
static mxArray * _mxarray7_;
static mxArray * _mxarray8_;
static mxArray * _mxarray9_;
void InitializeModule_viterbi_decode(void) {
_mxarray0_ = mclInitializeString(146, _array1_);
_mxarray2_ = mclInitializeString(145, _array3_);
_mxarray4_ = mclInitializeDouble(2.0);
_mxarray5_ = mclInitializeDouble(1.0);
_mxarray6_ = mclInitializeDoubleVector(0, 0, (double *)NULL);
_mxarray7_ = mclInitializeDouble(-1.0);
_mxarray8_ = mclInitializeDouble(0.0);
_mxarray9_ = mclInitializeDouble(-10000.0);
}
void TerminateModule_viterbi_decode(void) {
mxDestroyArray(_mxarray9_);
mxDestroyArray(_mxarray8_);
mxDestroyArray(_mxarray7_);
mxDestroyArray(_mxarray6_);
mxDestroyArray(_mxarray5_);
mxDestroyArray(_mxarray4_);
mxDestroyArray(_mxarray2_);
mxDestroyArray(_mxarray0_);
}
static mxArray * Mviterbi_decode(int nargout_,
mxArray * code,
mxArray * n,
mxArray * k,
mxArray * N,
mxArray * GEN,
mxArray * select);
_mexLocalFunctionTable _local_function_table_viterbi_decode
= { 0, (mexFunctionTableEntry *)NULL };
/*
* The function "mlfViterbi_decode" contains the normal interface for the
* "viterbi_decode" M-function from file
* "E:\工作资料\matlab\lowgain\viterbi_decode.m" (lines 1-61). This function
* processes any input arguments and passes them to the implementation version
* of the function, appearing above.
*/
mxArray * mlfViterbi_decode(mxArray * code,
mxArray * n,
mxArray * k,
mxArray * N,
mxArray * GEN,
mxArray * select) {
int nargout = 1;
mxArray * output = mclGetUninitializedArray();
mlfEnterNewContext(0, 6, code, n, k, N, GEN, select);
output = Mviterbi_decode(nargout, code, n, k, N, GEN, select);
mlfRestorePreviousContext(0, 6, code, n, k, N, GEN, select);
return mlfReturnValue(output);
}
/*
* The function "mlxViterbi_decode" contains the feval interface for the
* "viterbi_decode" M-function from file
* "E:\工作资料\matlab\lowgain\viterbi_decode.m" (lines 1-61). The feval
* function calls the implementation version of viterbi_decode through this
* function. This function processes any input arguments and passes them to the
* implementation version of the function, appearing above.
*/
void mlxViterbi_decode(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
mxArray * mprhs[6];
mxArray * mplhs[1];
int i;
if (nlhs > 1) {
mlfError(_mxarray0_);
}
if (nrhs > 6) {
mlfError(_mxarray2_);
}
for (i = 0; i < 1; ++i) {
mplhs[i] = mclGetUninitializedArray();
}
for (i = 0; i < 6 && i < nrhs; ++i) {
mprhs[i] = prhs[i];
}
for (; i < 6; ++i) {
mprhs[i] = NULL;
}
mlfEnterNewContext(
0, 6, mprhs[0], mprhs[1], mprhs[2], mprhs[3], mprhs[4], mprhs[5]);
mplhs[0]
= Mviterbi_decode(
nlhs, mprhs[0], mprhs[1], mprhs[2], mprhs[3], mprhs[4], mprhs[5]);
mlfRestorePreviousContext(
0, 6, mprhs[0], mprhs[1], mprhs[2], mprhs[3], mprhs[4], mprhs[5]);
plhs[0] = mplhs[0];
}
/*
* The function "Mviterbi_decode" is the implementation version of the
* "viterbi_decode" M-function from file
* "E:\工作资料\matlab\lowgain\viterbi_decode.m" (lines 1-61). It contains the
* actual compiled code for that M-function. It is a static function and must
* only be called from one of the interface functions, appearing below.
*/
/*
* %**********************************************************************
* % This function decodes the encoding sequence with viterbi algorithm *
* % only for (n,1,N) convolution codes with hard or soft input data. *
* %**********************************************************************
* function output=viterbi_decode(code,n,k,N,GEN,select)
*/
static mxArray * Mviterbi_decode(int nargout_,
mxArray * code,
mxArray * n,
mxArray * k,
mxArray * N,
mxArray * GEN,
mxArray * select) {
mexLocalFunctionTable save_local_function_table_
= mclSetCurrentLocalFunctionTable(&_local_function_table_viterbi_decode);
mxArray * output = mclGetUninitializedArray();
mxArray * search = mclGetUninitializedArray();
mxArray * history = mclGetUninitializedArray();
mxArray * path_value = mclGetUninitializedArray();
mxArray * bit = mclGetUninitializedArray();
mxArray * metric = mclGetUninitializedArray();
mxArray * metirc = mclGetUninitializedArray();
mxArray * y = mclGetUninitializedArray();
mxArray * ii = mclGetUninitializedArray();
mxArray * a = mclGetUninitializedArray();
mxArray * state = mclGetUninitializedArray();
mxArray * j = mclGetUninitializedArray();
mxArray * deci = mclGetUninitializedArray();
mxArray * i = mclGetUninitializedArray();
mxArray * frame_length = mclGetUninitializedArray();
mxArray * state_num = mclGetUninitializedArray();
mclCopyArray(&code);
mclCopyArray(&n);
mclCopyArray(&k);
mclCopyArray(&N);
mclCopyArray(&GEN);
mclCopyArray(&select);
/*
*
* state_num=2^(N-1);
*/
mlfAssign(
&state_num, mclMpower(_mxarray4_, mclMinus(mclVa(N, "N"), _mxarray5_)));
/*
* frame_length=length(code)/n;%including added zeros
*/
mlfAssign(
&frame_length,
mclMrdivide(mlfScalar(mclLengthInt(mclVa(code, "code"))), mclVa(n, "n")));
/*
*
* %convert decimal to binary
* for i=1:state_num
*/
{
int v_ = mclForIntStart(1);
int e_ = mclForIntEnd(mclVv(state_num, "state_num"));
if (v_ > e_) {
mlfAssign(&i, _mxarray6_);
} else {
/*
* deci=i-1;
* for j=N-1:-1:1
* state(i,j)=rem(deci,2); %first calculate the MSB; MSB-->LSB
* deci=fix(deci/2);
* end
* end
*/
for (; ; ) {
mlfAssign(&deci, mlfScalar(v_ - 1));
{
mclForLoopIterator viter__;
for (mclForStart(
&viter__,
mclMinus(mclVa(N, "N"), _mxarray5_),
_mxarray7_,
_mxarray5_);
mclForNext(&viter__, &j);
) {
mclArrayAssign2(
&state,
mlfRem(mclVv(deci, "deci"), _mxarray4_),
mlfScalar(v_),
mclVsv(j, "j"));
mlfAssign(
&deci,
mlfFix(mclMrdivide(mclVv(deci, "deci"), _mxarray4_)));
}
mclDestroyForLoopIterator(viter__);
}
if (v_ == e_) {
break;
}
++v_;
}
mlfAssign(&i, mlfScalar(v_));
}
}
/*
*
* %get two emit branchs of state i
* for i=1:state_num
*/
{
int v_ = mclForIntStart(1);
int e_ = mclForIntEnd(mclVv(state_num, "state_num"));
if (v_ > e_) {
mlfAssign(&i, _mxarray6_);
} else {
/*
* for j=1:2^k
* a=[j-1,state(i,:)];%input=0 or 1
* for ii=1:n
* y(j,ii,i)=rem(sum(bitand(a,GEN(ii,:))),2);
* end
* end
* end
*/
for (; ; ) {
int v_0 = mclForIntStart(1);
int e_0 = mclForIntEnd(mclMpower(_mxarray4_, mclVa(k, "k")));
if (v_0 > e_0) {
mlfAssign(&j, _mxarray6_);
} else {
for (; ; ) {
mlfAssign(
&a,
mlfHorzcat(
mlfScalar(v_0 - 1),
mclVe(
mclArrayRef2(
mclVsv(state, "state"),
mlfScalar(v_),
mlfCreateColonIndex())),
NULL));
{
int v_1 = mclForIntStart(1);
int e_1 = mclForIntEnd(mclVa(n, "n"));
if (v_1 > e_1) {
mlfAssign(&ii, _mxarray6_);
} else {
for (; ; ) {
mlfIndexAssign(
&y,
"(?,?,?)",
mlfScalar(v_0),
mlfScalar(v_1),
mlfScalar(v_),
mlfRem(
mclVe(
mlfSum(
mclVe(
mlfBitand(
mclVv(a, "a"),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -