/
SmoothAbs.m
36 lines (34 loc) · 1.17 KB
/
SmoothAbs.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function lxl = SmoothAbs(x,alpha,mLow,mUpp)
%
%lXl = SmoothAbs(x,alpha)
%lxl = SmoothAbs(x,alpha,mLow,mUpp)
%
%This function is a smooth version of absolute value. There are two
%versions of the function. If called with two arguments it will use
%hyperbolic tangent smoothing, and if called with 4 arguments it will use a
%fancy smoothing that allows for the slope to be adjusted on each side.
%
%INPUTS:
% x = a vector of inputs to smooth
% alpha = smoothing parameter, alpha > 0.
% Small alpha (1e-4) => no smoothing
% large alpha (1e-1) => heavy smoothing
% (alpha sample values assumes x on the order of 1)
% mLow = the slope of the I/O asymtote for positive x - default 1
% mUpp = the slope of the I/O asymtote for negative x - default 1
%
%OUTPUTS:
% lxl = the smooth version of x
%
switch nargin
case 2
lxl = x.*tanh(x/alpha);
case 4
lxl = alpha*(...
mLow*log(exp(-x/alpha)+1)+... %x>0 part
mUpp*log(exp(x/alpha)+1)... %x<0 part
);
otherwise
error('SmoothAbs must be called with either 2 or 4 arguments.');
end
end