-
Notifications
You must be signed in to change notification settings - Fork 2
/
filtic_test.go
69 lines (63 loc) · 1.61 KB
/
filtic_test.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package gdsp
import (
"fmt"
"math"
"testing"
)
func TestFilticLowPass1(t *testing.T) {
b := MakeVectorFromArray([]float64{0.25, 0.25})
a := MakeVectorFromArray([]float64{1.0, -0.5})
zfRef := 0.75
zf := Filtic(b, a, []float64{1.0}, []float64{1.0})
if zf[0] != zfRef {
t.FailNow()
}
}
func TestFilticLowPass2(t *testing.T) {
b := MakeVectorFromArray([]float64{0.25, 0.25})
a := MakeVectorFromArray([]float64{1.0, -0.5})
zfRef := 0.5
zf := Filtic(b, a, []float64{1.0}, nil)
if zf[0] != zfRef {
t.FailNow()
}
}
func TestFilticHighPass1(t *testing.T) {
b := MakeVectorFromArray([]float64{0.25, -0.25})
a := MakeVectorFromArray([]float64{1.0, 0.5})
zfRef := -0.25
zf := Filtic(b, a, []float64{0.0}, []float64{1.0})
if zf[0] != zfRef {
t.FailNow()
}
}
func TestFilticHighPass2(t *testing.T) {
b := MakeVectorFromArray([]float64{0.25, -0.25})
a := MakeVectorFromArray([]float64{1.0, 0.5})
zfRef := 0.0
zf := Filtic(b, a, []float64{0.0}, nil)
if zf[0] != zfRef {
t.FailNow()
}
}
func TestFiltic(t *testing.T) {
b := MakeVectorFromArray([]float64{0.25, -0.25, 0.15, -0.12, 0.2, 0.2})
a := MakeVectorFromArray([]float64{1.0, 0.5, 0.3, 0.1, 0.2, 0.3})
zf := Filtic(b, a, []float64{1.0, 0.2, 0.7}, []float64{1.0, 2.0, 3.0})
fmt.Printf("%v\n", zf)
if math.Abs(zf[0] - -0.94) > 0.000001 {
t.Errorf("Error 0 %f", zf[0])
}
if math.Abs(zf[1]-0.05) > 0.000001 {
t.Errorf("Error 1 %f", zf[1])
}
if math.Abs(zf[2]-0.53) > 0.000001 {
t.Errorf("Error 2 %f", zf[2])
}
if math.Abs(zf[3]-0.34) > 0.000001 {
t.Errorf("Error 3 %f", zf[3])
}
if math.Abs(zf[4] - -0.1) > 0.000001 {
t.Errorf("Error 4 %f", zf[4])
}
}