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
Ejemplo n.º 3
0
    def init_run(self, cur_run):
        """Set signals for reference and pauses between them."""

        ramp_dur_htc = 0.05
        cur_run.reference_signal = htc(75, cur_run.sample_rate, 0.32,
                                      cur_run.signal_freq/10,
                                      0.4*cur_run.signal_freq,
                                      1.6*cur_run.signal_freq,
                                       cur_run.C, cur_run.calib)
        cur_run.reference_signal = hanwin(cur_run.reference_signal,
                                          np.round(ramp_dur_htc*
                                                   cur_run.sample_rate))
Ejemplo n.º 4
0
    def init_trial(self, trial):
        """Set signal for variable."""

        sine_dur = 0.26
        ramp_dur_sine = 0.03
        ampl = np.sqrt(2)*10**((trial.variable-trial.calib)/20)
        start_phase = np.random.randint(0, 361)
        test_tone = gensin(trial.signal_freq, ampl, sine_dur, start_phase,
                           trial.sample_rate)
        test_tone = hanwin(test_tone,
                           np.round(ramp_dur_sine*trial.sample_rate))
        trial.test_signal = trial.reference_signal.copy()
        start_sample = np.round((len(trial.reference_signal)-len(test_tone))/2)
        trial.test_signal[start_sample:start_sample+len(test_tone)] += test_tone
Ejemplo n.º 5
0
    def init_experiment(self, exp):
        exp.add_parameter("frequency",[100, 200, 500, 1000, 2000, 4000], "Hz")
        exp.set_variable("gain", -30, "dB")
        exp.add_adapt_setting("1up2down", 3, 8, 1)
        exp.task = "loudness of the noise should go (u)p/(d)own? "
        exp.debug = False
        exp.discard_unfinished_runs = False
        exp.description = """This is the description of matching experiment"""

        ref = gensin(1000, 1, 0.6, 0, exp.sample_rate)
        srms = rms(ref)
        exp.reference_signal = ref/srms*10**(-30/20)
        exp.reference_signal = hanwin(exp.reference_signal, 0.05)
        exp.pre_signal = 0.1
        exp.between_signal = 0.2
        exp.post_signal = 0.3