summaryrefslogtreecommitdiff
path: root/device-functions.c
diff options
context:
space:
mode:
authorroot <root@avtech.domain.avtechpulse.com>2000-01-01 01:53:22 +0900
committerroot <root@avtech.domain.avtechpulse.com>2000-01-01 01:53:22 +0900
commit908f6cf9e4e61ddcdb53e2388364d95ff1952057 (patch)
tree40be40c4327089a36b2fc66e653ff7e86f79e959 /device-functions.c
parent4eebe6533563ba2806c9454d6e2d8b0b2c447082 (diff)
separate function for inverse interpolation of X given desired Y
Diffstat (limited to 'device-functions.c')
-rw-r--r--device-functions.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/device-functions.c b/device-functions.c
index 2bfd784..82d38e6 100644
--- a/device-functions.c
+++ b/device-functions.c
@@ -581,6 +581,8 @@ int Set_Pw(int check_possible_only,int word_override,int range_override,int chan
globals.ChannelState[channel].pw=set_pw;
Set_Update_Chans();
+ g_print_debug("pw range %d, word %d\n",relay_range,word_out);
+
if (!called_from_set_ampl) {
Set_Amplitude(0,0,0,0,0,0,channel,globals.ChannelState[channel].amplitude,1);
}
@@ -2483,14 +2485,36 @@ int Set_VI_Del_Cal(int parameter,int channel,int calibration_point_number)
static int linear_interpolation (int x1, int x2, float y1, float y2, float y_need)
{
+ if ((y2 == y1) || (x2 = x1)) {
+ return -1;
+ }
+
return (int) ( (y_need - y1) / (y2 - y1) * (float) (x2 - x1) ) + x1;
}
+static int inverse_interpolation (int x1, int x2, float y1, float y2, float y_need)
+{
+ // assuming y = B / (x - A)
+ // A, B = constants
+ // x = word
+ // y = output
+
+ if ((y1 == y2) || (y_need == 0.0)) {
+ return -1;
+ }
+
+ float A = ((y1 * x1) - (y2 * x2)) / (y1 - y2);
+ float B = y1 * (x1 - A);
+
+ return (int) (A + (B / y_need));
+}
+
+
int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int *relay_range,int *atten_range,
int *UseNegData,int *entry,int *word_out,int *actual_pol)
{
- float use_ampl,tweaked_use_ampl,fraction;
+ float use_ampl,tweaked_use_ampl;
int i;
float min_os_in_range,max_os_in_range;
float min_ampl_in_range,max_ampl_in_range;
@@ -2500,7 +2524,6 @@ int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int
short *pwl_vc;
int index,use_range;
int range_i,entry_i;
- float inverse_word_out;
int pw_polarity;
float pw_distort_val;
@@ -2841,7 +2864,6 @@ int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int
}
}
- fraction = (tweaked_use_ampl-pwlamp1) / (pwlamp1 - pwlamp2);
*relay_range=range_i;
*entry=entry_i;
@@ -2863,9 +2885,7 @@ int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int
// Normally just the first range is voltage-controlled.
if (reciprocal_relationship) {
- inverse_word_out = fraction * (1.0/((float) pwl_vc[index]) - 1.0/((float) pwl_vc[index+1]));
- inverse_word_out+=1/((float) pwl_vc[index]);
- *word_out=(int) (1.0/inverse_word_out);
+ *word_out = inverse_interpolation (pwl_vc[index], pwl_vc[index+1], pwlamp1, pwlamp2, tweaked_use_ampl);
} else {
*word_out = linear_interpolation (pwl_vc[index], pwl_vc[index+1], pwlamp1, pwlamp2, tweaked_use_ampl);
}
@@ -2914,14 +2934,10 @@ int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int
&& (fabs(pwl_amp[index+1])>smallest_allowed_number)
&& (fabs(pwl_amp[index]-pwl_amp[index+1])>smallest_allowed_number) ) {
*point_found=1;
-
- fraction = (tweaked_use_ampl-pwl_amp[index]) / (pwl_amp[index] - pwl_amp[index+1]);
*relay_range=use_range;
*entry=entry_i;
- inverse_word_out = fraction * (1.0/((float) pwl_vc[index]) - 1.0/((float) pwl_vc[index+1]));
- inverse_word_out+=1/((float) pwl_vc[index]);
- *word_out=(int) (1.0/inverse_word_out);
+ *word_out = inverse_interpolation (pwl_vc[index], pwl_vc[index+1], pwl_amp[index], pwl_amp[index+1], tweaked_use_ampl);
}
}
}