This article discusses an adaptive method for calculating the zero-crossing rate in actual use. The zero-pass rate is often used in speech detection and recognition. It is generally called a short-term zero-pass rate, which is more appropriate (that is, a short-term stable signal can calculate the zero-pass rate). It is simple and effective, this simple concept is also intended to be used in the near short term to identify footsteps and truck sounds ). The definition of zero crossing rate is generally described using the following expression:
The over-zero rate is a simple measurement of the frequency from the time domain. In general, the larger the over-zero rate, the higher the frequency is, and the higher the frequency is. For more information, see the relevant literature.
Because the noise introduced by the circuit and environment fluctuates at 0 horizontal positions, the over-zero rate is calculated directly, seriously affecting the recognition effect. Therefore, when calculating the zero-crossing rate, this paper limits the threshold of the signal amplitude. The threshold calculation method is as follows:
Because the signal processing must be a window, the average value of the last and current short-term Signal Peak Value VPP is used, multiply by the corresponding coefficient factor F (determined based on the actual noise environment, defined in this article between 0.1 and 0.2) as the threshold for calculating the zero-crossing rate of the current signal.
More intuitive expression in mathematics:
Therefore, the flowchart for calculating the zero-crossing rate after threshold value discrimination is:
The corresponding C program is:
/* signal thresh adaptive structure */struct st_zerorate_thr{ uint32_t pre; uint32_t cur;};/* * @brief * Calculate short time zero cross rate. Short time means n, n often choose to * be a frame(256,512 and so on) * * The diffrence with upstairs is that this one consider the adaptive thresh * when checking the signal, which removes the influence of noise. * @inputs * x[] - input sound signal * n - size of a frame * @outputs * @retval * zero cross rate in a frame length */uint16_t zero_rate(int16_t x[], int n, struct st_zerorate_thr thr){ int i = 1; /* Init to 1 */ uint16_t zero_cnt = 0; float tmp = 0; uint8_t x_pre = 0; while ( (x[i] < thr.cur) && (x[i] > -thr.cur) && (i<n) ) { i++; } x_pre = x[i++]; while ((i < n) && ((x[i] > thr.cur) || (x[i] < -thr.cur)) ) { tmp = x[i] * x_pre; if (tmp < 0) { zero_cnt = zero_cnt + 1; } x_pre = x[i]; i++; } return zero_cnt;}
The above Code defines the threshold structst_zerorate_thr
, The method for updating the threshold is executed in the (2) format,
#define TH_FACTOR (0.2f) /* 0.1~0.2 */void zerorate_thr_update(struct st_zerorate_thr thr, uint32_t peak_value){ thr.pre = thr.cur; thr.cur = (uint32_t)(TH_FACTOR * ((thr.pre + peak_value)>>1) );}
Adaptive zero-crossing rate algorithm for noisy signal