whitespace
This commit is contained in:
parent
c8cd8b95a8
commit
e1fa276ddc
|
|
@ -32,6 +32,7 @@ Author: 1985 Wayne A. Christopher, U. C. Berkeley CAD Group
|
||||||
|
|
||||||
extern bool cx_degrees;
|
extern bool cx_degrees;
|
||||||
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
cx_and(void *data1, void *data2, short int datatype1, short int datatype2, int length)
|
cx_and(void *data1, void *data2, short int datatype1, short int datatype2, int length)
|
||||||
{
|
{
|
||||||
|
|
@ -70,6 +71,7 @@ cx_and(void *data1, void *data2, short int datatype1, short int datatype2, int l
|
||||||
return ((void *) d);
|
return ((void *) d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
cx_or(void *data1, void *data2, short int datatype1, short int datatype2, int length)
|
cx_or(void *data1, void *data2, short int datatype1, short int datatype2, int length)
|
||||||
{
|
{
|
||||||
|
|
@ -108,6 +110,7 @@ cx_or(void *data1, void *data2, short int datatype1, short int datatype2, int le
|
||||||
return ((void *) d);
|
return ((void *) d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
cx_not(void *data, short int type, int length, int *newlength, short int *newtype)
|
cx_not(void *data, short int type, int length, int *newlength, short int *newtype)
|
||||||
{
|
{
|
||||||
|
|
@ -133,7 +136,6 @@ cx_not(void *data, short int type, int length, int *newlength, short int *newtyp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* This is a strange function. What we do is fit a polynomial to the
|
/* This is a strange function. What we do is fit a polynomial to the
|
||||||
* curve, of degree $polydegree, and then evaluate it at the points
|
* curve, of degree $polydegree, and then evaluate it at the points
|
||||||
* in the time scale. What we do is this: for every set of points that
|
* in the time scale. What we do is this: for every set of points that
|
||||||
|
|
@ -142,7 +144,9 @@ cx_not(void *data, short int type, int length, int *newlength, short int *newtyp
|
||||||
* one). At the ends we just use what we have... We have to detect
|
* one). At the ends we just use what we have... We have to detect
|
||||||
* badness here too...
|
* badness here too...
|
||||||
*
|
*
|
||||||
* Note that we pass arguments differently for this one cx_ function... */
|
* Note that we pass arguments differently for this one cx_ function...
|
||||||
|
*/
|
||||||
|
|
||||||
void *
|
void *
|
||||||
cx_interpolate(void *data, short int type, int length, int *newlength, short int *newtype, struct plot *pl, struct plot *newpl, int grouping)
|
cx_interpolate(void *data, short int type, int length, int *newlength, short int *newtype, struct plot *pl, struct plot *newpl, int grouping)
|
||||||
{
|
{
|
||||||
|
|
@ -153,7 +157,7 @@ cx_interpolate(void *data, short int type, int length, int *newlength, short int
|
||||||
int base;
|
int base;
|
||||||
|
|
||||||
if (grouping == 0)
|
if (grouping == 0)
|
||||||
grouping = length;
|
grouping = length;
|
||||||
|
|
||||||
/* First do some sanity checks. */
|
/* First do some sanity checks. */
|
||||||
if (!pl || !pl->pl_scale || !newpl || !newpl->pl_scale) {
|
if (!pl || !pl->pl_scale || !newpl || !newpl->pl_scale) {
|
||||||
|
|
@ -211,18 +215,19 @@ cx_interpolate(void *data, short int type, int length, int *newlength, short int
|
||||||
degree = 1;
|
degree = 1;
|
||||||
|
|
||||||
for (base = 0; base < length; base += grouping) {
|
for (base = 0; base < length; base += grouping) {
|
||||||
if (!ft_interpolate((double *) data + base, d + base,
|
if (!ft_interpolate((double *) data + base, d + base,
|
||||||
os->v_realdata + base, grouping,
|
os->v_realdata + base, grouping,
|
||||||
ns->v_realdata + base, grouping, degree))
|
ns->v_realdata + base, grouping, degree))
|
||||||
{
|
{
|
||||||
tfree(d);
|
tfree(d);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((void *) d);
|
return ((void *) d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
cx_deriv(void *data, short int type, int length, int *newlength, short int *newtype, struct plot *pl, struct plot *newpl, int grouping)
|
cx_deriv(void *data, short int type, int length, int *newlength, short int *newtype, struct plot *pl, struct plot *newpl, int grouping)
|
||||||
{
|
{
|
||||||
|
|
@ -230,11 +235,11 @@ cx_deriv(void *data, short int type, int length, int *newlength, short int *newt
|
||||||
double *spare;
|
double *spare;
|
||||||
double x;
|
double x;
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
int degree;
|
int degree;
|
||||||
int n, base;
|
int n, base;
|
||||||
|
|
||||||
if (grouping == 0)
|
if (grouping == 0)
|
||||||
grouping = length;
|
grouping = length;
|
||||||
/* First do some sanity checks. */
|
/* First do some sanity checks. */
|
||||||
if (!pl || !pl->pl_scale || !newpl || !newpl->pl_scale) {
|
if (!pl || !pl->pl_scale || !newpl || !newpl->pl_scale) {
|
||||||
fprintf(cp_err, "Internal error: cx_deriv: bad scale\n");
|
fprintf(cp_err, "Internal error: cx_deriv: bad scale\n");
|
||||||
|
|
@ -242,9 +247,9 @@ cx_deriv(void *data, short int type, int length, int *newlength, short int *newt
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cp_getvar("dpolydegree", CP_NUM, °ree))
|
if (!cp_getvar("dpolydegree", CP_NUM, °ree))
|
||||||
degree = 2; /* default quadratic */
|
degree = 2; /* default quadratic */
|
||||||
|
|
||||||
n = degree + 1;
|
n = degree + 1;
|
||||||
|
|
||||||
spare = alloc_d(n);
|
spare = alloc_d(n);
|
||||||
scratch = alloc_d(n * (n + 1));
|
scratch = alloc_d(n * (n + 1));
|
||||||
|
|
@ -253,169 +258,168 @@ cx_deriv(void *data, short int type, int length, int *newlength, short int *newt
|
||||||
*newtype = type;
|
*newtype = type;
|
||||||
|
|
||||||
if (type == VF_COMPLEX) {
|
if (type == VF_COMPLEX) {
|
||||||
ngcomplex_t *c_outdata, *c_indata;
|
ngcomplex_t *c_outdata, *c_indata;
|
||||||
double *r_coefs, *i_coefs;
|
double *r_coefs, *i_coefs;
|
||||||
double *scale;
|
double *scale;
|
||||||
|
|
||||||
r_coefs = alloc_d(n);
|
r_coefs = alloc_d(n);
|
||||||
i_coefs = alloc_d(n);
|
i_coefs = alloc_d(n);
|
||||||
c_indata = (ngcomplex_t *) data;
|
c_indata = (ngcomplex_t *) data;
|
||||||
c_outdata = alloc_c(length);
|
c_outdata = alloc_c(length);
|
||||||
scale = alloc_d(length); /* XXX */
|
scale = alloc_d(length); /* XXX */
|
||||||
if (pl->pl_scale->v_type == VF_COMPLEX)
|
if (pl->pl_scale->v_type == VF_COMPLEX)
|
||||||
/* Not ideal */
|
/* Not ideal */
|
||||||
for (i = 0; i < length; i++)
|
for (i = 0; i < length; i++)
|
||||||
scale[i] = realpart(pl->pl_scale->v_compdata[i]);
|
scale[i] = realpart(pl->pl_scale->v_compdata[i]);
|
||||||
else
|
else
|
||||||
for (i = 0; i < length; i++)
|
for (i = 0; i < length; i++)
|
||||||
scale[i] = pl->pl_scale->v_realdata[i];
|
scale[i] = pl->pl_scale->v_realdata[i];
|
||||||
|
|
||||||
for (base = 0; base < length; base += grouping)
|
for (base = 0; base < length; base += grouping)
|
||||||
{
|
|
||||||
k = 0;
|
|
||||||
for (i = degree; i < grouping; i += 1)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* real */
|
|
||||||
for (j = 0; j < n; j++)
|
|
||||||
spare[j] = c_indata[j + i + base].cx_real;
|
|
||||||
if (!ft_polyfit(scale + i + base - degree,
|
|
||||||
spare, r_coefs, degree, scratch))
|
|
||||||
{
|
|
||||||
fprintf(stderr, "ft_polyfit @ %d failed\n", i);
|
|
||||||
}
|
|
||||||
ft_polyderiv(r_coefs, degree);
|
|
||||||
|
|
||||||
/* for loop gets the beginning part */
|
|
||||||
for (j = k; j <= i + degree / 2; j++)
|
|
||||||
{
|
{
|
||||||
x = scale[j + base];
|
k = 0;
|
||||||
c_outdata[j + base].cx_real =
|
for (i = degree; i < grouping; i += 1)
|
||||||
ft_peval(x, r_coefs, degree - 1);
|
{
|
||||||
}
|
|
||||||
|
|
||||||
/* imag */
|
/* real */
|
||||||
for (j = 0; j < n; j++)
|
for (j = 0; j < n; j++)
|
||||||
spare[j] = c_indata[j + i + base].cx_imag;
|
spare[j] = c_indata[j + i + base].cx_real;
|
||||||
if (!ft_polyfit(scale + i - degree + base,
|
if (!ft_polyfit(scale + i + base - degree,
|
||||||
spare, i_coefs, degree, scratch))
|
spare, r_coefs, degree, scratch))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ft_polyfit @ %d failed\n", i);
|
fprintf(stderr, "ft_polyfit @ %d failed\n", i);
|
||||||
}
|
}
|
||||||
ft_polyderiv(i_coefs, degree);
|
ft_polyderiv(r_coefs, degree);
|
||||||
|
|
||||||
/* for loop gets the beginning part */
|
/* for loop gets the beginning part */
|
||||||
for (j = k; j <= i - degree / 2; j++)
|
for (j = k; j <= i + degree / 2; j++)
|
||||||
{
|
{
|
||||||
x = scale[j + base];
|
x = scale[j + base];
|
||||||
c_outdata[j + base].cx_imag =
|
c_outdata[j + base].cx_real =
|
||||||
ft_peval(x, i_coefs, degree - 1);
|
ft_peval(x, r_coefs, degree - 1);
|
||||||
}
|
}
|
||||||
k = j;
|
|
||||||
}
|
/* imag */
|
||||||
|
for (j = 0; j < n; j++)
|
||||||
|
spare[j] = c_indata[j + i + base].cx_imag;
|
||||||
|
if (!ft_polyfit(scale + i - degree + base,
|
||||||
|
spare, i_coefs, degree, scratch))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ft_polyfit @ %d failed\n", i);
|
||||||
|
}
|
||||||
|
ft_polyderiv(i_coefs, degree);
|
||||||
|
|
||||||
|
/* for loop gets the beginning part */
|
||||||
|
for (j = k; j <= i - degree / 2; j++)
|
||||||
|
{
|
||||||
|
x = scale[j + base];
|
||||||
|
c_outdata[j + base].cx_imag =
|
||||||
|
ft_peval(x, i_coefs, degree - 1);
|
||||||
|
}
|
||||||
|
k = j;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get the tail */
|
||||||
|
for (j = k; j < length; j++)
|
||||||
|
{
|
||||||
|
x = scale[j + base];
|
||||||
|
/* real */
|
||||||
|
c_outdata[j + base].cx_real = ft_peval(x, r_coefs, degree - 1);
|
||||||
|
/* imag */
|
||||||
|
c_outdata[j + base].cx_imag = ft_peval(x, i_coefs, degree - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tfree(r_coefs);
|
||||||
|
tfree(i_coefs);
|
||||||
|
tfree(scale);
|
||||||
|
return (void *) c_outdata;
|
||||||
|
|
||||||
/* get the tail */
|
|
||||||
for (j = k; j < length; j++)
|
|
||||||
{
|
|
||||||
x = scale[j + base];
|
|
||||||
/* real */
|
|
||||||
c_outdata[j + base].cx_real = ft_peval(x, r_coefs, degree - 1);
|
|
||||||
/* imag */
|
|
||||||
c_outdata[j + base].cx_imag = ft_peval(x, i_coefs, degree - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* all-real case */
|
||||||
|
double *coefs;
|
||||||
|
|
||||||
tfree(r_coefs);
|
double *outdata, *indata;
|
||||||
tfree(i_coefs);
|
double *scale;
|
||||||
tfree(scale);
|
|
||||||
return (void *) c_outdata;
|
|
||||||
|
|
||||||
}
|
coefs = alloc_d(n);
|
||||||
else
|
indata = (double *) data;
|
||||||
{
|
outdata = alloc_d(length);
|
||||||
/* all-real case */
|
scale = alloc_d(length); /* XXX */
|
||||||
double *coefs;
|
|
||||||
|
|
||||||
double *outdata, *indata;
|
/* Here I encountered a problem because when we issue an instruction like this:
|
||||||
double *scale;
|
* plot -deriv(vp(3)) to calculate something similar to the group delay, the code
|
||||||
|
* detects that vector vp(3) is real and it is believed that the frequency is also
|
||||||
coefs = alloc_d(n);
|
* real. The frequency is COMPLEX and the program aborts so I'm going to put the
|
||||||
indata = (double *) data;
|
* check that the frequency is complex vector not to abort.
|
||||||
outdata = alloc_d(length);
|
*/
|
||||||
scale = alloc_d(length); /* XXX */
|
|
||||||
|
|
||||||
/* Here I encountered a problem because when we issue an instruction like this:
|
|
||||||
* plot -deriv(vp(3)) to calculate something similar to the group delay, the code
|
|
||||||
* detects that vector vp(3) is real and it is believed that the frequency is also
|
|
||||||
* real. The frequency is COMPLEX and the program aborts so I'm going to put the
|
|
||||||
* check that the frequency is complex vector not to abort.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/* Original problematic code
|
/* Original problematic code
|
||||||
* for (i = 0; i < length; i++)
|
* for (i = 0; i < length; i++)
|
||||||
* scale[i] = pl->pl_scale->v_realdata[i];
|
* scale[i] = pl->pl_scale->v_realdata[i];
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Modified to deal with complex frequency vector */
|
/* Modified to deal with complex frequency vector */
|
||||||
if (pl->pl_scale->v_type == VF_COMPLEX)
|
if (pl->pl_scale->v_type == VF_COMPLEX)
|
||||||
for (i = 0; i < length; i++)
|
for (i = 0; i < length; i++)
|
||||||
scale[i] = realpart(pl->pl_scale->v_compdata[i]);
|
scale[i] = realpart(pl->pl_scale->v_compdata[i]);
|
||||||
else
|
else
|
||||||
for (i = 0; i < length; i++)
|
for (i = 0; i < length; i++)
|
||||||
scale[i] = pl->pl_scale->v_realdata[i];
|
scale[i] = pl->pl_scale->v_realdata[i];
|
||||||
|
|
||||||
|
|
||||||
|
for (base = 0; base < length; base += grouping)
|
||||||
for (base = 0; base < length; base += grouping)
|
|
||||||
{
|
|
||||||
k = 0;
|
|
||||||
for (i = degree; i < grouping; i += 1)
|
|
||||||
{
|
|
||||||
if (!ft_polyfit(scale + i - degree + base,
|
|
||||||
indata + i - degree + base, coefs, degree, scratch))
|
|
||||||
{
|
|
||||||
fprintf(stderr, "ft_polyfit @ %d failed\n", i + base);
|
|
||||||
}
|
|
||||||
ft_polyderiv(coefs, degree);
|
|
||||||
|
|
||||||
/* for loop gets the beginning part */
|
|
||||||
for (j = k; j <= i - degree / 2; j++)
|
|
||||||
{
|
{
|
||||||
/* Seems the same problem because the frequency vector is complex
|
k = 0;
|
||||||
* and the real part of the complex should be accessed because if we
|
for (i = degree; i < grouping; i += 1)
|
||||||
* run x = pl-> pl_scale-> v_realdata [base + j]; the execution will
|
{
|
||||||
* abort.
|
if (!ft_polyfit(scale + i - degree + base,
|
||||||
*/
|
indata + i - degree + base, coefs, degree, scratch))
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ft_polyfit @ %d failed\n", i + base);
|
||||||
|
}
|
||||||
|
ft_polyderiv(coefs, degree);
|
||||||
|
|
||||||
if (pl->pl_scale->v_type == VF_COMPLEX)
|
/* for loop gets the beginning part */
|
||||||
x = realpart(pl->pl_scale->v_compdata[j+base]); /* For complex scale vector */
|
for (j = k; j <= i - degree / 2; j++)
|
||||||
else
|
{
|
||||||
x = pl->pl_scale->v_realdata[j + base]; /* For real scale vector */
|
/* Seems the same problem because the frequency vector is complex
|
||||||
|
* and the real part of the complex should be accessed because if we
|
||||||
|
* run x = pl-> pl_scale-> v_realdata [base + j]; the execution will
|
||||||
|
* abort.
|
||||||
|
*/
|
||||||
|
|
||||||
outdata[j + base] = ft_peval(x, coefs, degree - 1);
|
if (pl->pl_scale->v_type == VF_COMPLEX)
|
||||||
}
|
x = realpart(pl->pl_scale->v_compdata[j+base]); /* For complex scale vector */
|
||||||
k = j;
|
else
|
||||||
}
|
x = pl->pl_scale->v_realdata[j + base]; /* For real scale vector */
|
||||||
|
|
||||||
for (j = k; j < length; j++)
|
outdata[j + base] = ft_peval(x, coefs, degree - 1);
|
||||||
{
|
}
|
||||||
/* Again the same error */
|
k = j;
|
||||||
/* x = pl->pl_scale->v_realdata[j + base]; */
|
}
|
||||||
if (pl->pl_scale->v_type == VF_COMPLEX)
|
|
||||||
x = realpart(pl->pl_scale->v_compdata[j+base]); /* For complex scale vector */
|
|
||||||
else
|
|
||||||
x = pl->pl_scale->v_realdata[j + base]; /* For real scale vector */
|
|
||||||
|
|
||||||
outdata[j + base] = ft_peval(x, coefs, degree - 1);
|
for (j = k; j < length; j++)
|
||||||
}
|
{
|
||||||
}
|
/* Again the same error */
|
||||||
|
/* x = pl->pl_scale->v_realdata[j + base]; */
|
||||||
|
if (pl->pl_scale->v_type == VF_COMPLEX)
|
||||||
|
x = realpart(pl->pl_scale->v_compdata[j+base]); /* For complex scale vector */
|
||||||
|
else
|
||||||
|
x = pl->pl_scale->v_realdata[j + base]; /* For real scale vector */
|
||||||
|
|
||||||
|
outdata[j + base] = ft_peval(x, coefs, degree - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
tfree(coefs);
|
tfree(coefs);
|
||||||
tfree(scale); /* XXX */
|
tfree(scale); /* XXX */
|
||||||
return (char *) outdata;
|
return (char *) outdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -433,20 +437,20 @@ cx_group_delay(void *data, short int type, int length, int *newlength, short int
|
||||||
/* Check to see if we have the frequency vector for the derivative */
|
/* Check to see if we have the frequency vector for the derivative */
|
||||||
if (!eq(pl->pl_scale->v_name, "frequency"))
|
if (!eq(pl->pl_scale->v_name, "frequency"))
|
||||||
{
|
{
|
||||||
fprintf(cp_err, "Internal error: cx_group_delay: need frequency based complex vector.\n");
|
fprintf(cp_err, "Internal error: cx_group_delay: need frequency based complex vector.\n");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (type == VF_COMPLEX)
|
if (type == VF_COMPLEX)
|
||||||
for (i = 0; i < length; i++)
|
for (i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
v_phase[i] = radtodeg(cph(cc[i]));
|
v_phase[i] = radtodeg(cph(cc[i]));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(cp_err, "Signal must be complex to calculate group delay\n");
|
fprintf(cp_err, "Signal must be complex to calculate group delay\n");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -469,18 +473,18 @@ cx_group_delay(void *data, short int type, int length, int *newlength, short int
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(cx_degrees)
|
if(cx_degrees)
|
||||||
{
|
{
|
||||||
adjust_final=1.0/360;
|
adjust_final=1.0/360;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
adjust_final=1.0/(2*M_PI);
|
adjust_final=1.0/(2*M_PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < length; i++)
|
for (i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
group_delay[i] = -datos[i]*adjust_final;
|
group_delay[i] = -datos[i]*adjust_final;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adjust to Real because the result is Real */
|
/* Adjust to Real because the result is Real */
|
||||||
|
|
@ -492,6 +496,5 @@ cx_group_delay(void *data, short int type, int length, int *newlength, short int
|
||||||
*/
|
*/
|
||||||
pl->pl_dvecs->v_type= SV_TIME;
|
pl->pl_dvecs->v_type= SV_TIME;
|
||||||
|
|
||||||
return ((char *) group_delay);
|
return ((char *) group_delay);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue