Adelsbach/VSIPL
Core Programming Reference Guide
DD-00016-015
Core

This manual is preliminary and incomplete.
While our Core implementation implements all functions given in the standard we are still working on completing this documentation.

Please refer to the VSIPL standard for a complete function reference of the Core profile until we have completed work on this documentation.

4.6.1 vsip_vclip_p - Clip Vector Elements Between Thresholds

void vsip_vclip_i(const vsip_vview_i *a, vsip_scalar_i t1, vsip_scalar_i t2, 
                 vsip_scalar_i c1, vsip_scalar_i c2, const vsip_vview_i *r); 
void vsip_vclip_f(const vsip_vview_f *a, vsip_scalar_f t1, vsip_scalar_f t2, 
                  vsip_scalar_f c1, vsip_scalar_f c2, const vsip_vview_f *r);
Description

This function clips the elements of a vector between specified thresholds, replacing values outside the threshold range with corresponding clip values. The clipping operation is defined as:

   ꎧ
   || c1 ifai< t1
ri=  ai ift1≤ ai≤t2
   |⎩
     c2 ifai> t2

for all i from 0 to n-1, where n is the length of the vectors.

Parameters
Example

vsip_vview_f *signal, *clipped_signal; 
vsip_length n = 1024; 
 
// Create vectors 
signal = vsip_vcreate_f(n, VSIP_MEM_NONE); 
clipped_signal = vsip_vcreate_f(n, VSIP_MEM_NONE); 
 
// Initialize signal with some values (e.g., sine wave with noise) 
for (vsip_length i = 0; i < n; i++) { 
    float val = 10.0f * sin(2 * M_PI * i / n) + 5.0f * ((float)rand()/RAND_MAX - 0.5f); 
    vsip_vput_f(signal, i, val); 
} 
 
// Clip the signal between -5.0 and 5.0, replacing outliers with these bounds 
vsip_vclip_f(signal, -5.0f, 5.0f, -5.0f, 5.0f, clipped_signal); 
 
// The clipped_signal vector now contains the original values where they were 
// within [-5.0, 5.0], and -5.0 or 5.0 where they were outside this range 
 
// Clean up 
vsip_valldestroy_f(signal); 
vsip_valldestroy_f(clipped_signal);
Notes