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

📄 dqpskmodulation.c

📁 DQPSK调制的程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 * Writed by zhang jian
 * 2005/08/01
 *  
 *  
 * 
 *
 * Copyright 1990-2002 The MathWorks, Inc.
 * $Revision: 1.27 $
 */


/*
 * 这个函数主要是完成DQPSK modulation

#define S_FUNCTION_NAME  DQPSKmodulation
#define S_FUNCTION_LEVEL 2
#define NumberCIF 221184                                //4  CIF
#define NumberFIBModeABD 9216                           //12 FIB
#define NumberFIBModeC 12288                            //16 FIB
#define NumberModulation 196608                         //the size of modulation
#define NumberNullModeA 2656                            //null symbol sizeof mode a
#define NumberNullModeB 664                             //null symbol sizeof mode b
#define NumberNullModeC 345                             //null symbol sizeof mode c
#define NumberNullModeD 1328                            //null symbol sizeof mode d
#define NumberTuModeC   256                             //the point number of useful part
#define NumberTgModeC   63                              //the point number of cyclic part
#define NumberSymbolModeABD    76                       //the number of OFDM symbol mode a
#define NumberSymbolModeC    153                        //the number of OFDM symbol mode c
#define NumberCarrierModeC   192                        //the number of carrier mode c
#define NF 0.707106781                                  // The normalization factor, 1/sqrt(2)
#define PIhalf 1.570796325                              //the value of pi/2;

/*
 * Need to include simstruc.h for the definition of the SimStruct and
 * its associated macro definitions.
 */
#include "simstruc.h"
#include <math.h>
 
int_T mode;
int_T h_value[4][32] = {{0,2,0,0,0,0,1,1,2,0,0,0,2,2,1,1,0,2,0,0,0,0,1,1,2,0,0,0,2,2,1,1},
                              {0,3,2,3,0,1,3,0,2,1,2,3,2,3,3,0,0,3,2,3,0,1,3,0,2,1,2,3,2,3,3,0},
                              {0,0,0,2,0,2,1,3,2,2,0,2,2,0,1,3,0,0,0,2,0,2,1,3,2,2,0,2,2,0,1,3},
                              {0,1,2,1,0,3,3,2,2,3,2,1,2,1,3,2,0,1,2,1,0,3,3,2,2,3,2,1,2,1,3,2}};
      //the value of h table;
      int_T indextablemodea[2][48] = {{0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,3,2,1,0,3,2,1,0,3,2,1,0,3,2,1,0,3,2,1,0,3,2,1},
                                      {1,2,0,1,3,2,2,3,2,1,2,3,1,2,3,3,2,2,2,1,1,3,1,2,3,1,1,1,2,2,1,0,2,2,3,3,0,2,1,3,3,3,3,0,3,0,1,1}};
      int_T indextablemodeb[2][12] = {{0,1,2,3,0,1,2,1,0,3,2,1},{2,3,2,2,1,2,0,2,2,1,0,3}};
      int_T indextablemodec[2][6] = {{0,1,2,3,2,1},{2,3,0,2,2,2}};
      int_T indextablemoded[2][24] = {{0,1,2,3,0,1,2,3,0,1,2,3,0,3,2,1,0,3,2,1,0,3,2,1},{0,1,1,2,2,2,0,3,3,1,3,2,0,1,0,2,0,1,2,2,2,1,3,0}};

/* Error handling
 * --------------
 *
 * You should use the following technique to report errors encountered within
 * an S-function:
 *
 *       ssSetErrorStatus(S,"Error encountered due to ...");
 *       return;
 *
 * Note that the 2nd argument to ssSetErrorStatus must be persistent memory.
 * It cannot be a local variable. For example the following will cause
 * unpredictable errors:
 *
 *      mdlOutputs()
 *      {
 *         char msg[256];         {ILLEGAL: to fix use "static char msg[256];"}
 *         sprintf(msg,"Error due to %s", string);
 *         ssSetErrorStatus(S,msg);
 *         return;
 *      }
 *
 * See matlabroot/simulink/src/sfuntmpl_doc.c for more details.
 */
/*====================*
 * S-function methods *
 *====================*/

/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *    The sizes information is used by Simulink to determine the S-function
 *    block's characteristics (number of inputs, outputs, states, etc.).
 */
static void mdlInitializeSizes(SimStruct *S)
{
    /* See sfuntmpl_doc.c for more details on the macros below */
    /*ssSetNumSFcnParams(S, 0);   Number of expected parameters */
	ssSetNumSFcnParams(S, 1);
    if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) 
    {
        /* Return if number of expected != number of actual parameters */
        ssSetErrorStatus(S,"Error encountered due to setting the number of the function parameter!");
        return;
    }

