📄 add_noise.c
字号:
/*
* MATLAB Compiler: 3.0
* Date: Fri Mar 24 11:31:36 2006
* 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" "-m" "-W" "main" "-L"
* "C" "-t" "-T" "link:exe" "-h" "libmmfile.mlib"
* "adptive_bitpow_allocate_systems"
*/
#include "add_noise.h"
#include "libmatlbm.h"
#include "normrnd.h"
static mxArray * _mxarray0_;
static mxArray * _mxarray1_;
static mxArray * _mxarray2_;
void InitializeModule_add_noise(void) {
_mxarray0_ = mclInitializeDoubleVector(0, 0, (double *)NULL);
_mxarray1_ = mclInitializeDouble(0.0);
_mxarray2_ = mclInitializeDouble(-1.0);
}
void TerminateModule_add_noise(void) {
mxDestroyArray(_mxarray2_);
mxDestroyArray(_mxarray1_);
mxDestroyArray(_mxarray0_);
}
static mxArray * Madd_noise(int nargout_, mxArray * sgma, mxArray * input);
_mexLocalFunctionTable _local_function_table_add_noise
= { 0, (mexFunctionTableEntry *)NULL };
/*
* The function "mlfAdd_noise" contains the normal interface for the
* "add_noise" M-function from file
* "c:\matlab6p5\work\adptive_ofdm\adptive_ofdm\add_noise.m" (lines 1-9). This
* function processes any input arguments and passes them to the implementation
* version of the function, appearing above.
*/
mxArray * mlfAdd_noise(mxArray * sgma, mxArray * input) {
int nargout = 1;
mxArray * output = NULL;
mlfEnterNewContext(0, 2, sgma, input);
output = Madd_noise(nargout, sgma, input);
mlfRestorePreviousContext(0, 2, sgma, input);
return mlfReturnValue(output);
}
/*
* The function "mlxAdd_noise" contains the feval interface for the "add_noise"
* M-function from file
* "c:\matlab6p5\work\adptive_ofdm\adptive_ofdm\add_noise.m" (lines 1-9). The
* feval function calls the implementation version of add_noise through this
* function. This function processes any input arguments and passes them to the
* implementation version of the function, appearing above.
*/
void mlxAdd_noise(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
mxArray * mprhs[2];
mxArray * mplhs[1];
int i;
if (nlhs > 1) {
mlfError(
mxCreateString(
"Run-time Error: File: add_noise Line: 1 Column:"
" 1 The function \"add_noise\" was called with m"
"ore than the declared number of outputs (1)."),
NULL);
}
if (nrhs > 2) {
mlfError(
mxCreateString(
"Run-time Error: File: add_noise Line: 1 Column:"
" 1 The function \"add_noise\" was called with m"
"ore than the declared number of inputs (2)."),
NULL);
}
for (i = 0; i < 1; ++i) {
mplhs[i] = NULL;
}
for (i = 0; i < 2 && i < nrhs; ++i) {
mprhs[i] = prhs[i];
}
for (; i < 2; ++i) {
mprhs[i] = NULL;
}
mlfEnterNewContext(0, 2, mprhs[0], mprhs[1]);
mplhs[0] = Madd_noise(nlhs, mprhs[0], mprhs[1]);
mlfRestorePreviousContext(0, 2, mprhs[0], mprhs[1]);
plhs[0] = mplhs[0];
}
/*
* The function "Madd_noise" is the implementation version of the "add_noise"
* M-function from file
* "c:\matlab6p5\work\adptive_ofdm\adptive_ofdm\add_noise.m" (lines 1-9). 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.
*/
/*
* function output=add_noise(sgma,input)
*/
static mxArray * Madd_noise(int nargout_, mxArray * sgma, mxArray * input) {
mexLocalFunctionTable save_local_function_table_
= mclSetCurrentLocalFunctionTable(&_local_function_table_add_noise);
mxArray * output = NULL;
mxArray * noise = NULL;
mxArray * m = NULL;
mxArray * k = NULL;
mxArray * nl = NULL;
mxArray * n = NULL;
mclCopyArray(&sgma);
mclCopyArray(&input);
/*
* [n,nl]=size(input);
*/
mlfSize(mlfVarargout(&n, &nl, NULL), mclVa(input, "input"), NULL);
/*
* for k=1:nl
*/
{
int v_ = mclForIntStart(1);
int e_ = mclForIntEnd(mclVv(nl, "nl"));
if (v_ > e_) {
mlfAssign(&k, _mxarray0_);
} else {
/*
* for m=1:n
* noise=normrnd(0,sgma)+normrnd(0,sgma)*sqrt(-1); %噪声方差为sgma平方输入
* output(m,k)=input(m,k)+noise;
* end
* end
*/
for (; ; ) {
int v_0 = mclForIntStart(1);
int e_0 = mclForIntEnd(mclVv(n, "n"));
if (v_0 > e_0) {
mlfAssign(&m, _mxarray0_);
} else {
for (; ; ) {
mlfAssign(
&noise,
mclPlus(
mlfNormrnd(
_mxarray1_, mclVa(sgma, "sgma"), NULL, NULL),
mclMtimes(
mlfNormrnd(
_mxarray1_, mclVa(sgma, "sgma"), NULL, NULL),
mlfSqrt(_mxarray2_))));
mclIntArrayAssign2(
&output,
mclPlus(
mclIntArrayRef2(mclVa(input, "input"), v_0, v_),
mclVv(noise, "noise")),
v_0,
v_);
if (v_0 == e_0) {
break;
}
++v_0;
}
mlfAssign(&m, mlfScalar(v_0));
}
if (v_ == e_) {
break;
}
++v_;
}
mlfAssign(&k, mlfScalar(v_));
}
}
mclValidateOutput(output, 1, nargout_, "output", "add_noise");
mxDestroyArray(n);
mxDestroyArray(nl);
mxDestroyArray(k);
mxDestroyArray(m);
mxDestroyArray(noise);
mxDestroyArray(input);
mxDestroyArray(sgma);
mclSetCurrentLocalFunctionTable(save_local_function_table_);
return output;
/*
*
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -