-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrequency.go
69 lines (58 loc) · 1.03 KB
/
frequency.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 gorf
import (
"math"
"strings"
"github.com/whipstein/golinalg/mat"
)
type FreqUnit int
const (
Hz FreqUnit = iota
KHz = 1e3
MHz = 1e6
GHz = 1e9
THz = 1e12
)
type Sweep int
const (
Lin Sweep = iota
Log
)
type Frequency struct {
Start float64
Stop float64
NPts int
Unit FreqUnit
SweepType Sweep
Freq *mat.Vector
FreqScaled *mat.Vector
W *mat.Vector
}
func NewFrequency() *Frequency {
return &Frequency{Freq: vf(0), FreqScaled: vf(0), W: vf(0)}
}
func (f *Frequency) Setup(unit string) *Frequency {
switch strings.ToLower(unit) {
case "hz":
f.Unit = Hz
case "khz":
f.Unit = KHz
case "mhz":
f.Unit = MHz
case "ghz":
f.Unit = GHz
default:
panic("frequency unit not recognized")
}
return f
}
func (f *Frequency) Append(x float64) *Frequency {
if len(f.Freq.Data) == 0 {
f.Start = x
}
f.NPts++
f.Stop = x
f.FreqScaled.Append(x)
f.Freq.Append(x * float64(f.Unit))
f.W.Append(x * float64(f.Unit) * 2 * math.Pi)
return f
}