227 std::vector<int32_t> kiWfmSignal;
231 int n = kiWfmSignal.size();
233 if (
fIsDebug) printf(
"ERROR: Order too high; will make solution singular\n");
238 for (
int k = 1; k <= n - 2; k++)
239 r1 += std::pow(kiWfmSignal.at(k), 2);
241 float r2 = std::pow(kiWfmSignal.front(), 2);
242 float r3 = std::pow(kiWfmSignal.back(), 2);
246 r1 = 1. / (rho_b + r3);
248 std::vector<float> c, d;
249 c.push_back(kiWfmSignal.back() * r1);
250 d.push_back(kiWfmSignal.front() * r1);
254 std::vector<float> ef, eb, ec, ed;
255 std::vector<float> coeffs;
258 for (
int v_iter = 0; v_iter < n; v_iter++) {
259 ef.push_back(kiWfmSignal.at(v_iter));
260 eb.push_back(kiWfmSignal.at(v_iter));
261 ec.push_back(c.at(0) * kiWfmSignal.at(v_iter));
262 ed.push_back(d.at(0) * kiWfmSignal.at(v_iter));
268 if (rho_f <= 0 || rho_b <= 0) {
270 printf(
"PsdPronyFitter::ERROR: prediction squared error was less "
271 "than or equal to zero\n");
275 gam = 1. - ec.at(n - k);
276 del = 1. - ed.front();
277 if (gam <= 0 || gam > 1 || del <= 0 || del > 1) {
279 printf(
"PsdPronyFitter::ERROR: GAM or DEL gain factor not in "
280 "expected range 0 to 1\n");
285 std::vector<float> eff, ebb;
289 for (
int v_iter = 0; v_iter < n - 1; v_iter++) {
290 eff.at(v_iter) = ef.at(v_iter + 1);
291 ebb.at(v_iter) = eb.at(v_iter);
292 delta += eff.at(v_iter) * ebb.at(v_iter);
295 float k_f = -delta / rho_b;
296 float k_b = -delta / rho_f;
299 rho_f = rho_f * (1 - k_f * k_b);
300 rho_b = rho_b * (1 - k_f * k_b);
303 std::vector<float> temp_af = a_f;
304 std::reverse(std::begin(a_b), std::end(a_b));
305 for (uint8_t i = 0; i < a_f.size(); i++)
306 a_f.at(i) += k_f * a_b.at(i);
309 std::reverse(std::begin(a_b), std::end(a_b));
310 std::reverse(std::begin(temp_af), std::end(temp_af));
311 for (uint8_t i = 0; i < a_b.size(); i++)
312 a_b.at(i) += k_b * temp_af.at(i);
323 for (
int v_iter = 0; v_iter < n; v_iter++) {
324 eb.at(v_iter) = ebb.at(v_iter) + k_b * eff.at(v_iter);
325 ef.at(v_iter) = eff.at(v_iter) + k_f * ebb.at(v_iter);
329 coeffs.at(0) = ec.front();
330 coeffs.at(1) = coeffs.at(0) / del;
331 coeffs.at(2) = coeffs.at(0) / gam;
334 std::vector<float> temp_c = c;
335 for (uint8_t v_iter = 0; v_iter < c.size(); v_iter++) {
336 c.at(v_iter) += coeffs.at(1) * d.at(v_iter);
337 d.at(v_iter) += coeffs.at(2) * temp_c.at(v_iter);
341 std::vector<float> temp_ec = ec;
342 for (
int v_iter = 0; v_iter < n; v_iter++) {
343 ec.at(v_iter) += coeffs.at(1) * ed.at(v_iter);
344 ed.at(v_iter) += coeffs.at(2) * temp_ec.at(v_iter);
347 std::vector<float> ecc, edd;
350 for (
int v_iter = 0; v_iter < n - 1; v_iter++) {
351 ecc.at(v_iter) = ec.at(v_iter + 1);
352 edd.at(v_iter) = ed.at(v_iter);
355 if (rho_f <= 0 || rho_b <= 0) {
357 printf(
"PsdPronyFitter::ERROR2: prediction squared error was less "
358 "than or equal to zero\n");
361 gam = 1 - ecc.at(n - k - 1);
362 del = 1 - edd.front();
363 if (gam <= 0 || gam > 1 || del <= 0 || del > 1) {
365 printf(
"PsdPronyFitter::ERROR2: GAM or DEL gain factor not in "
366 "expected range 0 to 1\n");
372 coeffs.at(0) = ef.front();
373 coeffs.at(1) = eb.at(n - k - 1);
374 coeffs.at(2) = coeffs.at(1) / rho_b;
375 coeffs.at(3) = coeffs.at(0) / rho_f;
376 coeffs.at(4) = coeffs.at(0) / del;
377 coeffs.at(5) = coeffs.at(1) / gam;
380 std::vector<float> temp_ab = a_b;
381 std::reverse(std::begin(temp_ab), std::end(temp_ab));
382 std::reverse(std::begin(c), std::end(c));
384 for (uint8_t i = 0; i < a_b.size(); i++)
385 a_b.at(i) += coeffs.at(5) * c.at(i);
386 std::reverse(std::begin(c), std::end(c));
388 for (uint8_t i = 0; i < c.size(); i++)
389 c.at(i) += coeffs.at(2) * temp_ab.at(i);
390 c.push_back(coeffs.at(2));
392 std::vector<float> temp_af2 = a_f;
393 for (uint8_t i = 0; i < a_f.size(); i++)
394 a_f.at(i) += coeffs.at(4) * d.at(i);
396 for (uint8_t i = 0; i < d.size(); i++)
397 d.at(i) += coeffs.at(3) * temp_af2.at(i);
398 d.insert(d.begin(), coeffs.at(3));
401 rho_f = rho_f - coeffs.at(4) * coeffs.at(0);
402 rho_b = rho_b - coeffs.at(5) * coeffs.at(1);
404 if (rho_f <= 0 || rho_b <= 0) {
406 printf(
"PsdPronyFitter::ERROR3: prediction squared error was less "
407 "than or equal to zero\n");
412 for (
int v_iter = 0; v_iter < n; v_iter++) {
413 ec.at(v_iter) = ecc.at(v_iter) + coeffs.at(2) * eb.at(v_iter);
414 eb.at(v_iter) = eb.at(v_iter) + coeffs.at(5) * ecc.at(v_iter);
415 ed.at(v_iter) = edd.at(v_iter) + coeffs.at(3) * ef.at(v_iter);
416 ef.at(v_iter) = ef.at(v_iter) + coeffs.at(4) * edd.at(v_iter);
446 std::complex<float>** Zik_arr =
new std::complex<float>*[
fExpNumber + 1];
448 Zik_arr[i] =
new std::complex<float>[
fExpNumber + 1];
450 Zik_arr[i][j] = {0., 0.};
453 std::complex<float>* Zyk_arr =
new std::complex<float>[
fExpNumber + 1];
455 Zyk_arr[i] = {0., 0.};
458 const std::complex<float> unit = {1., 0.};
462 std::complex<float> temp = std::conj(
fz[i]) *
fz[j];
463 if (std::abs(temp - unit) > 1e-3) {
464 Zik_arr[i][j] =
static_cast<std::complex<float>
>((std::pow(temp,
static_cast<float>(samples_in_gate)) - unit)
468 Zik_arr[i][j] =
static_cast<std::complex<float>
>(samples_in_gate);
473 std::complex<float>* z_power =
new std::complex<float>[
fExpNumber + 1];
479 Zyk_arr[i] += (std::complex<float>) (std::conj(z_power[i]) * (
float)
fuWfm.at(sample_curr));
485 printf(
"\nampl calculation\n");
488 printf(
"%e%+ei ", std::real(Zik_arr[i][j]), std::imag(Zik_arr[i][j]));
489 printf(
" %e%+ei\n", std::real(Zyk_arr[i]), std::imag(Zyk_arr[i]));
496 printf(
"amplitudes\n%.0f%+.0fi ", std::real(
fh[0]), std::imag(
fh[0]));
498 printf(
"%e%+ei ", std::real(
fh[i]), std::imag(
fh[i]));
505 std::complex<float> fit_ampl_in_sample = {0., 0.};
507 for (
int sample_curr = 0; sample_curr <
fSampleTotal; sample_curr++) {
508 fit_ampl_in_sample = {0., 0.};
511 fit_ampl_in_sample +=
fh[i] * z_power[i];
514 fuFitWfm.at(sample_curr) = (uint16_t) std::real(fit_ampl_in_sample);
521 printf(
"waveform:\n");
522 for (uint8_t i = 0; i <
fuWfm.size(); i++)
523 printf(
"%u ",
fuWfm.at(i));
525 printf(
"\nfit waveform:\n");
526 for (uint8_t i = 0; i <
fuFitWfm.size(); i++)