/*  ssSetNumContStates(S, 0);
    ssSetNumDiscStates(S, 0);*/

    if (!ssSetNumInputPorts(S, 1)) 
    {
        ssSetErrorStatus(S,"Error encountered due to the wrong number of the inputport!");
        return;
    }
 //   ssSetInputPortWidth(S, 0, 1);
 //64 ports in CIF
	ssSetInputPortFrameData(S,0,-1);
    //ssSetInputPortComplexSignal(S, 0, COMPLEX_YES);
    mode = *mxGetPr(ssGetSFcnParam(S,0));
    if(mode==3)
    {
	 if(!ssSetInputPortMatrixDimensions(S,0,(NumberCIF+NumberFIBModeC),1)) 
         //the sizeof input port=233472
     {
        ssSetErrorStatus(S,"Error encountered due to the wrong inputport matrix dimension");
        return;
     }
    }
    else
    {
      if(!ssSetInputPortMatrixDimensions(S,0,(NumberCIF+NumberFIBModeABD),1)) 
          //the size of input port=230400;
     {
        ssSetErrorStatus(S,"Error encountered due to the wrong inputport matrix dimension");
        return;
     }  
    }
    //if(!ssSetInputPortWidth(S, portnumber, DYNAMICALLY_SIZED)) return;
    ssSetInputPortDataType(S, 0, DYNAMICALLY_TYPED);
    ssSetInputPortDirectFeedThrough(S, 0, 1);
 //   ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/
    /*
     * Set direct feedthrough flag (1=yes, 0=no).
     * A port has direct feedthrough if the input is used in either
     * the mdlOutputs or mdlGetTimeOfNextVarHit functions.
     * See matlabroot/simulink/src/sfuntmpl_directfeed.txt.
     */
    if (!ssSetNumOutputPorts(S, 1)) 
        {
            ssSetErrorStatus(S,"Error encountered due to setting the wrong number of outport");
            return;
        }
 //   ssSetOutputPortWidth(S, 0, 1);
	ssSetOutputPortFrameData(S,0,-1);
        // complex value output; 
   // ssSetOutputPortComplexSignal(S, 0, COMPLEX_YES);
    if(mode==3)
   {
    if(!ssSetOutputPortMatrixDimensions(S,0,(NumberCIF+NumberFIBModeC+8*NumberCarrierModeC),1))
    {
        ssSetErrorStatus(S,"Error encountered due to the wrong outputport matrix dimension");
        return;
    }
    }
    else
    {
        if(!ssSetOutputPortMatrixDimensions(S,0,(NumberCIF+NumberFIBModeABD+16*NumberCarrierModeC),1))
    {
        ssSetErrorStatus(S,"Error encountered due to the wrong outputport matrix dimension");
        return;
    }
    }
   // ssSetOutputPortWidth(S, 0, NumberCIF);
    ssSetOutputPortDataType(S, 0, DYNAMICALLY_TYPED);
 // OFDM symbol

    ssSetNumSampleTimes(S, 1);
    ssSetNumRWork(S, 0);
    ssSetNumIWork(S, 0);
    ssSetNumPWork(S, 0);
    ssSetNumModes(S, 0);
    ssSetNumNonsampledZCs(S, 0);

 //   ssSetOptions(S, 0);
	ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE);
}



/* Function: mdlInitializeSampleTimes =========================================
 * Abstract:
 *    This function is used to specify the sample time(s) for your
 *    S-function. You must register the same number of sample times as
 *    specified in ssSetNumSampleTimes.
 */
static void mdlInitializeSampleTimes(SimStruct *S)
{
    ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
    ssSetOffsetTime(S, 0, 0.0);
}



#undef MDL_INITIALIZE_CONDITIONS   /* Change to #undef to remove function */
#if defined(MDL_INITIALIZE_CONDITIONS)
  /* Function: mdlInitializeConditions ========================================
   * Abstract:
   *    In this function, you should initialize the continuous and discrete
   *    states for your S-function block.  The initial states are placed
   *    in the state vector, ssGetContStates(S) or ssGetRealDiscStates(S).
   *    You can also perform any other initialization activities that your
   *    S-function may require. Note, this routine will be called at the
   *    start of simulation and if it is present in an enabled subsystem
   *    configured to reset states, it will be call when the enabled subsystem
   *    restarts execution to reset the states.
   */
  static void mdlInitializeConditions(SimStruct *S)
  {

⌨️ 快捷键说明

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