summaryrefslogtreecommitdiff
path: root/device-functions.c
diff options
context:
space:
mode:
authorroot <root@avtech.domain.avtechpulse.com>2000-01-01 00:46:35 +0900
committerroot <root@avtech.domain.avtechpulse.com>2000-01-01 00:46:35 +0900
commit0243a5fd3a1ac3a3812b56c29a9a8bf86db2d46b (patch)
tree8d107686ae05d80080c3fa141ab66beeade39849 /device-functions.c
parent908f6cf9e4e61ddcdb53e2388364d95ff1952057 (diff)
add, but don't use, 3 pt inversion interpolation - doesn't work well!
Diffstat (limited to 'device-functions.c')
-rw-r--r--device-functions.c53
1 files changed, 51 insertions, 2 deletions
diff --git a/device-functions.c b/device-functions.c
index 82d38e6..609208e 100644
--- a/device-functions.c
+++ b/device-functions.c
@@ -2493,6 +2493,35 @@ static int linear_interpolation (int x1, int x2, float y1, float y2, float y_nee
}
+static int inverse_3pt_interpolation (int X1, int X2, int X3, float y1, float y2, float y3, float y_need)
+{
+ // assuming y = C + B / (x - A)
+ // A, B, C = constants
+ // x = word
+ // y = output
+
+ // doesn't seem to work well - abandoned
+
+ if ((y1 == y2) || (y2 == y3) || (y1 == y3) || (y_need == 0.0)) {
+ return -1;
+ }
+
+ float x1 = (float) X1;
+ float x2 = (float) X2;
+ float x3 = (float) X3;
+
+ float A = (x1*x2*y1 - x1*x2*y2 - x1*x3*y1 + x1*x3*y3 + x2*x3*y2 - x2*x3*y3) /
+ (-x1*y2 + x1*y3 + x2*y1 - x2*y3 - x3*y1 + x3*y2);
+
+ float B = (y1 - y2) / ((1 / (x1 - A)) - (1 / (x2 - A)));
+
+ float C = y1 - B / (x1 - A);
+
+ float solved = A + B / (y_need - C);
+ return (int) solved;
+}
+
+
static int inverse_interpolation (int x1, int x2, float y1, float y2, float y_need)
{
// assuming y = B / (x - A)
@@ -2507,7 +2536,11 @@ static int inverse_interpolation (int x1, int x2, float y1, float y2, float y_ne
float A = ((y1 * x1) - (y2 * x2)) / (y1 - y2);
float B = y1 * (x1 - A);
- return (int) (A + (B / y_need));
+ int solved = (int) (A + (B / y_need));
+
+// printf ("x1 %d, x2 %d, y1 %e, y2 %e, solved %d for %e\n",x1,x2,y1,y2,solved,y_need);
+
+ return (int) solved;
}
@@ -2823,7 +2856,11 @@ int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int
// we copy these floats out into variables because anything that touches
// floats seems to generate instructions that can't work on unaligned
// data and these are unaligned.
- float pwlamp1, pwlamp2;
+ float pwlamp0, pwlamp1, pwlamp2;
+
+// if (index>0) {
+// memcpy(&pwlamp0, &pwl_amp[index-1], sizeof(pwlamp0));
+// }
memcpy(&pwlamp1, &pwl_amp[index], sizeof(pwlamp1));
memcpy(&pwlamp2, &pwl_amp[index+1], sizeof(pwlamp2));
@@ -2886,6 +2923,13 @@ int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int
if (reciprocal_relationship) {
*word_out = inverse_interpolation (pwl_vc[index], pwl_vc[index+1], pwlamp1, pwlamp2, tweaked_use_ampl);
+
+// if (index>0) {
+// int test_word_out = inverse_3pt_interpolation (pwl_vc[index-1], pwl_vc[index], pwl_vc[index+1], pwlamp0, pwlamp1, pwlamp2, tweaked_use_ampl);
+// printf ("%d %d\n",*word_out,test_word_out);
+// *word_out = test_word_out;
+// }
+
} else {
*word_out = linear_interpolation (pwl_vc[index], pwl_vc[index+1], pwlamp1, pwlamp2, tweaked_use_ampl);
}
@@ -2938,6 +2982,11 @@ int Set_VI_Control(int parameter,int channel,float new_ampl,int *point_found,int
*entry=entry_i;
*word_out = inverse_interpolation (pwl_vc[index], pwl_vc[index+1], pwl_amp[index], pwl_amp[index+1], tweaked_use_ampl);
+// if (index>0) {
+// int test_word_out = inverse_3pt_interpolation (pwl_vc[index-1], pwl_vc[index], pwl_vc[index+1], pwl_amp[index-1], pwl_amp[index], pwl_amp[index+1], tweaked_use_ampl);
+// printf ("ext %d %d\n",*word_out,test_word_out);
+// *word_out = test_word_out;
+// }
}
}
}