added raw file expression functions deriv2() and deriv20() (3-point derivatives)

This commit is contained in:
stefan schippers 2025-11-16 19:58:50 +01:00
parent 1799334a43
commit 369fac66a9
1 changed files with 43 additions and 34 deletions

View File

@ -1747,34 +1747,36 @@ static double ravg_store(int what , int i, int p, int last, double value)
#define INTEG 18 #define INTEG 18
#define AVG 19 #define AVG 19
#define DERIV 20 #define DERIV 20
#define EXCH 21 #define DERIV2 21 /* 3 point deriv */
#define DUP 22 #define EXCH 22
#define RAVG 23 /* running average */ #define DUP 23
#define DB20 24 #define RAVG 24 /* running average */
#define DERIV0 25 /* derivative to first sweep variable, regardless of specified sweep_idx */ #define DB20 25
#define PREV 26 /* previous point */ #define DERIV0 26 /* derivative to first sweep variable, regardless of specified sweep_idx */
#define DEL 27 /* delay by an anount of sweep axis distance */ #define DERIV20 27 /* 3 point derivative to first sweep variable, regardless of specified sweep_idx */
#define MAX 28 /* clip data above given argument */ #define PREV 28 /* previous point */
#define MIN 29 /* clip data below given argument */ #define DEL 29 /* delay by an anount of sweep axis distance */
#define ATAN 30 #define MAX 30 /* clip data above given argument */
#define ASIN 31 #define MIN 31 /* clip data below given argument */
#define ACOS 32 #define ATAN 32
#define COSH 33 #define ASIN 33
#define SINH 34 #define ACOS 34
#define ATANH 35 #define COSH 35
#define ACOSH 36 #define SINH 36
#define ASINH 37 #define ATANH 37
#define IDX 38 /* index of point in raw file (0, 1, 2, ...) */ #define ACOSH 38
#define REAL 39 #define ASINH 39
#define IMAG 40 #define IDX 40 /* index of point in raw file (0, 1, 2, ...) */
#define GT 41 /* greater than */ #define REAL 41
#define LT 42 /* greater than */ #define IMAG 42
#define EQ 43 #define GT 43 /* greater than */
#define NE 44 #define LT 44 /* greater than */
#define GE 45 #define EQ 45
#define LE 46 #define NE 46
#define COND 47 /* conditional expression: X cond Y ? --> X if conf == 1 else Y */ #define GE 47
#define CPH 48 /* continuous phase. Instead of -180..+180 avoid discontinuities */ #define LE 48
#define COND 49 /* conditional expression: X cond Y ? --> X if conf == 1 else Y */
#define CPH 50 /* continuous phase. Instead of -180..+180 avoid discontinuities */
#define ORDER_DERIV 1 /* 1 or 2: 1st order or 2nd order differentiation. 1st order is faster */ #define ORDER_DERIV 1 /* 1 or 2: 1st order or 2nd order differentiation. 1st order is faster */
@ -1881,7 +1883,17 @@ int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr, c
if(first > 0) first--; if(first > 0) first--;
} }
else if(!strcmp(n, "deriv0()")) { else if(!strcmp(n, "deriv0()")) {
stack1[stackptr1++].i = DERIV0; stack1[stackptr1++].i = DERIV0; /* derivative calculation to first sweep var */
if(first > 0) first--;
if(first > 0) first--;
}
else if(!strcmp(n, "deriv2()")) { /* 3 point derivative calculation */
stack1[stackptr1++].i = DERIV2;
if(first > 0) first--;
if(first > 0) first--;
}
else if(!strcmp(n, "deriv20()")) { /* 3 point derivative calculation to first sweep var */
stack1[stackptr1++].i = DERIV20;
if(first > 0) first--; if(first > 0) first--;
if(first > 0) first--; if(first > 0) first--;
} }
@ -2086,7 +2098,6 @@ int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr, c
} }
stack2[stackptr2 - 1] = result; stack2[stackptr2 - 1] = result;
break; break;
#if ORDER_DERIV==1
case DERIV: case DERIV:
if( p == first ) { if( p == first ) {
result = 0; result = 0;
@ -2117,8 +2128,7 @@ int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr, c
} }
stack2[stackptr2 - 1] = result; stack2[stackptr2 - 1] = result;
break; break;
#else /* second order backward differentiation formulas */ case DERIV2:
case DERIV:
if( p == first ) { if( p == first ) {
result = 0; result = 0;
stack1[i].prevy = stack2[stackptr2 - 1]; stack1[i].prevy = stack2[stackptr2 - 1];
@ -2150,7 +2160,7 @@ int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr, c
} }
stack2[stackptr2 - 1] = result; stack2[stackptr2 - 1] = result;
break; break;
case DERIV0: case DERIV20:
if( p == first ) { if( p == first ) {
result = 0; result = 0;
stack1[i].prevy = stack2[stackptr2 - 1]; stack1[i].prevy = stack2[stackptr2 - 1];
@ -2182,7 +2192,6 @@ int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr, c
} }
stack2[stackptr2 - 1] = result; stack2[stackptr2 - 1] = result;
break; break;
#endif
case PREV: case PREV:
if(p == first) { if(p == first) {
result = stack2[stackptr2 - 1]; result = stack2[stackptr2 - 1];