def _get_time(self): if not self._time_valid: log.debug('recomputing _time') duration = self.get_current_value('trial_duration') self._time = wave.time(self.iface_behavior.fs, duration) self._time_valid = True return self._time
def generate_trial_waveform(self): # Use BBN seed = self.get_current_value("seed") depth = self.get_current_value("modulation_depth") direction = self.get_current_value("modulation_direction") fm = self.get_current_value("fm") duration = self.get_current_value("trial_duration") t = signal.time(self.iface_behavior.fs, duration) # Save the actual seed that's used to generate the trial waveform if seed == -1: seed = int(time.time()) self.set_current_value("seed", seed) # Do not use the self.random_generator for generating the seed. This # generator is for use only for generating the intertrial waveform. state = np.random.RandomState(seed) waveform = state.uniform(low=-1, high=1, size=len(t)) # Since we are drawing samples from a uniform distribution and we wish # to normalize for the RMS voltage, we need to divide by 0.5 which is # the RMS value of the waveform. We could recompute the RMS value on # each cycle; however, I think it's better to use the same value each # time. The RMS of the waveform over time will compute to 0.5 (because # the samples are unformly distributed between -1 and 1). waveform = waveform / 0.5 eq_phase = signal.sam_eq_phase(depth, direction) eq_power = signal.sam_eq_power(depth) envelope = depth / 2.0 * np.cos(2 * np.pi * fm * t + eq_phase) + 1 - depth / 2.0 envelope *= 1 / eq_power return waveform * envelope