void gen_interp_frequency(struct curve_points *plot) { int i, j, curves; int first_point, num_points; double y; curves = num_curves(plot); first_point = 0; for (i = 0; i < curves; i++) { num_points = next_curve(plot, &first_point); /* If cumulative, replace the current y-value with the sum of all previous y-values. This assumes that the data has already been sorted by x-values. */ if( plot->plot_smooth == SMOOTH_CUMULATIVE ) { y = 0; for (j = first_point; j < first_point + num_points; j++) { if (plot->points[j].type == UNDEFINED) continue; y += plot->points[j].y; plot->points[j].y = y; } } do_freq(plot, first_point, num_points); first_point += num_points + 1; } return; }
void gen_interp_unwrap(struct curve_points *plot) { int i, j, curves; int first_point, num_points; double y, lasty, diff; curves = num_curves(plot); first_point = 0; for (i = 0; i < curves; i++) { num_points = next_curve(plot, &first_point); lasty = 0; /* make all plots start the same place */ for (j = first_point; j < first_point + num_points; j++) { if (plot->points[j].type == UNDEFINED) continue; y = plot->points[j].y; do { diff = y - lasty; if (diff > M_PI) y -= 2*M_PI; if (diff < -M_PI) y += 2*M_PI; } while (fabs(diff) > M_PI); plot->points[j].y = y; lasty = y; } do_freq(plot, first_point, num_points); first_point += num_points + 1; } return; }
void gen_interp(struct curve_points *plot) { spline_coeff *sc; double *bc; struct coordinate *new_points; int i, curves; int first_point, num_points; curves = num_curves(plot); new_points = gp_alloc((samples_1 + 1) * curves * sizeof(struct coordinate), "interpolation table"); first_point = 0; for (i = 0; i < curves; i++) { num_points = next_curve(plot, &first_point); switch (plot->plot_smooth) { case SMOOTH_CSPLINES: sc = cp_tridiag(plot, first_point, num_points); do_cubic(plot, sc, first_point, num_points, new_points + i * (samples_1 + 1)); free(sc); break; case SMOOTH_ACSPLINES: sc = cp_approx_spline(plot, first_point, num_points); do_cubic(plot, sc, first_point, num_points, new_points + i * (samples_1 + 1)); free(sc); break; case SMOOTH_BEZIER: case SMOOTH_SBEZIER: bc = cp_binomial(num_points); do_bezier(plot, bc, first_point, num_points, new_points + i * (samples_1 + 1)); free((char *) bc); break; case SMOOTH_KDENSITY: do_kdensity( plot, first_point, num_points, new_points + i * (samples_1 + 1)); break; default: /* keep gcc -Wall quiet */ ; } new_points[(i + 1) * (samples_1 + 1) - 1].type = UNDEFINED; first_point += num_points; } free(plot->points); plot->points = new_points; plot->p_max = curves * (samples_1 + 1); plot->p_count = plot->p_max - 1; return; }
void gen_interp_frequency(struct curve_points *plot) { int i, j, curves; int first_point, num_points; double y, y_total; curves = num_curves(plot); if (plot->plot_smooth == SMOOTH_CUMULATIVE_NORMALISED) { y_total = 0.0; first_point = 0; for (i = 0; i < curves; i++) { num_points = next_curve(plot, &first_point); for (j = first_point; j < first_point + num_points; j++) { if (plot->points[j].type == UNDEFINED) continue; y_total += plot->points[j].y; } first_point += num_points + 1; } } first_point = 0; for (i = 0; i < curves; i++) { num_points = next_curve(plot, &first_point); /* If cumulative, replace the current y-value with the sum of all previous y-values. This assumes that the data has already been sorted by x-values. */ if( plot->plot_smooth == SMOOTH_CUMULATIVE ) { y = 0; for (j = first_point; j < first_point + num_points; j++) { if (plot->points[j].type == UNDEFINED) continue; y += plot->points[j].y; plot->points[j].y = y; } } /* Alternatively, cumulative normalised means replace the current y-value with the sum of all previous y-values divided by the total sum of all values. This assumes the data is sorted as before. Normalising in this way allows comparison of the CDF of data sets with differing total numbers of samples. */ if (plot->plot_smooth == SMOOTH_CUMULATIVE_NORMALISED) { y = 0; for (j = first_point; j < first_point + num_points; j++) { if (plot->points[j].type == UNDEFINED) continue; y += plot->points[j].y; plot->points[j].y = y / y_total; } } do_freq(plot, first_point, num_points); first_point += num_points + 1; } return; }