Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "sta_lta_detector.h"
- STA_LTA_Detector::STA_LTA_Detector(int adc_freq, int adc_ch_mask)
- : Tech_Channel(),
- sta_length(sta_factor * adc_freq / top_freq),
- lta_length(lta_factor * adc_freq / top_freq),
- {
- for (int i = 0; i < 3; ++i) {
- if ((adc_ch_mask >> i) & 1) {
- ++num_of_adcs;
- }
- }
- #if DEBUG
- 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);
- #endif
- }
- void STA_LTA_Detector::push_to_calc(int64_t data1_, int64_t data2_, int64_t data3_) {
- data1_ >>= 8;
- data2_ >>= 8;
- data3_ >>= 8;
- int64_t val = ((data1_ * data1_) + (data2_ * data2_) + (data3_ * data3_)) / num_of_adcs;
- lta_accumulator -= tech_buf[position];
- sta_accumulator -= tech_buf[(position + lta_length - sta_length) % lta_length];
- tech_buf[position++] = val;
- position %= lta_length;
- lta_accumulator += val;
- sta_accumulator += val;
- calc_trigger();
- }
- void STA_LTA_Detector::calc_trigger() {
- sta_to_lta[cur_pos] = estimate_denominator * sta_accumulator / lta_accumulator * lta_factor / sta_factor;
- if (!is_background_mode_on && !is_triggered && is_filled) {
- trigg_fraction = sta_to_lta[cur_pos] - sta_to_lta[prev_pos];
- if (trigg_fraction > trigg_lvl || trigg_fraction < -trigg_lvl) {
- is_triggered = true;
- trigg_to_show = trigg_fraction;
- ++events_count;
- }
- }
- else if (position == 0) {
- is_filled = true;
- }
- cur_pos ^= 1;
- prev_pos ^= 1;
- }
- #if DEBUG
- void STA_LTA_Detector::show_triggered() {
- print_wrap("Numerator of trigger function is (%d), tigger level is (|%d|).\r\n", trigg_to_show, trigg_lvl);
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement