本帖最后由 韩风 于 2016-12-9 18:04 编辑
用matlab建立如下模型:
QQ截图20161209171040.png (41.83 KB, 下载次数: 27)
2016-12-9 17:49 上传
然后生成如下C++代码
QQ截图20161209174645.png (105.6 KB, 下载次数: 14)
2016-12-9 17:49 上传
有两个重要文件 Filter.h和Filter.cpp;
代码如下
/*
* Filter.h
*
* Code generation for model "Filter".
*
* Model version : 1.3
* Simulink Coder version : 8.11 (R2016b) 25-Aug-2016
* C++ source code generated on : Fri Dec 09 15:53:37 2016
*
* Target selection: grt.tlc
* Note: GRT includes extra infrastructure and instrumentation for prototyping
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#ifndef RTW_HEADER_Filter_h_
#define RTW_HEADER_Filter_h_
#include
#include
#include
#include
#ifndef Filter_COMMON_INCLUDES_
# define Filter_COMMON_INCLUDES_
#include "rtwtypes.h"
#include "rtw_continuous.h"
#include "rtw_solver.h"
#include "rt_logging.h"
#endif /* Filter_COMMON_INCLUDES_ */
#include "Filter_types.h"
/* Shared type includes */
#include "multiword_types.h"
#include "rt_nonfinite.h"
#include "rtGetInf.h"
/* Macros for accessing real-time model data structure */
#ifndef rtmGetFinalTime
# define rtmGetFinalTime(rtm) ((rtm)->Timing.tFinal)
#endif
#ifndef rtmGetRTWLogInfo
# define rtmGetRTWLogInfo(rtm) ((rtm)->rtwLogInfo)
#endif
#ifndef rtmGetErrorStatus
# define rtmGetErrorStatus(rtm) ((rtm)->errorStatus)
#endif
#ifndef rtmSetErrorStatus
# define rtmSetErrorStatus(rtm, val) ((rtm)->errorStatus = (val))
#endif
#ifndef rtmGetStopRequested
# define rtmGetStopRequested(rtm) ((rtm)->Timing.stopRequestedFlag)
#endif
#ifndef rtmSetStopRequested
# define rtmSetStopRequested(rtm, val) ((rtm)->Timing.stopRequestedFlag = (val))
#endif
#ifndef rtmGetStopRequestedPtr
# define rtmGetStopRequestedPtr(rtm) (&((rtm)->Timing.stopRequestedFlag))
#endif
#ifndef rtmGetT
# define rtmGetT(rtm) ((rtm)->Timing.taskTime0)
#endif
#ifndef rtmGetTFinal
# define rtmGetTFinal(rtm) ((rtm)->Timing.tFinal)
#endif
/* Block states (auto storage) for system '' */
typedef struct {
dsp_VariableBandwidthIIRFilte_T obj; /* '/Variable Bandwidth IIR Filter' */
real_T NextOutput; /* '/Random Number' */
void *VariableBandwidthIIRFilter_PWOR;/* '/Variable Bandwidth IIR Filter' */
uint32_T RandSeed; /* '/Random Number' */
boolean_T objisempty; /* '/Variable Bandwidth IIR Filter' */
boolean_T isInitialized; /* '/Variable Bandwidth IIR Filter' */
} DW_Filter_T;
/* External outputs (root outports fed by signals with auto storage) */
typedef struct {
real_T y; /* '/y' */
} ExtY_Filter_T;
/* Parameters (auto storage) */
struct P_Filter_T_ {
real_T VariableBandwidthIIRFilter_Pass;/* Expression: 1e3
* Referenced by: '/Variable Bandwidth IIR Filter'
*/
real_T RandomNumber_Mean; /* Expression: 0
* Referenced by: '/Random Number'
*/
real_T RandomNumber_StdDev; /* Computed Parameter: RandomNumber_StdDev
* Referenced by: '/Random Number'
*/
real_T RandomNumber_Seed; /* Expression: 0
* Referenced by: '/Random Number'
*/
};
/* Real-time Model Data Structure */
struct tag_RTM_Filter_T {
const char_T *errorStatus;
RTWLogInfo *rtwLogInfo;
/*
* Timing:
* The following substructure contains information regarding
* the timing information for the model.
*/
struct {
time_T taskTime0;
uint32_T clockTick0;
uint32_T clockTickH0;
time_T stepSize0;
time_T tFinal;
boolean_T stopRequestedFlag;
} Timing;
};
/* Block parameters (auto storage) */
#ifdef __cplusplus
extern "C" {
#endif
extern P_Filter_T Filter_P;
#ifdef __cplusplus
}
#endif
/* Block states (auto storage) */
extern DW_Filter_T Filter_DW;
#ifdef __cplusplus
extern "C" {
#endif
/* External outputs (root outports fed by signals with auto storage) */
extern ExtY_Filter_T Filter_Y;
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Model entry point functions */
extern void Filter_initialize(void);
extern void Filter_step(void);
extern void Filter_terminate(void);
#ifdef __cplusplus
}
#endif
/* Real-time Model object */
#ifdef __cplusplus
extern "C" {
#endif
extern RT_MODEL_Filter_T *const Filter_M;
#ifdef __cplusplus
}
#endif
/*-
* The generated code includes comments that allow you to trace directly
* back to the appropriate location in the model. The basic format
* is /block_name, where system is the system number (uniquely
* assigned by Simulink) and block_name is the name of the block.
*
* Use the MATLAB hilite_system command to trace the generated code back
* to the model. For example,
*
* hilite_system('') - opens system 3
* hilite_system('/Kp') - opens and selects block Kp which resides in S3
*
* Here is the system hierarchy for this model
*
* '' : 'Filter'
*/
#endif /* RTW_HEADER_Filter_h_ */
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
/*
* Filter.cpp
*
* Code generation for model "Filter".
*
* Model version : 1.3
* Simulink Coder version : 8.11 (R2016b) 25-Aug-2016
* C++ source code generated on : Fri Dec 09 15:53:37 2016
*
* Target selection: grt.tlc
* Note: GRT includes extra infrastructure and instrumentation for prototyping
* Embedded hardware selection: Intel->x86-64 (Windows64)
* Code generation objectives: Unspecified
* Validation result: Not run
*/
#include "stdafx.h"
#include "Filter.h"
#include "Filter_private.h"
/* Block states (auto storage) */
DW_Filter_T Filter_DW;
/* External outputs (root outports fed by signals with auto storage) */
ExtY_Filter_T Filter_Y;
/* Real-time model */
RT_MODEL_Filter_T Filter_M_;
RT_MODEL_Filter_T *const Filter_M = &Filter_M_;
/* Forward declaration for local functions */
static void VariableBandwidthIIRFilter_poly(const real_T q[2], int8_T N, real_T
p_data[], int32_T p_sizes[2]);
static void Filter_conv(const real_T A_data[], const int32_T A_sizes[2], const
real_T B_data[], const int32_T B_sizes[2], real_T C_data[], int32_T C_sizes[2]);
static void VariableBandwidthIIRFilter_newp(const real_T b_data[], const real_T
allpassnum[2], const real_T allpassden[2], int8_T M, real_T temppoly_data[],
int32_T temppoly_sizes[2]);
static void VariableBandwidthIIRFilter_tune(dsp_VariableBandwidthIIRFilte_T *obj);
static real_T VariableBandwidthIIRFilter_step(dsp_VariableBandwidthII