#ifndef DISTURBANCE_DETECTION_H #define DISTURBANCE_DETECTION_H #include #include "preamble_generator.h" #define PREAMBLE_BIT_GROUP 3 #define PREAMBLE_PHASE_NUM 3 #define PREAMBLE_BIT_LEN (PREAMBLE_LENGTH + 1) /* 32 + 1 temp. */ #define PREAMBLE_SCALE (3200 + 5) #define PREAMBLE_SEARCH_DELTA 64 /* define the length of the array to store the wavelet transform results */ #define WQ_VTB_ZC_DWT_BUF_LEN_MAX (3200 + 128) typedef struct _wq_preamble_bit_value_t { uint16_t bit_pos[PREAMBLE_BIT_GROUP]; uint8_t mag_sign[PREAMBLE_BIT_GROUP]; /* 0: negative, else : positive */ float mag_val[PREAMBLE_BIT_GROUP]; uint8_t bit_cnt; } wq_prm_bit_val_t; typedef struct _wq_preamble_value_t { uint32_t preamble; /* preamble found */ uint32_t pos; /* finally pos. */ float avg_val; /* finally value. */ uint8_t mag_sign[PREAMBLE_LENGTH]; /* 0: negative, else : positive */ uint16_t bits_pos[PREAMBLE_LENGTH]; /* pos of each bit */ float mag_val[PREAMBLE_LENGTH]; }wq_prm_val_t; /* define the structure of array combination required by wavelet transform */ typedef struct _wq_dwt_buff_t { /* define the array required for wavelet transform */ float result_buf[WQ_VTB_ZC_DWT_BUF_LEN_MAX]; float buf[WQ_VTB_ZC_DWT_BUF_LEN_MAX * 2]; /* defines the array needed to find distortion locations */ uint16_t pos_buf[WQ_VTB_ZC_DWT_BUF_LEN_MAX / 2]; uint8_t dir_buf[WQ_VTB_ZC_DWT_BUF_LEN_MAX / 2]; } wq_dwt_buff_t; uint8_t disturb_detection(uint32_t phase, int32_t *data, uint16_t data_len, uint8_t sample_order, int32_t exp_pos, float ave_mag, wq_prm_bit_val_t *preamble_bits_data, wq_dwt_buff_t *dwt_buf); #endif