Spectrogram complex phase
When creating a MagSpectrogram
object from a wav file or a Waveform
object, the user can now use the compute_phase
argument to specify that the complex phase angle should be computed and stored along with the magnitude spectrogram.
The complex phase angle is a 2d numpy array with precisely the same shape as the magnitude spectrogram. Therefore, to ensure that cropping and segmentation operations are applied equally to both arrays, we store the complex phase angle along with the magnitude spectrogram, as follows,
self.data = np.stack([self.data, phase_angle], axis=2)
Moreover, we add the following two methods to the MagSpectrogram
class,
def get_data(self):
""" Get magnitude spectrogram data """
if np.ndim(self.data) == 3: return self.data[:,:,0]
else: return super().get_data()
def get_phase_angle(self):
""" Get magnitude spectrogram complex phase angle, if available """
if np.ndim(self.data) == 3: return self.data[:,:,1]
else: return None
The get_data
method overwrites the corresponding method from the BaseAudio
class.