@@ -39,13 +39,17 @@ def __init__(self, **kwargs):
39
39
def draw (self ):
40
40
plt .title (self .name )
41
41
plt .plot (self .points [0 ], self .points [1 ])
42
- plt .xlabel ('Rate ' )
42
+ plt .xlabel ('Time (s) ' )
43
43
plt .ylabel ('Amplitude' )
44
+ plt .savefig ('{}' .format (self .name ))
45
+ plt .grid (True )
44
46
plt .show ()
45
47
46
48
def draw_phase (self ):
47
49
plt .title (self .name + 'Phase spectrum' )
48
50
plt .phase_spectrum (self .points [1 ])
51
+ plt .savefig ('{} Phase spectrum' .format (self .name ))
52
+ plt .grid (True )
49
53
plt .show ()
50
54
51
55
def __str__ (self ):
@@ -97,7 +101,7 @@ def get_fft(self):
97
101
return self .fft
98
102
99
103
def get_energy (self ):
100
- return np .sum ((np .abs (self .data ) ** 2 ) / (self .sample_rate ** - 1 ) )
104
+ return np .sum ((np .abs (self .data ) ** 2 )) / len (self .data )
101
105
102
106
def get_duration (self ):
103
107
return len (self .data ) / float (self .sample_rate )
@@ -119,20 +123,23 @@ def when_max(self):
119
123
return when
120
124
121
125
def shift_right (self , slc ):
126
+ if slc < 0 :
127
+ return self .shift_left (abs (slc ))
122
128
amount = int (slc * self .sample_rate )
123
129
filename = path .join (mkdtemp (), 'newfile.dat' )
124
- fpath = np .memmap (filename , dtype = 'int16 ' , mode = 'w+' , shape = amount + len (self .data ))
125
- fpath [amount :: ] = self .data
130
+ fpath = np .memmap (filename , dtype = 'float64 ' , mode = 'w+' , shape = len (self .data ))
131
+ fpath [amount :] = self .data [: - amount ]
126
132
logging .info ('{} {} shifted right' .format (self .name , amount ))
127
133
return Noise (name = '{} time shifted right {}' .format (amount , self .name ),
128
134
data = fpath , path = '' )
129
135
130
- # Todo: check this function
131
136
def shift_left (self , slc ):
137
+ if slc < 0 :
138
+ return self .shift_right (abs (slc ))
132
139
amount = int (slc * self .sample_rate )
133
140
filename = path .join (mkdtemp (), 'newfile.dat' )
134
- fpath = np .memmap (filename , dtype = 'int16 ' , mode = 'w+' , shape = amount + len (self .data ))
135
- fpath [:: len ( self . data ) ] = self .data
141
+ fpath = np .memmap (filename , dtype = 'float64 ' , mode = 'w+' , shape = len (self .data ))
142
+ fpath [:- amount ] = self .data [ amount :]
136
143
logging .info ('{} {} shifted left' .format (self .name , amount ))
137
144
return Noise (name = '{} time shifted left {}' .format (amount , self .name ),
138
145
data = fpath , path = '' )
0 commit comments