Ejemplo n.º 1
0
    def init_trial(self, trial):
        """Set signal for variable."""

        noise_dur = 0.3         # duration of noise
        pause_dur = 0.03        # pause between noise and sine
        sine_dur = 0.015        # duration of test signal
        ramp_dur = 0.0075       # ramp of hann window

        sine_freq = 1600        # freq of test signal
        noise_freq = 1600       # midfreq of noise
        noise_band_width = 300  # bandwidth of noise

        # trial.test_signal = test_tone (matlab)
        sine_ampl = np.sqrt(2)*10**(trial.variable/20)
        m_test = gensin(sine_freq, sine_ampl, sine_dur, 0,
                                   trial.sample_rate)
        m_test = hanwin(m_test, np.round(
            ramp_dur*trial.sample_rate))

        # generate new instance of running noise
        m_ref = np.random.randn(np.round(noise_dur*trial.sample_rate))
        m_ref = fft_rect_filt(m_ref, noise_freq-noise_band_width/2,
                              noise_freq+noise_band_width/2, trial.sample_rate)

        # adjust its level
        m_ref = m_ref/rms(m_ref)*10**(trial.noise_level/20)
        # apply onset/offset ramps
        m_ref = hanwin(m_ref, np.round(ramp_dur*trial.sample_rate))


        pause_zeros = np.zeros(np.round(pause_dur*trial.sample_rate))
        sine_zeros = np.zeros(np.round(sine_dur*trial.sample_rate))
        trial.reference_signal = np.concatenate((m_ref, pause_zeros, sine_zeros))
        trial.test_signal = np.concatenate((m_ref, pause_zeros, m_test))
Ejemplo n.º 2
0
 def init_trial(self, trial):
     """Set signal for variable."""
     trial.test_signal = np.random.randn(0.6*trial.sample_rate)
     trial.test_signal = fft_rect_filt(trial.test_signal,
                                       trial.frequency-50,
                                       trial.frequency+50,
                                       trial.sample_rate)
     
     trial.test_signal = trial.test_signal/rms(trial.test_signal)*10**(trial.variable/20)
     trial.test_signal = hanwin(trial.test_signal, 0.05)
     return trial