Last active
July 8, 2019 19:06
-
-
Save catfact/5ab4589156432c09a2cf9154b5368b9a to your computer and use it in GitHub Desktop.
tanc clipper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function y = tanc(x, a) | |
| g = 1 - a; | |
| y = 1 - g * (1 - tanhx((x - a) / g)); | |
| endfunction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % positive softclipper using "tanc" shaper | |
| % t = limit threshold | |
| % w = limit knee width | |
| function y = tanc_softclip_pos(x, t, w) | |
| a = 1/w; | |
| lim = x/t; | |
| if lim > a | |
| y = lim; | |
| else | |
| y = tanc(a, min(max(lim, 0), 10)); | |
| endif | |
| endfunction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| n = 64; | |
| x = linspace(-1, 1, n); | |
| t = 0.5; | |
| w = 0.2; | |
| y = zeros(n); | |
| for i=1:n | |
| if x(i) < 0 | |
| y(i) = tanc_softclip_pos(x(i)*-1, t, w) * -1; | |
| else | |
| y(i) = tanc_softclip_pos(x(i), t, w); | |
| endif | |
| endfor | |
| plot(x, y); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % tanh approximation | |
| function y = tanhx(x) | |
| y = (1-exp(-2*x))/(1+exp(-2*x)); | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
adapted from this faust code:
but i've missed or misinterpreted something.
soft_clip_positiveoutputs a ratio of input to limit threshold, which should probably be rescaled?currently outputs the following transfer func with
lim_thresh= 0.5,lim_knee_width=0.2(i may also be totally mis-estimating the correct range of these parameters)