diff --git a/src/frontend/parse.c b/src/frontend/parse.c index 25b46559a..29457a1de 100644 --- a/src/frontend/parse.c +++ b/src/frontend/parse.c @@ -140,6 +140,7 @@ struct func ft_funcs[] = { { "magnitude", cx_mag }, { "cph", cx_cph }, /* SJdV */ { "cphase", cx_cph }, /* SJdV Continious phase*/ + { "unwrap", cx_unwrap }, { "ph", cx_ph }, { "phase", cx_ph }, { "j", cx_j }, @@ -177,7 +178,9 @@ struct func ft_funcs[] = { { "unitvec", cx_unitvec }, { "length", cx_length }, { "vecmin", cx_min }, + { "minimum", cx_min }, { "vecmax", cx_max }, + { "maximum", cx_max }, { "vecd", cx_d }, { "interpolate", (cx_function_t*) cx_interpolate }, { "deriv", (cx_function_t*) cx_deriv }, diff --git a/src/include/ngspice/fteext.h b/src/include/ngspice/fteext.h index f7535fbbc..9c70d15a4 100644 --- a/src/include/ngspice/fteext.h +++ b/src/include/ngspice/fteext.h @@ -55,6 +55,7 @@ extern bool cx_degrees; extern void *cx_mag(void *, short int , int , int *, short int *); extern void *cx_ph(void *, short int , int , int *, short int *); extern void *cx_cph(void *, short int , int , int *, short int *); +extern void *cx_unwrap(void *, short int , int , int *, short int *); extern void *cx_j(void *, short int , int , int *, short int *); extern void *cx_real(void *, short int , int , int *, short int *); extern void *cx_imag(void *, short int , int , int *, short int *); diff --git a/src/maths/cmaths/cmath1.c b/src/maths/cmaths/cmath1.c index 50be9fbd6..b8427ec22 100644 --- a/src/maths/cmaths/cmath1.c +++ b/src/maths/cmaths/cmath1.c @@ -93,6 +93,29 @@ cx_cph(void *data, short int type, int length, int *newlength, short int *newtyp return ((void *) d); } +/* Modified from above but with real phase vector in degrees as input */ +void * +cx_unwrap(void *data, short int type, int length, int *newlength, short int *newtype) +{ + double *d = alloc_d(length); + double *dd = (double *) data; + int i; + + *newlength = length; + *newtype = VF_REAL; + if (type == VF_REAL) { + double last_ph = degtorad(dd[0]); + d[0] = last_ph; + for (i = 1; i < length; i++) { + double ph = degtorad(dd[i]); + last_ph = ph - (2*M_PI) * floor((ph - last_ph)/(2*M_PI) + 0.5); + d[i] = radtodeg(last_ph); + } + } + /* Otherwise it is 0, but tmalloc zeros the stuff already. */ + return ((void *) d); +} + /* If this is pure imaginary we might get real, but never mind... */ void * diff --git a/src/maths/cmaths/cmath1.h b/src/maths/cmaths/cmath1.h index 7855f68dc..165738a9a 100644 --- a/src/maths/cmaths/cmath1.h +++ b/src/maths/cmaths/cmath1.h @@ -10,6 +10,7 @@ void * cx_mag(void *data, short int type, int length, int *newlength, short int *newtype); void * cx_ph(void *data, short int type, int length, int *newlength, short int *newtype); void * cx_cph(void *data, short int type, int length, int *newlength, short int *newtype); +void * cx_unwrap(void *data, short int type, int length, int *newlength, short int *newtype); void * cx_j(void *data, short int type, int length, int *newlength, short int *newtype); void * cx_real(void *data, short int type, int length, int *newlength, short int *newtype); void * cx_imag(void *data, short int type, int length, int *newlength, short int *newtype);