Advertisement
Nuke29

sta_lta_detector.cpp

Oct 3rd, 2022 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | Source Code | 0 0
  1. #include "sta_lta_detector.h"
  2.  
  3. STA_LTA_Detector::STA_LTA_Detector(int adc_freq, int adc_ch_mask)
  4. : Tech_Channel(),
  5.   sta_length(sta_factor * adc_freq / top_freq),
  6.   lta_length(lta_factor * adc_freq / top_freq),
  7. {
  8.     for (int i = 0; i < 3; ++i) {
  9.         if ((adc_ch_mask >> i) & 1) {
  10.             ++num_of_adcs;
  11.         }
  12.     }
  13. #if DEBUG
  14.     print_wrap("STA_LTA: number of working ADCs is (%d), STA LEN is (%d), LTA LEN is (%d).\r\n", num_of_adcs, sta_length, lta_length);
  15. #endif
  16. }
  17.  
  18. void STA_LTA_Detector::push_to_calc(int64_t data1_, int64_t data2_, int64_t data3_) {
  19.     data1_ >>= 8;
  20.     data2_ >>= 8;
  21.     data3_ >>= 8;
  22.     int64_t val = ((data1_ * data1_) + (data2_ * data2_) + (data3_ * data3_)) / num_of_adcs;
  23.  
  24.     lta_accumulator -= tech_buf[position];
  25.     sta_accumulator -= tech_buf[(position + lta_length - sta_length) % lta_length];
  26.     tech_buf[position++] = val;
  27.     position %= lta_length;
  28.  
  29.   lta_accumulator += val;
  30.   sta_accumulator += val;
  31.  
  32.   calc_trigger();
  33. }
  34.  
  35. void STA_LTA_Detector::calc_trigger() {
  36.     sta_to_lta[cur_pos] = estimate_denominator * sta_accumulator / lta_accumulator * lta_factor / sta_factor;
  37.     if (!is_background_mode_on && !is_triggered && is_filled) {
  38.         trigg_fraction = sta_to_lta[cur_pos] - sta_to_lta[prev_pos];
  39.         if (trigg_fraction > trigg_lvl || trigg_fraction < -trigg_lvl) {
  40.             is_triggered = true;
  41.             trigg_to_show = trigg_fraction;
  42.             ++events_count;
  43.         }
  44.     }
  45.     else if (position == 0) {
  46.         is_filled = true;
  47.     }
  48.     cur_pos ^= 1;
  49.     prev_pos ^= 1;
  50. }
  51.  
  52. #if DEBUG
  53. void STA_LTA_Detector::show_triggered() {
  54.     print_wrap("Numerator of trigger function is (%d), tigger level is (|%d|).\r\n", trigg_to_show, trigg_lvl);
  55. }
  56. #endif
  57.  
  58.  
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement