-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignalplotter.py
More file actions
43 lines (32 loc) · 1.19 KB
/
signalplotter.py
File metadata and controls
43 lines (32 loc) · 1.19 KB
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
import numpy as np
import matplotlib.pyplot as plt
class SignalPlotter:
def __init__(self,timeStep,timeMax):
"""
timeStep : the step for time Axis from second
timeMax : the max time in the time Axis in same scale
"""
self.time = []
self.amp = []
self.timeStep = timeStep
self.timeMax = timeMax
self.numberOfSteps = timeMax/timeStep
plt.plot(self.time,self.amp)
plt.ion()
self.time.append(0) #the base to increment over it
#manages signal relative to time
def __manageSignal(self):
if len(self.amp) > self.numberOfSteps:
del self.amp[0] #shift signal by deleting the first element
if len(self.time) != self.numberOfSteps:
while len(self.time) < len(self.amp) :
self.time.append(self.time[-1]+self.timeStep)
def addAmp(self,amp):
self.amp = list(amp)
self.__manageSignal()
def draw(self):
plt.gca().lines[0].set_xdata(self.time);
plt.gca().lines[0].set_ydata(self.amp);
plt.gca().relim();
plt.gca().autoscale_view();
plt.pause(self.timeStep)