This repository has been archived by the owner on Aug 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
waveform.py
182 lines (146 loc) · 5.85 KB
/
waveform.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# -*- coding: utf-8 -*-
from math import pi, sqrt
import numpy as np
__all__ = [
'ACV_A1',
'ACV_A2',
'ACV_A3',
'ACV_A4',
'ACV_A5',
'ACV_A6',
'ACV_A7',
'ACV_A8'
]
# Heavy-side step function
H_num = lambda t: 1 if t > 0 else 0
H = lambda T: np.asarray([1 if t > 0 else 0 for t in T])
# pure sine
def ACV_A1(T, Hz=50):
"""
Generate a pure sine wave at a specified frequency
keyword arguments:
T -- time points to generate the waveform given in seconds
Hz -- The desired frequency of the signal (default:50)
"""
ampl = 1000
T = np.asarray(T, dtype=np.float64)
return ampl * sqrt(2) * np.sin(2*pi*Hz * T)
def ACV_A2(T, Hz=50):
"""
Generate a pure sine wave with a DC offset at a specified frequency
keyword arguments:
T -- time points to generate the waveform given in seconds
Hz -- The desired frequency of the signal (default:50)
"""
ampl = 1000
offset = 500
T = np.asarray(T, dtype=np.float64)
return ampl * sqrt(2) * np.sin(2*pi*Hz * T) + offset
def ACV_A3(T, Hz=50):
"""
Generate a fundamental with a 3rd overtone
keyword arguments:
T -- time points to generate the waveform given in seconds
Hz -- The desired frequency of the signal (default:50)
"""
ampl = 1000
T = np.asarray(T, dtype=np.float64)
main_wave = np.sin(2*pi*Hz * T)
harmonic_wave = 0.05 * np.sin(2*pi*Hz * T * 4 + pi * 2 / 3)
return ampl * sqrt(2) * (main_wave + harmonic_wave)
def ACV_A4(T, Hz=50):
"""
Generate a fundamental with a 4th overtone
keyword arguments:
T -- time points to generate the waveform given in seconds
Hz -- The desired frequency of the signal (default:50)
"""
ampl = 1000
T = np.asarray(T, dtype=np.float64)
main_wave = np.sin(2*pi*Hz * T)
harmonic_wave = 0.07 * np.sin(2*pi*Hz * T * 5 + pi * 22 / 18)
return ampl * sqrt(2) * (main_wave + harmonic_wave)
def ACV_A5(T, Hz=50):
"""
Generate a realistic triangle wave
keyword arguments:
T -- time points to generate the waveform given in seconds
Hz -- The desired frequency of the signal (default:50)
"""
ampl = 1000
T = np.asarray(T, dtype=np.float64)
wave_1 = np.sin(2*pi*Hz * T)
wave_2 = 0.05 * np.sin(2*pi*Hz * T * 3 - pi)
wave_3 = 0.05 * np.sin(2*pi*Hz * T * 5)
wave_4 = 0.02 * np.sin(2*pi*Hz * T * 7 - pi)
wave_5 = 0.01 * np.sin(2*pi*Hz * T * 9)
return ampl * sqrt(2) * (wave_1 + wave_2 + wave_3 + wave_4 + wave_5)
def ACV_A6(T, Hz=50):
"""
Generate a realistic triangle wave
keyword arguments:
T -- time points to generate the waveform given in seconds
Hz -- The desired frequency of the signal (default:50)
"""
ampl = 1000
T = np.asarray(T, dtype=np.float64)
wave_1 = np.sin(2*pi*Hz * T)
wave_2 = 0.02 * np.sin(2*pi*Hz * T * 3 - pi)
wave_3 = 0.02 * np.sin(2*pi*Hz * T * 5)
wave_4 = 0.0015 * np.sin(2*pi*Hz * T * 7 - pi)
wave_5 = 0.009 * np.sin(2*pi*Hz * T * 9)
return ampl * sqrt(2) * (wave_1 + wave_2 + wave_3 + wave_4 + wave_5)
def ACV_A7(T, Hz=50):
"""
Generate a growing sine wave, where the wave starts at 0 and reaches 0.9 of
full amplitude at 250 cycles. Thereafter it will linearly increase to full
amplitude at 500 cycles and terminate to 0
Frequency locked to 50Hz and = 0 at t>10
keyword arguments:
T -- time points to generate the waveform given in seconds
Hz -- The desired frequency of the signal (default:50)
"""
ampl = 1000
Hz = 50
T = np.asarray(T, dtype=np.float64)
wave_main = np.sin(2*pi*Hz * T)
step_func = (0.9 * T / 5 * H(5-T) + H(T-5) * H(10-T) * (0.9 + 0.1 * (T-5) / 5))
return ampl * sqrt(2) * wave_main * step_func
def ACV_A8(T, Hz=50):
"""
Generate a growing sine wave, which reaches 100 times the amplitude at
500 cycles
frequency not implemented and signal = 0 at t>1000*pi
signal frequency = 0.15915494309189535 Hz?
keyword arguments:
T -- time points to generate the waveform given in seconds
Hz -- The desired frequency of the signal (default:50)
"""
ampl = 1000
Hz = 50
T = np.asarray(T, dtype=np.float64)
wave_main = np.sin(T)
step_func = T / (10 * pi) * H(10 - T / (2*pi*Hz))
return ampl * sqrt(2) * wave_main * step_func
_ACV_A1_L = lambda T, Hz = 50: 1000 * sqrt(2) * np.sin(2*pi*Hz * T)
_ACV_A2_L = lambda T, Hz = 50: 1000 * sqrt(2) * np.sin(2*pi*Hz * T) + 500
_ACV_A3_L = lambda T, Hz = 50: 1000 * sqrt(2) * (np.sin(2*pi*Hz * T) +
0.05 * np.sin(2*pi*Hz * T * 4 + pi * 2 / 3))
_ACV_A4_L = lambda T, Hz = 50:( 1000 * sqrt(2) * (np.sin(2*pi*Hz * T) +
0.07 * np.sin(2*pi*Hz * T * 5 + pi * 22 / 18)))
# Realistic triangle
_ACV_A5_L = lambda T, Hz = 50:( 1000 * sqrt(2) * (np.sin(2*pi*Hz * T) +
0.05 * np.sin(2*pi*Hz * T * 3 - pi) +
0.05 * np.sin(2*pi*Hz * T * 5) +
0.02 * np.sin(2*pi*Hz * T * 7 - pi) +
0.01 * np.sin(2*pi*Hz * T * 9)))
_ACV_A6_L = lambda T, Hz = 50:( 1000 * sqrt(2) * (np.sin(2*pi*Hz * T) +
0.02 * np.sin(2*pi*Hz * T * 3 - pi) +
0.02 * np.sin(2*pi*Hz * T * 5) +
0.0015 * np.sin(2*pi*Hz * T * 7 - pi) +
0.009 * np.sin(2*pi*Hz * T * 9)))
# A7 & A8 convert so that a input of 16*pi corresponds to a input 0.25 in the current version
_ACV_A7_OLD = lambda T: [1000 * sqrt(2) * np.sin(100 * pi * t) *
(0.9 * t / 5 * H_num(5-t) + H_num(t-5) * H_num(10-t) * (0.9 + 0.1 * (t-5) / 5)) for t in T]
_ACV_A8_OLD = lambda T: [1000 * sqrt(2) * np.sin(t) *
t / (10 * pi) * H_num(10 - t / (100 * pi)) for t in T]