Skip to content

Instantly share code, notes, and snippets.

@jpcima
Last active January 4, 2020 15:23
Show Gist options
  • Save jpcima/f647105ea46360122c661fd6e46f1e91 to your computer and use it in GitHub Desktop.
Save jpcima/f647105ea46360122c661fd6e46f1e91 to your computer and use it in GitHub Desktop.
Asymmetric soft clipper with parameter
# license CC0-1.0 or MIT
cubic(x)=(x*x*x/3)
lm(k)=-sqrt(k*k*k)/(k*k*k) # the local minimum
kubic(k,x)=x-cubic(k*x)
max(a,b)=(a>b)?a:b
nl(k,x)=(x>0)?x:kubic(k,max(x,lm(k)))
set xrange [-1:+1]
plot nl(1.0,x), nl(1.25,x), nl(1.5,x), nl(1.75,x), nl(2.0,x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment