⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modulint.c

📁 数字通信第四版原书的例程
💻 C
字号:
/*
 * MODULINT  A modulate integrator.
 *           (see manual under Advanced Topics).
 *
 *           Syntax:  [sys, x0] = moldulint(t,x,u,flag,x0,lowbd,upbd)
 *
 * Wes Wang 5/5/94
 * Copyright (c) 1994-96 The MathWorks, Inc.
 * All Rights Reserved
 * $Revision: 1.1 $  $Date: 1996/04/01 19:03:19 $
 */

#undef MODEL_NAME
#define MODEL_NAME modulint

#define X0  ssGetArg(S, 0)

/*
 * need to include simstruc.h for the definition of the SimStruct and
 * its associated macro definitions.
 */

#include "simstruc.h"

/*
 * mdlInitializeSizes - called to initialize the sizes array stored in
 *                      the SimStruct.  The sizes array defines the
 *                      characteristics (number of inputs, outputs,
 *                      states, etc.) of the S-Function.
 */

static void mdlInitializeSizes (S)
    SimStruct *S;
{
    /*
     * Set-up size information.
     */
    
    ssSetNumContStates(    S, 1);
    ssSetNumDiscStates(    S, 0);
    ssSetNumOutputs(       S, 1);
    ssSetNumInputs(        S, 1);
    ssSetDirectFeedThrough(S, 0);
    ssSetNumSampleTimes(   S, 1);
    ssSetNumRWork(         S, 0);
    ssSetNumIWork(         S, 0);
    ssSetNumInputArgs(     S, 3);
}

/*
 * mdlInitializeSampleTimes - initializes the array of sample times stored in
 *                            the SimStruct associated with this S-Function.
 */

static void mdlInitializeSampleTimes(S)
    SimStruct *S;
{
    ssSetSampleTimeEvent(S, 0, 0.);
    ssSetOffsetTimeEvent(S, 0, 0.);
}

/*
 * mdlInitializeConditions - initializes the states for the S-Function
 */

static void mdlInitializeConditions(x0, S)
    double *x0;
    SimStruct *S;
{
    if ((mxGetM(X0) == 0) || (mxGetN(X0) == 0))
     *x0 = 0.;
    else
       *x0 = mxGetPr(X0)[0];
}

/*
 * mdlOutputs - computes the outputs of the S-Function
 */

static void mdlOutputs(y, x, u, S, tid)
    double *y, *x, *u;
    SimStruct *S;
    int tid;
{
    y[0] = x[0];
}

/*
 * mdlUpdate - computes the discrete states of the S-Function
 */

static void mdlUpdate(x, u, S, tid)
    double *x, *u;
    SimStruct *S;
    int tid;
{
    Matrix *mx_up, *mx_low;
    double bd_up, bd_low, differ;

    mx_up = ssGetArg(S,1);
    mx_low = ssGetArg(S,2);

    if ((mxGetM(mx_up) == 0) || (mxGetN(mx_up) == 0))    
      bd_up = 0;
    else
      bd_up = mxGetPr(ssGetArg(S,2))[0];

    if ((mxGetM(mx_low) == 0) || (mxGetN(mx_low) == 0))    
      bd_low = 0;
    else
      bd_low = mxGetPr(ssGetArg(S,1))[0];

    differ = bd_up - bd_low;

    if (differ > 0.0) {
      while (u[0] < bd_low)
        x[0] = x[0] + differ;
      while (x[0] > bd_up)
        x[0] = x[0] - differ;
    }
}

/*
 * mdlDerivatives - computes the derivatives of the S-Function
 */

static void mdlDerivatives(dx, x, u, S, tid)
    double *dx, *x, *u;
    SimStruct *S;
    int tid;
{
    dx[0] = u[0];
}

/*
 * mdlTerminate - called at termination of model execution.
 */

static void mdlTerminate(S)
    SimStruct *S;
{
}

#ifdef    MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */
#include "simulink.c"      /* MEX glue */
#else
#include "cg_glue.h"       /* Code generation glue */
#endif



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -