📄 cfunc.mod
字号:
/* $Id: cfunc.mod,v 1.4 2005/08/23 18:29:53 pnenzi Exp $ *//*.......1.........2.........3.........4.........5.........6.........7.........8================================================================================FILE s_xfer/cfunc.modCopyright 1991Georgia Tech Research Corporation, Atlanta, Ga. 30332All Rights ReservedPROJECT A-8503-405 AUTHORS 17 Mar 1991 Jeffrey P. MurrayMODIFICATIONS 18 Apr 1991 Harry Li 27 Sept 1991 Jeffrey P. Murray SUMMARY This file contains the functional description of the s-domain transfer function (s_xfer) code model.INTERFACES FILE ROUTINE CALLED CMmacros.h cm_message_send(); CM.c void *cm_analog_alloc() void *cm_analog_get_ptr() int cm_analog_integrate()REFERENCED FILES Inputs from and outputs to ARGS structure. NON-STANDARD FEATURES NONE===============================================================================*//*=== INCLUDE FILES ====================*/#include <math.h> /*=== CONSTANTS ========================*//*=== MACROS ===========================*/ /*=== LOCAL VARIABLES & TYPEDEFS =======*/ /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/ /*=============================================================================FUNCTION cm_complex_divAUTHORS 27 Sept 1991 Jeffrey P. MurrayMODIFICATIONS NONESUMMARY Performs a complex division.INTERFACES FILE ROUTINE CALLED N/A N/ARETURNED VALUE A Mif_Complex_t value representing the result of the complex division. GLOBAL VARIABLES NONENON-STANDARD FEATURES NONE==============================================================================*/#include <stdlib.h>/*=== Static CM_COMPLEX_DIV ROUTINE ===*//**** Cm_complex_div Function - FAKE ***********//* *//* Function will not be used in finished *//* system...provides a stub for performing *//* a simple complex division. *//* 12/3/90 JPM *//* *//***********************************************/static Mif_Complex_t cm_complex_div(Mif_Complex_t x, Mif_Complex_t y) {double mag_x, phase_x, mag_y, phase_y;Mif_Complex_t out; mag_x = sqrt( (x.real * x.real) + (x.imag * x.imag) );phase_x = atan2(x.imag, x.real);mag_y = sqrt( (y.real * y.real) + (y.imag * y.imag) );phase_y = atan2(y.imag, y.real); mag_x = mag_x/mag_y;phase_x = phase_x - phase_y;out.real = mag_x * cos(phase_x);out.imag = mag_x * sin(phase_x);return out;} /*==============================================================================FUNCTION cm_s_xfer()AUTHORS 17 Mar 1991 Jeffrey P. MurrayMODIFICATIONS 18 Apr 1991 Harry Li 27 Sept 1991 Jeffrey P. MurraySUMMARY This function implements the s_xfer code model.INTERFACES FILE ROUTINE CALLED CMmacros.h cm_message_send(); CM.c void *cm_analog_alloc() void *cm_analog_get_ptr() int cm_analog_integrate()RETURNED VALUE Returns inputs and outputs via ARGS structure.GLOBAL VARIABLES NONENON-STANDARD FEATURES NONE==============================================================================*//*=== CM_S_XFER ROUTINE ===*//***************************************** S-Domain Transfer Function - ** Code Body ** ** Last Modified - 9/27/91 JPM *****************************************/void cm_s_xfer(ARGS) /* structure holding parms, inputs, outputs, etc. */{ double *out; /* pointer to the output */ double *in; /* pointer to the input */ double in_offset; /* input offset */ double *gain; /* pointer to the gain */ double **den_coefficient; /* dynamic array that holds the denominator coefficients */ double **old_den_coefficient;/* dynamic array that holds the old denonminator coefficients */ double **num_coefficient; /* dynamic array that holds the numerator coefficients */ double **old_num_coefficient;/* dynamic array that holds the old numerator coefficients */ double factor; /* gain factor in case the highest denominator coefficient is not 1 */ double **integrator; /* outputs of the integrators */ double **old_integrator; /* previous integrator outputs */ double null; /* dummy pointer for use with the integrate function */ double pout_pin; /* partial out wrt in */ /*double total_gain;*/ /* not used, currently-used with ITP stuff */ double temp; /* temporary variable used with the correct type of AC value */ double frac; /* holds fractional part of a divide */ double divide_integer; /* integer part of a modf used in AC */ double denormalized_freq; /* denormalization constant...the nominal corner or center frequencies specified by the model coefficients will be denormalized by this amount. Thus, if coefficients were obtained which specified a 1 rad/sec cornere frequency, specifying a value of 1000.0 for denormalized_freq will cause the model to shift the corner freq. to 2.0 * pi * 1000.0 */ double *old_gain; /* pointer to the gain if the highest order denominator coefficient is not factored out */ Mif_Complex_t ac_gain, acc_num, acc_den; int i; /* generic loop counter index */ int den_size; /* size of the denominator coefficient array */ int num_size; /* size of the numerator coefficient array */ char *num_size_error="\n***ERROR***\nS_XFER: Numerator coefficient array size greater than\ndenominator coefficiant array size.\n"; /** Retrieve frequently used parameters (used by all analyses)... **/ in_offset = PARAM(in_offset); num_size = PARAM_SIZE(num_coeff); den_size = PARAM_SIZE(den_coeff); if ( PARAM_NULL(denormalized_freq) ) { denormalized_freq = 1.0; } else { denormalized_freq = PARAM(denormalized_freq); } if ( num_size > den_size ) { cm_message_send(num_size_error); return; } /** Test for INIT; if so, allocate storage, otherwise, retrieve previous **/ /** timepoint input values as necessary in subsequent analysis sections... **/ if (INIT==1) { /* First pass...allocate storage for previous values... */ /* Allocate rotational storage for integrator outputs, in & out *//***** The following two lines may be unnecessary in the final version *****//* We have to allocate memory and use cm_analog_alloc, because the ITP variables are not functional */ integrator = (double **) calloc(den_size,sizeof(double *)); old_integrator = (double **) calloc(den_size,sizeof(double *)); for (i=0; i<den_size; i++) { integrator[i] = cm_analog_alloc(i,sizeof(double)); old_integrator[i] = cm_analog_get_ptr(i,0); } /* Allocate storage for coefficient values */ den_coefficient = (double **) calloc(den_size,sizeof(double *)); old_den_coefficient = (double **) calloc(den_size,sizeof(double *)); num_coefficient = (double **) calloc(num_size,sizeof(double *)); old_num_coefficient = (double **) calloc(num_size,sizeof(double *)); for(i=den_size;i<(2*den_size);i++){ old_den_coefficient[i-den_size] = den_coefficient[i-den_size] = cm_analog_alloc(i,sizeof(double)); } for(i=2*den_size;i<(2*den_size + num_size);i++){ old_num_coefficient[i-2*den_size] = num_coefficient[i-2*den_size] = cm_analog_alloc(i,sizeof(double)); } out = cm_analog_alloc(2*den_size+num_size,sizeof(double)); in = cm_analog_alloc(2*den_size+num_size+1,sizeof(double)); /* ITP_VAR_SIZE(den) = den_size; */ gain = cm_analog_alloc(2*den_size+num_size+2,sizeof(double));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -