From 0243a5fd3a1ac3a3812b56c29a9a8bf86db2d46b Mon Sep 17 00:00:00 2001 From: root Date: Sat, 1 Jan 2000 00:46:35 +0900 Subject: add, but don't use, 3 pt inversion interpolation - doesn't work well! --- device-functions.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file 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; +// } } } } -- cgit