Logo Search packages:      
Sourcecode: aubio version File versions  Download package

smpl_t vec_moving_thres ( fvec_t vec,
fvec_t tmp,
uint_t  win_post,
uint_t  win_pre,
uint_t  win_pos 

adaptative thresholding

y=fn_thresh(fn,x,post,pre) compute adaptive threshold at each time fn : a function name or pointer, eg 'median' x: signal vector post: window length, causal part pre: window length, anti-causal part Returns: y: signal the same length as x

Formerly median_thresh, used compute median over a window of post+pre+1 samples, but now works with any function that takes a vector or matrix and returns a 'representative' value for each column, eg medians=fn_thresh(median,x,8,8) minima=fn_thresh(min,x,8,8) see SPARMS for explanation of post and pre

Definition at line 233 of file mathutils.c.

References _fvec_t::data, and _fvec_t::length.

  smpl_t * medar = (smpl_t *)tmpvec->data[0];
  uint_t k;
  uint_t win_length =  post+pre+1;
  uint_t length =  vec->length;
  /* post part of the buffer does not exist */
  if (pos<post+1) {
    for (k=0;k<post+1-pos;k++) 
      medar[k] = 0.; /* 0-padding at the beginning */
    for (k=post+1-pos;k<win_length;k++)
      medar[k] = vec->data[0][k+pos-post];
  /* the buffer is fully defined */
  } else if (pos+pre<length) {
    for (k=0;k<win_length;k++)
      medar[k] = vec->data[0][k+pos-post];
  /* pre part of the buffer does not exist */
  } else {
    for (k=0;k<length-pos+post+1;k++)
      medar[k] = vec->data[0][k+pos-post];
    for (k=length-pos+post+1;k<win_length;k++) 
      medar[k] = 0.; /* 0-padding at the end */
  return vec_median(tmpvec);

Generated by  Doxygen 1.6.0   Back to index