Sha256: c97be401ff70945491c776d62d23661cebad49df3fa17b7130dbb7f6b2842cf5
Contents?: true
Size: 968 Bytes
Versions: 9
Compression:
Stored size: 968 Bytes
Contents
module SPCore # Implement a "cookbook" bandpass filter using the BiquadFilter class, # based on the well-known RBJ biquad filter. class CookbookBandpassFilter < BiquadFilter def initialize sample_rate super(sample_rate) end def set_critical_freq_and_bw critical_freq, bandwidth @critical_freq = critical_freq @bandwidth = bandwidth # setup variables omega = 2.0 * Math::PI * @critical_freq / @sample_rate sn = Math::sin(omega) cs = Math::cos(omega) alpha = sn * Math::sinh(BiquadFilter::LN_2 / 2.0 * @bandwidth * omega / sn) b0 = alpha b1 = 0.0 b2 = -alpha a0 = 1.0 + alpha a1 = -2.0 * cs a2 = 1.0 - alpha # precompute the coefficients @biquad.b0 = b0 / a0 @biquad.b1 = b1 / a0 @biquad.b2 = b2 / a0 @biquad.a0 = a0 / a0 @biquad.a1 = a1 / a0 @biquad.a2 = a2 / a0 ## zero initial samples #@biquad.x1 = @biquad.x2 = 0 #@biquad.y1 = @biquad.y2 = 0 end end end
Version data entries
9 entries across 9 versions & 1 rubygems