# Clipping Complex Samples to +/- 1.0?

**URL:** <https://www.ruby-forum.com/t/clipping-complex-samples-to-1-0/241426>\
**Category:** GNU Radio\
**Created:** [April 7, 2015, 2:27am UTC](https://www.ruby-forum.com/t/clipping-complex-samples-to-1-0/241426 "2015-04-07T02:27:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [April 7, 2015, 2:27am UTC](https://www.ruby-forum.com/t/clipping-complex-samples-to-1-0/241426/1 "2015-04-07T02:27:06Z")

</div>

This may be more of a general C++ question than a GNU Radio question…  
Is  
there any super convenient and fast way to clip a complex signal to +/-  
1.0  
on both I & Q?

Something other than splitting them up into floats and using  
branchless\_clip or if statements?

-John

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [April 7, 2015, 3:12pm UTC](https://www.ruby-forum.com/t/clipping-complex-samples-to-1-0/241426/2 "2015-04-07T15:12:23Z")

</div>

Hi John - There aren’t a lot of choices to do clipping; this is  
basically:

{{{  
float\* in = (float\*) INPUT;  
float\* out = (float\*) OUTPUT;  
for(int nn=0; nn\<NUMBER; ++nn) {  
\*out++ = std::max(std::min(\*in++, 1.0),-1.0);  
}  
}}}

You could use Volk’s “volk\_32f\_x2\_max\_32f” and “volk\_32f\_x2\_min\_32f”  
kernel \< [Vector Optimized Library of Kernels: $title](http://libvolk.org/doxygen/volk_32f_x2_max_32f.html) \> & \<  
[Vector Optimized Library of Kernels: $title](http://libvolk.org/doxygen/volk_32f_x2_min_32f.html) \>, which would  
auto-magically handle the whole loop for you.

Maybe someone else can come up with a good reference for a branchless  
version of this? Hope this helps! - MLD
