def shift(self, shift_idx): """-------------------------------------------------------------------- Shifts the distribution by the given number of samples ----------------------------------------------------------------------- shift_idx : The number of samples that the distribution is to be shifted --------------------------------------------------------------------""" # Shift only if the index is non-zero and the distribution is in # cent units if shift_idx and self.has_cent_bin(): # update reference frequency self.ref_freq = Converter.cent_to_hz( self.bins[shift_idx] - self.bins[0], ref_freq=self.ref_freq) # If distribution is a PCD, we do a circular shift if self.is_pcd(): self.vals = np.concatenate((self.vals[shift_idx:], self.vals[:shift_idx])) else: # If distribution is a PD, shift the bins. self.bins -= self.step_size * shift_idx
def cent_to_hz(self): if self.has_cent_bin(): self.bins = Converter.cent_to_hz(self.bins, self.ref_freq) self.ref_freq = None else: raise ValueError('The bin unit should be "cent".')