Avoid jump in phase when crossing 90° boundaries.

Code similar to cx_cph in cmath1.c
This commit is contained in:
Holger Vogt 2022-07-03 11:28:00 +02:00
parent b629aad60c
commit 474a1e47b8
1 changed files with 10 additions and 6 deletions

View File

@ -496,19 +496,23 @@ cx_group_delay(void *data, short int type, int length, int *newlength, short int
return (NULL); return (NULL);
} }
if (type == VF_COMPLEX) {
if (type == VF_COMPLEX) /* accept continuous phase over 90° boundaries */
for (i = 0; i < length; i++) double last_ph = cph(cc[0]);
{ v_phase[0] = radtodeg(last_ph);
v_phase[i] = radtodeg(cph(cc[i])); for (i = 1; i < length; i++) {
double ph = cph(cc[i]);
last_ph = ph - (2 * M_PI) * floor((ph - last_ph) / (2 * M_PI) + 0.5);
v_phase[i] = radtodeg(last_ph);
// fprintf(stderr, "v_phase %e, cc %e %e\n", v_phase[i], cc[i].cx_real, cc[i].cx_imag);
} }
}
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);
} }
type = VF_REAL; type = VF_REAL;
/* datos_aux = (char *)cx_deriv((char *)v_phase, type, length, newlength, newtype, pl, newpl, grouping); /* datos_aux = (char *)cx_deriv((char *)v_phase, type, length, newlength, newtype, pl, newpl, grouping);