added wave processor functions `re()` and `im()` to get real and imaginary part from modulus and phase (expressed in deg)

This commit is contained in:
stefan schippers 2024-02-25 23:54:39 +01:00
parent 7a45497b45
commit 783b5c7aaa
2 changed files with 14 additions and 0 deletions

View File

@ -182,6 +182,8 @@ p{padding: 15px 30px 10px;}
<li><kbd>exch()</kbd> Exchange top 2 operands on stack</li>
<li><kbd>ravg()</kbd> Running average of over a specified time window</li>
<li><kbd>del()</kbd> Delete waveform by specified quantity on the X-axis</li>
<li><kbd>re()</kbd> Return real part of complex number specified as magnitude and phase (in deg)</li>
<li><kbd>im()</kbd> Return imaginary part of complex number specified as magnitude and phase (in deg)</li>
</ul>
<p>1 argument operators:</p>
<ul>

View File

@ -1489,6 +1489,8 @@ static double ravg_store(int what , int i, int p, int last, double value)
#define ACOSH 36
#define ASINH 37
#define IDX 38 /* index of point in raw file (0, 1, 2, ...) */
#define REAL 39
#define IMAG 40
#define ORDER_DERIV 1 /* 1 or 2: 1st order or 2nd order differentiation. 1st order is faster */
@ -1564,6 +1566,8 @@ int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr, c
else if(!strcmp(n, "ravg()")) stack1[stackptr1++].i = RAVG;
else if(!strcmp(n, "max()")) stack1[stackptr1++].i = MAX;
else if(!strcmp(n, "min()")) stack1[stackptr1++].i = MIN;
else if(!strcmp(n, "im()")) stack1[stackptr1++].i = IMAG;
else if(!strcmp(n, "re()")) stack1[stackptr1++].i = REAL;
else if(!strcmp(n, "del()")) {
int d, t = 0, p = 0;
/* set 'first' to beginning of dataset containing 'first' */
@ -1707,6 +1711,14 @@ int plot_raw_custom_data(int sweep_idx, int first, int last, const char *expr, c
stack2[stackptr2 - 2] = pow(stack2[stackptr2 - 2], stack2[stackptr2 - 1]);
stackptr2--;
break;
case REAL:
stack2[stackptr2 - 2] = stack2[stackptr2 - 2] * cos(stack2[stackptr2 - 1] * XSCH_PI / 180.);
stackptr2--;
break;
case IMAG:
stack2[stackptr2 - 2] = stack2[stackptr2 - 2] * sin(stack2[stackptr2 - 1] * XSCH_PI / 180.);
stackptr2--;
break;
case EXCH:
tmp = stack2[stackptr2 - 2];
stack2[stackptr2 - 2] = stack2[stackptr2 - 1];