Example #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))
Example #2
0
 def init_run(self, cur_run):
     """Set signals for reference and pauses between them."""
     print(self.parameters['frequency']['values'][0])
     ref = gensin(self.parameters['frequency']['values'][0],1,1,0,cur_run.sample_rate)
     rms = np.sqrt(np.mean(np.square(ref)))
     cur_run.reference_signal = ref/rms*10**(-30/20)
     cur_run.pre_signal = np.zeros(0.5*cur_run.sample_rate)
     cur_run.between_signal = cur_run.pre_signal
     cur_run.post_signal = cur_run.pre_signal
     return cur_run
Example #3
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
Example #4
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
Example #5
0
 def init_trial(self, trial):
     ampl = np.sqrt(2)*10**(trial.variable/20)
     test = gensin(1600, ampl, 0.03, trial.sample_rate)
     pos = np.round((len(trial.reference_signal) - len(test))/2)
     trial.test_signal = trial.reference_signal.copy()
     trial.test_signal[pos:pos+len(test)] += test
Example #6
0
 def init_trial(self, trial):
     """Set signal for variable."""
     gain = 2**0.5*10**(trial.variable/20)
     trial.test_signal = gensin(trial.frequency,gain,1,0,trial.sample_rate)
     return trial