Sha256: f20d8be9d27a9f37d306796b575457427e478e816375ee1d68c9fff79f41453f
Contents?: true
Size: 941 Bytes
Versions: 9
Compression:
Stored size: 941 Bytes
Contents
module SPCore # Provide simple saturation methods, that limit input above the given threshold value. class Saturation # Sigmoid-based saturation when input is above threshold. # From musicdsp.org, posted by Bram. def self.sigmoid input, threshold input_abs = input.abs if input_abs < threshold return input else #y = threshold + (1.0 - threshold) * mock_sigmoid((input_abs - threshold) / ((1.0 - threshold) * 1.5)) y = threshold + (1.0 - threshold) * Math::tanh((input_abs - threshold)/(1-threshold)) if input > 0.0 return y else return -y end end end # A Gompertz-sigmoid-based saturation when input is above threshold. def self.gompertz input, threshold a = threshold b = -4 c = -2 x = input.abs y = 2 * a * Math::exp(b * Math::exp(c * x)) if input > 0.0 return y else return -y end end end end
Version data entries
9 entries across 9 versions & 1 rubygems