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

📄 switchinput.c

📁 ofdm算法的c语言实现。码率已降至2.4k以下。
💻 C
字号:
/*
 * File: switchinput.c
 *
 *
  *
  *   --- THIS FILE GENERATED BY S-FUNCTION BUILDER: 2.0 ---
  *
  *   This file is an S-function produced by the S-Function
  *   Builder which only recognizes certain fields.  Changes made
  *   outside these fields will be lost the next time the block is
  *   used to load, edit, and resave this file. This file will be overwritten
  *   by the S-function Builder block. If you want to edit this file by hand, 
  *   you must change it only in the area defined as:  
  *
  *        %%%-SFUNWIZ_defines_Changes_BEGIN
  *        #define NAME 'replacement text' 
  *        %%% SFUNWIZ_defines_Changes_END
  *
  *   DO NOT change NAME--Change the 'replacement text' only.
  *
  *   For better compatibility with the Real-Time Workshop, the
  *   "wrapper" S-function technique is used.  This is discussed
  *   in the Real-Time Workshop User's Manual in the Chapter titled,
  *   "Wrapper S-functions".
  *
  *  -------------------------------------------------------------------------
  * | See matlabroot/simulink/src/sfuntmpl_doc.c for a more detailed template |
  *  ------------------------------------------------------------------------- 
 * Created: Sat Apr 30 13:42:44 2005
 * 
 *
 */


#define S_FUNCTION_NAME switchinput
#define S_FUNCTION_LEVEL 2
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
/* %%%-SFUNWIZ_defines_Changes_BEGIN --- EDIT HERE TO _END */
#define NUM_INPUTS          2
/* Input Port  0 */
#define IN_PORT_0_NAME      index
#define INPUT_0_WIDTH       1
#define INPUT_DIMS_0_COL    1
#define INPUT_0_DTYPE       real_T
#define INPUT_0_COMPLEX     COMPLEX_NO
#define IN_0_FRAME_BASED    FRAME_NO
#define IN_0_DIMS           1-D
#define INPUT_0_FEEDTHROUGH 1
#define IN_0_ISSIGNED        0
#define IN_0_WORDLENGTH      8
#define IN_0_FIXPOINTSCALING 1
#define IN_0_FRACTIONLENGTH  9
#define IN_0_BIAS            0
#define IN_0_SLOPE           0.125
/* Input Port  1 */
#define IN_PORT_1_NAME      signal
#define INPUT_1_WIDTH       -1
#define INPUT_DIMS_1_COL    1
#define INPUT_1_DTYPE       creal_T
#define INPUT_1_COMPLEX     COMPLEX_YES
#define IN_1_FRAME_BASED    FRAME_YES
#define IN_1_DIMS           1-D
#define INPUT_1_FEEDTHROUGH 1
#define IN_1_ISSIGNED        0
#define IN_1_WORDLENGTH      8
#define IN_1_FIXPOINTSCALING 1
#define IN_1_FRACTIONLENGTH  9
#define IN_1_BIAS            0
#define IN_1_SLOPE           0.125

#define NUM_OUTPUTS          4
/* Output Port  0 */
#define OUT_PORT_0_NAME      y0
#define OUTPUT_0_WIDTH       -1
#define OUTPUT_DIMS_0_COL    1
#define OUTPUT_0_DTYPE       creal_T
#define OUTPUT_0_COMPLEX     COMPLEX_YES
#define OUT_0_FRAME_BASED    FRAME_YES
#define OUT_0_DIMS           1-D
/* Output Port  1 */
#define OUT_PORT_1_NAME      y1
#define OUTPUT_1_WIDTH       -1
#define OUTPUT_DIMS_1_COL    1
#define OUTPUT_1_DTYPE       creal_T
#define OUTPUT_1_COMPLEX     COMPLEX_YES
#define OUT_1_FRAME_BASED    FRAME_YES
#define OUT_1_DIMS           1-D
/* Output Port  2 */
#define OUT_PORT_2_NAME      y2
#define OUTPUT_2_WIDTH       -1
#define OUTPUT_DIMS_2_COL    1
#define OUTPUT_2_DTYPE       creal_T
#define OUTPUT_2_COMPLEX     COMPLEX_YES
#define OUT_2_FRAME_BASED    FRAME_YES
#define OUT_2_DIMS           1-D
/* Output Port  3 */
#define OUT_PORT_3_NAME      y3
#define OUTPUT_3_WIDTH       -1
#define OUTPUT_DIMS_3_COL    1
#define OUTPUT_3_DTYPE       creal_T
#define OUTPUT_3_COMPLEX     COMPLEX_YES
#define OUT_3_FRAME_BASED    FRAME_YES
#define OUT_3_DIMS           1-D

#define NPARAMS              0

#define SAMPLE_TIME_0        INHERITED_SAMPLE_TIME
#define NUM_DISC_STATES      0
#define DISC_STATES_IC       [0]
#define NUM_CONT_STATES      0
#define CONT_STATES_IC       [0]

