Browse Source

introduce unwrap, minimum and maximum function

pre-master-46
dwarning 13 years ago
committed by rlar
parent
commit
4635a19ba9
  1. 3
      src/frontend/parse.c
  2. 1
      src/include/ngspice/fteext.h
  3. 23
      src/maths/cmaths/cmath1.c
  4. 1
      src/maths/cmaths/cmath1.h

3
src/frontend/parse.c

@ -140,6 +140,7 @@ struct func ft_funcs[] = {
{ "magnitude", cx_mag }, { "magnitude", cx_mag },
{ "cph", cx_cph }, /* SJdV */ { "cph", cx_cph }, /* SJdV */
{ "cphase", cx_cph }, /* SJdV Continious phase*/ { "cphase", cx_cph }, /* SJdV Continious phase*/
{ "unwrap", cx_unwrap },
{ "ph", cx_ph }, { "ph", cx_ph },
{ "phase", cx_ph }, { "phase", cx_ph },
{ "j", cx_j }, { "j", cx_j },
@ -177,7 +178,9 @@ struct func ft_funcs[] = {
{ "unitvec", cx_unitvec }, { "unitvec", cx_unitvec },
{ "length", cx_length }, { "length", cx_length },
{ "vecmin", cx_min }, { "vecmin", cx_min },
{ "minimum", cx_min },
{ "vecmax", cx_max }, { "vecmax", cx_max },
{ "maximum", cx_max },
{ "vecd", cx_d }, { "vecd", cx_d },
{ "interpolate", (cx_function_t*) cx_interpolate }, { "interpolate", (cx_function_t*) cx_interpolate },
{ "deriv", (cx_function_t*) cx_deriv }, { "deriv", (cx_function_t*) cx_deriv },

1
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_mag(void *, short int , int , int *, short int *);
extern void *cx_ph(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_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_j(void *, short int , int , int *, short int *);
extern void *cx_real(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 *); extern void *cx_imag(void *, short int , int , int *, short int *);

23
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); 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... */ /* If this is pure imaginary we might get real, but never mind... */
void * void *

1
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_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_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_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_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_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); void * cx_imag(void *data, short int type, int length, int *newlength, short int *newtype);

Loading…
Cancel
Save