-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignals.py
More file actions
74 lines (45 loc) · 1.62 KB
/
Signals.py
File metadata and controls
74 lines (45 loc) · 1.62 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
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
'''
* Signals.py
*
* Created on: 16.05.2018
* Last modified:
* Author: Andrew Jason Bishop
*
* Signal class is a combination of samples and time line for
* time discrete signals. The constructor method generates the
* time line by giving the sample rate. It is based on numpy.
*
* SignalPlotter class simplifies plotting Signal instances by
* virtue of the pyplot.subplot2grid() method. It also takes a
* keyword dictionary for parameters like colspan, markers, etc.
*
'''
import matplotlib.pyplot as plt
import numpy as np
class Signal:
def __init__(self, _samples, _fs):
self.samples = _samples
self.sampleRate = _fs
self.number_of_samples = _samples.size
self.addTimeLine()
def addTimeLine(self):
samplingInterval = 1.0/self.sampleRate
end = samplingInterval * self.number_of_samples
self.timeLine = np.arange(0, end, samplingInterval)
def getMaxTime(self):
index_of_last_sample = self.number_of_samples - 1
return self.timeLine[index_of_last_sample]
class SignalPlotter:
def __init__(self, _dimensions):
self.gridDimensions = _dimensions
def plotSignal(self, _signal, _coords, _kwargs={}):
ax = self.makeAxes(_coords, _kwargs)
artists = self.plotToAxes(_signal, ax)
return artists
def makeAxes(self, _coords, _kwargs):
ax = plt.subplot2grid( self.gridDimensions, _coords, **_kwargs)
return ax
def plotToAxes(self, _signal, _ax):
artists = _ax.plot(_signal.timeLine, _signal.samples)
return artists
'''EOF'''