7
"github.com/jfcg/butter"
13
func Butter(RGB []RGB_float64) []RGB_float64 {
16
wc := 2 * math.Pi * dt
29
a, b := wc*1.2, wc*2.5
30
Rfilter := butter.NewBandPass2(a, b)
31
Gfilter := butter.NewBandPass2(a, b)
32
Bfilter := butter.NewBandPass2(a, b)
35
RGB[i].R = Rfilter.Next(RGB[i].R)
36
RGB[i].G = Gfilter.Next(RGB[i].G)
37
RGB[i].B = Bfilter.Next(RGB[i].B)
44
func ButterworthLowpassFilter(signal []float64, sampleRate float64, cutoffFreq float64) ([]float64, error) {
47
nyquistFreq := 0.5 * sampleRate
48
normalCutoff := cutoffFreq / nyquistFreq
51
b, a, err := butterworthLowpass(order, normalCutoff)
57
filteredSignal := make([]float64, len(signal))
58
for i := 0; i < len(signal); i++ {
59
for j := 0; j <= order; j++ {
61
filteredSignal[i] += b[j] * signal[i-j]
64
for j := 1; j <= order; j++ {
66
filteredSignal[i] -= a[j] * filteredSignal[i-j]
71
return filteredSignal, nil
74
func butterworthLowpass(order int, normalCutoff float64) (b, a []float64, err error) {
76
return nil, nil, fmt.Errorf("Порядок фильтра должен быть положительным числом")
78
if normalCutoff <= 0 || normalCutoff >= 1.0 {
79
return nil, nil, fmt.Errorf("Частота среза должна быть между 0 и 1")
83
b, a = make([]float64, order+1), make([]float64, order+1)
84
wc := 2.0 * math.Pi * normalCutoff
87
for i := 0; i < order; i++ {
88
a[i+1] = a[i] * (-wc / float64(i+1))
91
for i := 0; i <= order; i++ {
98
func Butter2(RGB []RGB_float64) []RGB_float64 {
100
RGBsOut := make([]RGB_float64, len(RGB))
101
r := make([]float64, len(RGB))
102
g := make([]float64, len(RGB))
103
b := make([]float64, len(RGB))
109
sampleRate := 1.0 / 30.0
111
r, _ = ButterworthLowpassFilter(r, sampleRate, cutoffFreq)
112
g, _ = ButterworthLowpassFilter(g, sampleRate, cutoffFreq)
113
b, _ = ButterworthLowpassFilter(b, sampleRate, cutoffFreq)