Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * mer_detector.cpp
- *
- * Created on: 13 ΠΌΠ°Ρ. 2022 Π³.
- * Author: gala13
- */
- #include "mer_detector.h"
- MER_Detector::MER_Detector(int adc_freq, int adc_ch_mask)
- : Tech_Channel(),
- mer_length(mer_factor * adc_freq / top_freq),
- arr_length(2 * mer_length - 1),
- step(mer_length - 1)
- {
- for (int i = 0; i < 3; ++i) {
- if ((adc_ch_mask >> i) & 1) {
- ++num_of_adcs;
- }
- }
- #if DEBUG
- print_wrap("MER: number of working ADCs is (%d), MER LEN is (%d).\r\n", num_of_adcs, mer_length);
- #endif
- }
- void MER_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;
- left_mer_accum -= tech_buf[position];
- right_mer_accum -= tech_buf[(position + step) % arr_length];
- left_mer_accum += tech_buf[(position + mer_length) % arr_length];
- right_mer_accum += val;
- tech_buf[position++] = val;
- position %= arr_length;
- calc_trigger();
- }
- void MER_Detector::calc_trigger() {
- mer_ratio[cur_pos] = estimate_denominator * right_mer_accum / left_mer_accum;
- if (!is_background_mode_on && !is_triggered && is_filled) {
- trigg_fraction = mer_ratio[cur_pos] - mer_ratio[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 MER_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