#define SFUNWIZ_GENERATE_TLC 0
#define SOURCEFILES "__SFB__"
#define PANELINDEX           6
#define SFUNWIZ_REVISION     3.0
/* %%%-SFUNWIZ_defines_Changes_END --- EDIT HERE TO _BEGIN */
/*<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
#include "simstruc.h"

#if defined(MATLAB_MEX_FILE)
#include "tmwtypes.h"
#include "simstruc_types.h"
#else
#include "rtwtypes.h"
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#include <math.h>
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define u_width 1
#define y_width 1
/*
 * Create external references here.  
 *
 */
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
/* extern double func(double a); */
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */

/*
 * Output functions
 *
 */
void switchinput_Outputs_wrapper(SimStruct *S, const real_T *index,
                          const creal_T *signal,
                          creal_T *y0,
                          creal_T *y1,
                          creal_T *y2,
                          creal_T *y3)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
/* This sample sets the output equal to the input
          y0[0] = u0[0];
 For complex signals use: y0[0].re = u0[0].re;
                          y0[0].im = u0[0].im;
                          y1[0].re = u1[0].re;
                          y1[0].im = u1[0].im;*/
 
    
     int_T i;
     int_T data_width = ssGetInputPortWidth(S,1) ; 
     int_T selector= *index ; 
     
     switch  ( selector )
     {
         case 1:
             {
                 for ( i = 0; i< data_width ; i ++ )
                 {
                     y0[i] = signal[i] ; 
                     y1[i].re = 0 ; 
                     y1[i].im = 0 ; 
                     y2[i].re = 0 ; 
                     y2[i].im = 0 ; 
                     y3[i].re = 0 ;
                     y3[i].im = 0 ; 
                 }
             }
             break;
         case 2:
             {
                 for ( i = 0 ; i < data_width ; i ++ )
                 {
                     y1[i] = signal[i] ;
                     y0[i].re = 0 ; 
                     y0[i].im = 0 ; 
                     y2[i].re = 0 ; 
                     y2[i].im = 0 ;
                     y3[i].re = 0 ;
                     y3[i].im = 0 ; 
                 }
             }
             break;
         case 3:
             {
                 for ( i = 0 ; i < data_width ; i ++ )
                 {
                     y2[i] = signal[i] ; 
                     y0[i].re = 0 ; 
                     y0[i].im = 0 ; 
                     y1[i].re = 0 ;
                     y1[i].im = 0 ; 
                     y3[i].re = 0 ;
                     y3[i].im = 0 ; 
                 } 
             }
             break;
         case 4:
             {
                 for ( i = 0 ; i < data_width ; i ++ )
                 {
                     y3[i] = signal[i] ; 
                     y0[i].re = 0 ;
                     y0[i].im = 0 ; 
                     y1[i].re = 0 ; 
                     y1[i].im = 0;
                     y2[i].re = 0 ; 
                     y2[i].im = 0 ;
                 }
             }
             break;
         default:
             ssSetErrorStatus(S,"the Input0 value error!");
             break;            
     }
    

/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}

/*====================*
 * S-function methods *
 *====================*/
/* Function: mdlInitializeSizes ===============================================
 * Abstract:
 *   Setup sizes of the various vectors.
 */
