/* Copyright 2002 The MathWorks, Inc. */ /* $Revision: 1.1.4.2 $ */ /* * * --- THIS FILE GENERATED BY S-FUNCTION BUILDER: 2.0 --- * * This file is a wrapper 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_wrapper_XXXXX_Changes_BEGIN * Your Changes go here * %%%-SFUNWIZ_wrapper_XXXXXX_Changes_END * * 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". * * Created: Thu May 16 11:47:49 2002 */ /* * Include Files * */ #include "tmwtypes.h" /* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */ #include /* %%%-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 sfbuilder_meanstd_Outputs_wrapper(const real_T *sig, real_T *Mean, real_T *stDeviation, const real_T *xD) { /* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */ /* This example calculates the mean and standard deviation over time */ /* Mean is equal to the second Discrete State: xD[1] */ *Mean = xD[1]; /* Standard Deviation is equal to the third Discrete State: xD[2] */ *stDeviation = xD[2]; /* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */ } /* * Updates function * */ void sfbuilder_meanstd_Update_wrapper(const real_T *sig, const real_T *Mean, const real_T *stDeviation, real_T *xD) { /* %%%-SFUNWIZ_wrapper_Update_Changes_BEGIN --- EDIT HERE TO _END */ real_T NminusOne, AminusOne, deltaN; real_T temp1, temp2; NminusOne = xD[0]; AminusOne = xD[1]; /* N = 1 + NminusOne */ xD[0] = xD[0] + 1; /*An = 1/N *(An_1 * N-1 + xn) */ xD[1] = (1/xD[0]) * (xD[1] * NminusOne + sig[0]); /* temp1 = (x - A(n-1)) ^ 2 */ temp1 = (sig[0] - AminusOne) * (sig[0] - AminusOne); /* temp2 = (A(n-1) -A(n)) ^ 2 */ temp2 = (AminusOne - xD[1]) *(AminusOne - xD[1]); /* stDeviation(n) = sqrt( (1/N) ( N-1 * Delta^2 - N *(A(n-1) -A(n)) ^ 2 * * (x - A(n-1)) ^ 2)); */ deltaN = xD[2]; deltaN = (1 / xD[0]) * ( NminusOne * deltaN*deltaN - xD[0]*temp2 + temp1 ) ; if(deltaN) { deltaN = fabs(deltaN); } xD[2] = sqrt(deltaN); /* %%%-SFUNWIZ_wrapper_Update_Changes_END --- EDIT HERE TO _BEGIN */ } /* * Derivatives function * */ void sfbuilder_meanstd_Derivatives_wrapper(const real_T *sig, const real_T *Mean, const real_T *stDeviation, real_T *dx ) { /* %%%-SFUNWIZ_wrapper_Derivatives_Changes_BEGIN --- EDIT HERE TO _END */ /* %%%-SFUNWIZ_wrapper_Derivatives_Changes_END --- EDIT HERE TO _BEGIN */ }