Skip to content

Commit 6a40070

Browse files
committed
added code and screenshots regarding signal approximation
1 parent 7d519be commit 6a40070

File tree

9 files changed

+107
-0
lines changed

9 files changed

+107
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*~
2+
.~lock*
23
*.pyc
34
__pycache__/
45
venv/
Lines changed: 49 additions & 0 deletions
Loading
8.69 KB
Binary file not shown.
15 KB
Binary file not shown.
159 KB
Loading
280 KB
Loading
438 KB
Loading
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# 2*pi is one period use degrees internally
2+
# signal is 9+3
3+
4+
#https://people.cs.clemson.edu/~dhouse/courses/405/notes/splines.pdf
5+
#https://www.youtube.com/watch?v=bn8iJKFldq0
6+
7+
#python -m venv venv
8+
#pip install scipy
9+
#pip install matplotlib
10+
11+
#def signal_degree(x):
12+
# return x % 360
13+
14+
#print(signal_degree(30.1))
15+
#print(signal_degree(30.1+360))
16+
17+
18+
#https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.BPoly.from_derivatives.html
19+
#https://docs.scipy.org/doc/scipy/tutorial/interpolate.html
20+
21+
from scipy.interpolate import BPoly
22+
#function1 = BPoly.from_derivatives([0, 1, 30], [[0,0],[1,0],[-1,1]])
23+
#function2 = BPoly.from_derivatives([0, 1, 30], [[0,0],[1,0],[-1,1]], orders=1)
24+
#print(function1(1))
25+
26+
#0,3.75,7.5,11.25,15,18.75,22.5,26.25
27+
#[0,0],[0,0],[0,0.02],[1,0],[0,-2.6],[-1,0],[0,0.02],[0,0]
28+
29+
#function1 = BPoly.from_derivatives(x, y, orders=1)
30+
#function2 = BPoly.from_derivatives([0,3.75,7.5,11.25,15,18.75,22.5,26.25], [[0,0],[0,0],[0,0.02],[1,0],[0,-0.6],[-1,0],[0,0.02],[0,0]])
31+
32+
33+
34+
35+
import matplotlib.pyplot as plt
36+
import numpy as np
37+
38+
x = [e/100 for e in range(0,36000, 375)]
39+
x2 = [e/1000 for e in range(0,360000, 375)]
40+
y = [0,0,0,1,0,-1,0,0]*9+[0,0,0,0,0,0,0,0]*3
41+
fp = [[0,0],[0,0],[0,0],[1,0],[0,0],[-1,0],[0,0],[0,0]]*9+[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]*3
42+
gp = [[0,0],[0,0],[0,0.02],[1,0],[0,-0.6],[-1,0],[0,0.02],[0,0]]*9+[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]*3
43+
hp = [[0,0],[0,0],[0.05,0.02],[1,0],[0,-0.6],[-1,0],[-0.05,0.02],[0,0]]*9+[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]*3
44+
45+
f = BPoly.from_derivatives(x, fp, orders=1)
46+
g = BPoly.from_derivatives(x, gp)
47+
h = BPoly.from_derivatives(x, hp)
48+
49+
#x = [0,3.75,7.5,11.25,15,18.75,22.5,26.25]
50+
#y = [0,0,0,1,0,-1,0,0]
51+
#y1 = [function1(e) for e in x]
52+
#y2 = [function2(e) for e in x]
53+
#plt.plot(x, y, 'o', y2)
54+
#plt.legend(['data', 'linear', 'cubic'], loc='best')
55+
plt.plot(x, y, 'bo', x, [f(e) for e in x], 'g--', x2, [g(e) for e in x2], 'r', x2, [h(e) for e in x2], 'b')
56+
plt.axis([0,360, -1.25, 1.25])
57+
plt.show()
1.17 MB
Binary file not shown.

0 commit comments

Comments
 (0)