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

📄 cfunc.mod

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 MOD
📖 第 1 页 / 共 2 页
字号:
     /*   gain = (double *) calloc(1,sizeof(double));          ITP_VAR(total_gain) = gain;         ITP_VAR_SIZE(total_gain) = 1.0;  */                                    		// Retrieve pointers		for (i=0; i<den_size; i++) {            integrator[i] = cm_analog_get_ptr(i,0);            old_integrator[i] = cm_analog_get_ptr(i,0);        }		out = cm_analog_get_ptr(2*den_size+num_size,0);           in = cm_analog_get_ptr(2*den_size+num_size+1,0);   		for(i=den_size;i<2*den_size;i++){		    den_coefficient[i-den_size] = cm_analog_get_ptr(i,0);			old_den_coefficient[i-den_size] = cm_analog_get_ptr(i,0);		} 		for(i=2*den_size;i<2*den_size+num_size;i++){			num_coefficient[i-2*den_size] = cm_analog_get_ptr(i,0);			old_num_coefficient[i-2*den_size] = cm_analog_get_ptr(i,0);		}         gain = cm_analog_get_ptr(2*den_size+num_size+2,0);      }else { /* Allocation was not necessary...retrieve previous values */            /* Set pointers to storage locations for in, out, and integrators...*/         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_get_ptr(i,0);            old_integrator[i] = cm_analog_get_ptr(i,1);        }        out = cm_analog_get_ptr(2*den_size+num_size,0);           in = cm_analog_get_ptr(2*den_size+num_size+1,0);                   /* Set den_coefficient & gain pointers to ITP values */        /* for denominator coefficients & gain...      */        old_den_coefficient = (double **) calloc(den_size,sizeof(double));          den_coefficient = (double **) calloc(den_size,sizeof(double));  		for(i=den_size;i<2*den_size;i++){            old_den_coefficient[i-den_size] = cm_analog_get_ptr(i,1);		    den_coefficient[i-den_size] = cm_analog_get_ptr(i,0);            *(den_coefficient[i-den_size]) = *(old_den_coefficient[i-den_size]);		}         num_coefficient = (double **) calloc(num_size,sizeof(double));  		old_num_coefficient = (double **) calloc(num_size,sizeof(double));  		for(i=2*den_size;i<2*den_size+num_size;i++){		    old_num_coefficient[i-2*den_size] = cm_analog_get_ptr(i,1);			num_coefficient[i-2*den_size] = cm_analog_get_ptr(i,0);			*(num_coefficient[i-2*den_size]) = *(old_num_coefficient[i-2*den_size]);		}         /* gain has to be stored each time since it could possibly change		   if the highest order denominator coefficient isn't zero.  This		   is a hack until the ITP variables work */        old_gain = cm_analog_get_ptr(2*den_size+num_size+2,1);          gain = cm_analog_get_ptr(2*den_size+num_size+2,0);  		*gain = *old_gain;        /* gain = ITP_VAR(total_gain); */        }    /** Test for TIME=0.0; if so, initialize...       **/    if (TIME == 0.0) {  /* First pass...set initial conditions... */                /* Initialize integrators to int_ic condition values... */        for (i=0; i<den_size-1; i++) {   /* Note...do NOT set the highest   */                                         /* order value...this represents   */                                         /* the "calculated" input to the   */                                         /* actual highest integrator...it  */                                         /* is NOT a true state variable.   */            if ( PARAM_NULL(int_ic) ) {                // *(integrator[i]) = *(old_integrator[i]) = PARAM(int_ic[0]);				*(integrator[i]) = *(old_integrator[i]) = 0;            }                                                            else {                *(integrator[i]) = *(old_integrator[i]) =                                    PARAM(int_ic[den_size - 2 - i]);            }        }        /*** Read in coefficients and denormalize, if required ***/        for (i=0; i<num_size; i++) {            *(num_coefficient[i]) = PARAM(num_coeff[num_size - 1 - i]);            if ( denormalized_freq != 1.0 ) {                *(num_coefficient[i]) = *(num_coefficient[i]) /                                         pow(denormalized_freq,(double) i);            }        }        for (i=0; i<den_size; i++) {            *(den_coefficient[i]) = PARAM(den_coeff[den_size - 1 - i]);            if ( denormalized_freq != 1.0 ) {                *(den_coefficient[i]) = *(den_coefficient[i]) /                                         pow(denormalized_freq,(double) i);            }        }        /* Test denominator highest order coefficient...if that value   */        /* is other than 1.0, then divide all denominator coefficients  */        /* and the gain by that value...                                */		// if ( (factor = PARAM(den_coeff[den_size-1])) != 1.0 ) {		if ( (factor = *den_coefficient[den_size-1]) != 1.0 ) {            for (i=0; i<den_size; i++) {                *(den_coefficient[i]) = *(den_coefficient[i]) / factor;            }            *gain = PARAM(gain) / factor;         }        else {    /* No division by coefficient necessary... */                  /* only need to adjust gain value.         */            *gain = PARAM(gain);         }            }                                     /**** DC & Transient Analyses **************************/    if (ANALYSIS != MIF_AC) {             /**** DC Analysis - Not needed JPM 10/29/91 *****************//*        if (ANALYSIS == MIF_DC) {                            ?* Test to see if a term exists for the zero-th order               denom coeff...                   ?* division by zero if output                          ?* num_coefficient[0]/den_coefficient[0],              ?* so output init. conds. instead...                   if ( 0.0 == *(den_coefficient[0])) {                                                                                                            *out = 0.0;                for (i=0; i<num_size; i++) {                    *out = *out + ( *(old_integrator[i]) *                                     *(num_coefficient[i]) );                 }                *out = *gain * *out;                pout_pin = *(old_integrator[1]);            }            ?* Zero-th order den term != 0.0, so output             ?*    num_coeff[0]/den_coeff[0]...                      else {                                                                              *out = *gain * ( INPUT(in) +                                  in_offset) * ( *(num_coefficient[0]) /                                                *(den_coefficient[0]) );                pout_pin = 0.0;            }        }         else {   */        /**** Transient & DC Analyses ****************************/        /*** Read input value for current time, and              calculate pseudo-input which includes input              offset and gain....                         ***/        *in = *gain * (INPUT(in)+in_offset);        /*** Obtain the "new" input to the Controller              Canonical topology, then propagate through             the integrators....                         ***/        /* calculate the "new" input to the first integrator, based on   */        /* the old values of each integrator multiplied by their         */        /* respective denominator coefficients and then subtracted       */        /* from *in....                                                  */        /* Note that this value, which is similar to a state variable,   */        /* is stored in *(integrator[den_size-1]).                       */        *(integrator[den_size-1]) = *in;        for (i=0; i<den_size-1; i++) {              *(integrator[den_size-1]) =                           *(integrator[den_size-1]) -                           *(old_integrator[i]) * *(den_coefficient[i]);        }            /* Propagate the new input through each integrator in succession. */                for (i=den_size-1; i>0; i--) {              cm_analog_integrate(*(integrator[i]),(integrator[i-1]),&null);        }        /* Calculate the output based on the new integrator values... */        *out = 0.0;        for (i=0; i<num_size; i++) {            *out = *out + ( *(integrator[i]) *                             *(num_coefficient[i]) );        }        pout_pin = *(integrator[1]);                /** Output values for DC & Transient **/        OUTPUT(out) = *out;                  PARTIAL(out,in) = pout_pin;         // cm_analog_auto_partial(); // Removed again. Seems to have problems.    }    /**** AC Analysis ************************************/    else {                            /*** Calculate Real & Imaginary portions of AC gain ***/        /***    at the current RAD_FREQ point...             ***/         /*** Calculate Numerator Real & Imaginary Components... ***/                acc_num.real = 0.0;        acc_num.imag = 0.0;        for (i=0; i<num_size; i++) {            frac = modf(i/2.0, &divide_integer); /* Determine the integer portion    */                                                 /* of a divide-by-2.0 on the index. */            if (modf(divide_integer/2.0,&temp) > 0.0 ) { /* Negative coefficient       */                                                     /* values for this iteration. */                if (frac > 0.0 ) {  /** Odd Powers of "s" **/                    acc_num.imag = acc_num.imag - *(num_coefficient[i]) * pow(RAD_FREQ,i) * (*gain);                 }                else {                      /** Even Powers of "s" **/                    acc_num.real = acc_num.real - *(num_coefficient[i]) * pow(RAD_FREQ,i) * (*gain);                 }            }            else {               /* Positive coefficient values for this iteration */                if (frac> 0.0 ) {  /** Odd Powers of "s" **/                    acc_num.imag = acc_num.imag + *(num_coefficient[i]) * pow(RAD_FREQ,i) * (*gain);                 }                else {                      /** Even Powers of "s" **/                    acc_num.real = acc_num.real + *(num_coefficient[i]) * pow(RAD_FREQ,i) * (*gain);                 }            }        }        /*** Calculate Denominator Real & Imaginary Components... ***/                acc_den.real = 0.0;        acc_den.imag = 0.0;        for (i=0; i<den_size; i++) {            frac = modf(i/2.0, &divide_integer);  /* Determine the integer portion    */                                                 /* of a divide-by-2.0 on the index. */            if (modf(divide_integer/2.0,&temp) > 0.0 ) { /* Negative coefficient       */                                                     /* values for this iteration. */                if (frac > 0.0 ) {  /** Odd Powers of "s" **/                    acc_den.imag = acc_den.imag - *(den_coefficient[i]) * pow(RAD_FREQ,i);                 }                else {                      /** Even Powers of "s" **/                    acc_den.real = acc_den.real - *(den_coefficient[i]) * pow(RAD_FREQ,i);                 }            }            else {               /* Positive coefficient values for this iteration */                if (frac > 0.0 ) {  /** Odd Powers of "s" **/                    acc_den.imag = acc_den.imag + *(den_coefficient[i]) * pow(RAD_FREQ,i);                 }                else {                      /** Even Powers of "s" **/                    acc_den.real = acc_den.real + *(den_coefficient[i]) * pow(RAD_FREQ,i);                 }            }        }                              /* divide numerator values by denominator values */                                                            ac_gain = cm_complex_div(acc_num, acc_den);        AC_GAIN(out,in) = ac_gain;    }	  /* free all allocated memory */		if(integrator) free(integrator);		if(old_integrator) free(old_integrator);		if(den_coefficient) free(den_coefficient);		if(old_den_coefficient) free(old_den_coefficient);		if(num_coefficient) free(num_coefficient);		if(old_num_coefficient) free(old_num_coefficient);}

⌨️ 快捷键说明

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