static void mdlInitializeSizes(SimStruct *S)
{

    DECL_AND_INIT_DIMSINFO(inputDimsInfo);
    DECL_AND_INIT_DIMSINFO(outputDimsInfo);
    ssSetNumSFcnParams(S, NPARAMS);
     if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
	 return; /* Parameter mismatch will be reported by Simulink */
     }

    ssSetNumContStates(S, NUM_CONT_STATES);
    ssSetNumDiscStates(S, NUM_DISC_STATES);

    if (!ssSetNumInputPorts(S, NUM_INPUTS)) return;
    /*Input Port 0 */
    ssSetInputPortWidth(S,  0, INPUT_0_WIDTH); /* */
    ssSetInputPortDataType(S, 0, SS_DOUBLE);
    ssSetInputPortComplexSignal(S,  0, INPUT_0_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 0, INPUT_0_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 0, 1); /*direct input signal access*/

    /*Input Port 1 */
    inputDimsInfo.width = INPUT_1_WIDTH;
    ssSetInputPortDimensionInfo(S,  1, &inputDimsInfo);
    ssSetInputPortMatrixDimensions(  S , 1, INPUT_1_WIDTH, INPUT_DIMS_1_COL);
    ssSetInputPortFrameData(S,  1, IN_1_FRAME_BASED);

    ssSetInputPortDataType(S, 1, SS_DOUBLE);
    ssSetInputPortComplexSignal(S,  1, INPUT_1_COMPLEX);
    ssSetInputPortDirectFeedThrough(S, 1, INPUT_1_FEEDTHROUGH);
    ssSetInputPortRequiredContiguous(S, 1, 1); /*direct input signal access*/


    if (!ssSetNumOutputPorts(S, NUM_OUTPUTS)) return;
    /* Output Port 0 */
    outputDimsInfo.width = OUTPUT_0_WIDTH;
    ssSetOutputPortDimensionInfo(S, 0, &outputDimsInfo);
    ssSetOutputPortMatrixDimensions( S ,0, OUTPUT_0_WIDTH, OUTPUT_DIMS_0_COL);
    ssSetOutputPortFrameData(S, 0, OUT_0_FRAME_BASED);
    ssSetOutputPortDataType(S, 0, SS_DOUBLE);
    ssSetOutputPortComplexSignal(S, 0, OUTPUT_0_COMPLEX);
    /* Output Port 1 */
    outputDimsInfo.width = OUTPUT_1_WIDTH;
    ssSetOutputPortDimensionInfo(S, 1, &outputDimsInfo);
    ssSetOutputPortMatrixDimensions( S ,1, OUTPUT_1_WIDTH, OUTPUT_DIMS_1_COL);
    ssSetOutputPortFrameData(S, 1, OUT_1_FRAME_BASED);
    ssSetOutputPortDataType(S, 1, SS_DOUBLE);
    ssSetOutputPortComplexSignal(S, 1, OUTPUT_1_COMPLEX);
    /* Output Port 2 */
    outputDimsInfo.width = OUTPUT_2_WIDTH;
    ssSetOutputPortDimensionInfo(S, 2, &outputDimsInfo);
    ssSetOutputPortMatrixDimensions( S ,2, OUTPUT_2_WIDTH, OUTPUT_DIMS_2_COL);
    ssSetOutputPortFrameData(S, 2, OUT_2_FRAME_BASED);
    ssSetOutputPortDataType(S, 2, SS_DOUBLE);
    ssSetOutputPortComplexSignal(S, 2, OUTPUT_2_COMPLEX);
    /* Output Port 3 */
    outputDimsInfo.width = OUTPUT_3_WIDTH;
    ssSetOutputPortDimensionInfo(S, 3, &outputDimsInfo);
    ssSetOutputPortMatrixDimensions( S ,3, OUTPUT_3_WIDTH, OUTPUT_DIMS_3_COL);
    ssSetOutputPortFrameData(S, 3, OUT_3_FRAME_BASED);
    ssSetOutputPortDataType(S, 3, SS_DOUBLE);
    ssSetOutputPortComplexSignal(S, 3, OUTPUT_3_COMPLEX);

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

    /* Take care when specifying exception free code - see sfuntmpl_doc.c */
    ssSetOptions(S, (SS_OPTION_EXCEPTION_FREE_CODE |
                     SS_OPTION_USE_TLC_WITH_ACCELERATOR |
		     SS_OPTION_WORKS_WITH_CODE_REUSE));
}

# define MDL_SET_INPUT_PORT_FRAME_DATA
static void mdlSetInputPortFrameData(SimStruct  *S, 
                                     int_T      port,
                                     Frame_T    frameData)
{
    ssSetInputPortFrameData(S, port, frameData);
}
/* Function: mdlInitializeSampleTimes =========================================
 * Abstract:
 *    Specifiy  the sample time.
 */
static void mdlInitializeSampleTimes(SimStruct *S)
{
    ssSetSampleTime(S, 0, SAMPLE_TIME_0);
    ssSetOffsetTime(S, 0, 0.0);
}

#define MDL_SET_INPUT_PORT_DATA_TYPE
static void mdlSetInputPortDataType(SimStruct *S, int port, DTypeId dType)
{
    ssSetInputPortDataType( S, 0, dType);
}
#define MDL_SET_OUTPUT_PORT_DATA_TYPE
static void mdlSetOutputPortDataType(SimStruct *S, int port, DTypeId dType)
{
    ssSetOutputPortDataType(S, 0, dType);
}

#define MDL_SET_DEFAULT_PORT_DATA_TYPES
static void mdlSetDefaultPortDataTypes(SimStruct *S)
{
  ssSetInputPortDataType( S, 0, SS_DOUBLE);
 ssSetOutputPortDataType(S, 0, SS_DOUBLE);
}
/* Function: mdlOutputs =======================================================
 *
*/
static void mdlOutputs(SimStruct *S, int_T tid)
{
    const real_T   *index  = (const real_T*) ssGetInputPortSignal(S,0);
    const creal_T   *signal  = (const creal_T*) ssGetInputPortSignal(S,1);
    creal_T        *y0  = (creal_T *)ssGetOutputPortRealSignal(S,0);
    creal_T        *y1  = (creal_T *)ssGetOutputPortRealSignal(S,1);
    creal_T        *y2  = (creal_T *)ssGetOutputPortRealSignal(S,2);
    creal_T        *y3  = (creal_T *)ssGetOutputPortRealSignal(S,3);

    switchinput_Outputs_wrapper(S,index, signal, y0, y1, y2, y3);
}



/* Function: mdlTerminate =====================================================
 * Abstract:
 *    In this function, you should perform any actions that are necessary
 *    at the termination of a simulation.  For example, if memory was
 *    allocated in mdlStart, this is the place to free it.
 */
static void mdlTerminate(SimStruct *S)
{
}

#ifdef  MATLAB_MEX_FILE    /* Is this file being compiled as a MEX-file? */
#include "simulink.c"      /* MEX-file interface mechanism */
#else
#include "cg_sfun.h"       /* Code generation registration function */
#endif


⌨️ 快捷键说明

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