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 ()
0 commit comments