improve internal stimulus handling
This commit is contained in:
parent
251ca4f2ef
commit
af2172c81b
@ -1,8 +1,6 @@
|
|||||||
from stimuli.AbstractStimulus import AbstractStimulus
|
from stimuli.AbstractStimulus import AbstractStimulus
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from numba import jit, njit
|
from numba import jit, njit
|
||||||
import time
|
|
||||||
from warnings import warn
|
|
||||||
|
|
||||||
|
|
||||||
class SinusAmplitudeModulationStimulus(AbstractStimulus):
|
class SinusAmplitudeModulationStimulus(AbstractStimulus):
|
||||||
@ -25,10 +23,10 @@ class SinusAmplitudeModulationStimulus(AbstractStimulus):
|
|||||||
|
|
||||||
return self.amplitude * am * carrier
|
return self.amplitude * am * carrier
|
||||||
|
|
||||||
def get_stimulus_start_ms(self):
|
def get_stimulus_start_s(self):
|
||||||
return self.start_time
|
return self.start_time
|
||||||
|
|
||||||
def get_stimulus_duration_ms(self):
|
def get_stimulus_duration_s(self):
|
||||||
return self.duration
|
return self.duration
|
||||||
|
|
||||||
def get_amplitude(self):
|
def get_amplitude(self):
|
||||||
@ -42,24 +40,25 @@ class SinusAmplitudeModulationStimulus(AbstractStimulus):
|
|||||||
start_time = self.start_time
|
start_time = self.start_time
|
||||||
duration = self.duration
|
duration = self.duration
|
||||||
|
|
||||||
values = convert_to_array(carrier, amp, mod_freq, contrast, start_time, duration, time_start, total_time, step_size)
|
values = convert_to_array(carrier, amp, mod_freq, contrast, start_time, duration, time_start, total_time, step_size/1000)
|
||||||
|
|
||||||
return values
|
return values
|
||||||
|
|
||||||
|
|
||||||
@jit(nopython=True)
|
#@jit(nopython=True) # makes it slower?
|
||||||
def convert_to_array(carrier_freq, amplitude, modulation_freq, contrast, start_time, duration, time_start, total_time, step_size):
|
def convert_to_array(carrier_freq, amplitude, modulation_freq, contrast, start_time, duration, time_start, total_time, step_size_s):
|
||||||
# if the whole stimulus time has the amplitude modulation just built it at once;
|
# if the whole stimulus time has the amplitude modulation just built it at once;
|
||||||
if time_start >= start_time and start_time+duration < time_start+total_time:
|
if time_start >= start_time and start_time+duration < time_start+total_time:
|
||||||
carrier = np.sin(2 * np.pi * carrier_freq * np.arange(start_time, total_time-start_time, step_size/1000))
|
carrier = np.sin(2 * np.pi * carrier_freq * np.arange(start_time, total_time - start_time, step_size_s))
|
||||||
modulation = 1 + contrast * np.sin(2 * np.pi * modulation_freq * np.arange(start_time, total_time-start_time, step_size/1000))
|
modulation = 1 + contrast * np.sin(2 * np.pi * modulation_freq * np.arange(start_time, total_time - start_time, step_size_s))
|
||||||
values = amplitude * carrier * modulation
|
values = amplitude * carrier * modulation
|
||||||
return values
|
return values
|
||||||
|
|
||||||
# if it is split into parts with and without amplitude modulation built it in parts:
|
# if it is split into parts with and without amplitude modulation built it in parts:
|
||||||
values = np.array([])
|
values = np.empty(1)
|
||||||
|
|
||||||
if time_start < start_time:
|
if time_start < start_time:
|
||||||
carrier_before_am = np.sin(2 * np.pi * carrier_freq * np.arange(time_start, start_time, step_size / 1000))
|
carrier_before_am = np.sin(2 * np.pi * carrier_freq * np.arange(time_start, start_time, step_size_s))
|
||||||
values = np.concatenate((values, amplitude * carrier_before_am))
|
values = np.concatenate((values, amplitude * carrier_before_am))
|
||||||
|
|
||||||
# there is at least a second part of the stimulus that contains the amplitude:
|
# there is at least a second part of the stimulus that contains the amplitude:
|
||||||
@ -68,14 +67,14 @@ def convert_to_array(carrier_freq, amplitude, modulation_freq, contrast, start_t
|
|||||||
if duration is np.inf:
|
if duration is np.inf:
|
||||||
|
|
||||||
carrier_during_am = np.sin(
|
carrier_during_am = np.sin(
|
||||||
2 * np.pi * carrier_freq * np.arange(start_time, time_start+total_time, step_size / 1000))
|
2 * np.pi * carrier_freq * np.arange(start_time, time_start + total_time, step_size_s))
|
||||||
am = 1 + contrast * np.sin(
|
am = 1 + contrast * np.sin(
|
||||||
2 * np.pi * modulation_freq * np.arange(start_time, time_start+total_time, step_size / 1000))
|
2 * np.pi * modulation_freq * np.arange(start_time, time_start + total_time, step_size_s))
|
||||||
else:
|
else:
|
||||||
carrier_during_am = np.sin(
|
carrier_during_am = np.sin(
|
||||||
2 * np.pi * carrier_freq * np.arange(start_time, start_time + duration, step_size / 1000))
|
2 * np.pi * carrier_freq * np.arange(start_time, start_time + duration, step_size_s))
|
||||||
am = 1 + contrast * np.sin(
|
am = 1 + contrast * np.sin(
|
||||||
2 * np.pi * modulation_freq * np.arange(start_time, start_time + duration, step_size / 1000))
|
2 * np.pi * modulation_freq * np.arange(start_time, start_time + duration, step_size_s))
|
||||||
values = np.concatenate((values, amplitude * am * carrier_during_am))
|
values = np.concatenate((values, amplitude * am * carrier_during_am))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -83,7 +82,7 @@ def convert_to_array(carrier_freq, amplitude, modulation_freq, contrast, start_t
|
|||||||
print("Given stimulus time parameters (start, total) result in no part of it containing the amplitude modulation!")
|
print("Given stimulus time parameters (start, total) result in no part of it containing the amplitude modulation!")
|
||||||
|
|
||||||
if time_start+total_time > start_time+duration:
|
if time_start+total_time > start_time+duration:
|
||||||
carrier_after_am = np.sin(2 * np.pi * carrier_freq * np.arange(start_time+duration, time_start+total_time, step_size/1000))
|
carrier_after_am = np.sin(2 * np.pi * carrier_freq * np.arange(start_time + duration, time_start + total_time, step_size_s))
|
||||||
values = np.concatenate((values, amplitude*carrier_after_am))
|
values = np.concatenate((values, amplitude*carrier_after_am))
|
||||||
|
|
||||||
return values
|
return values
|
||||||
|
Loading…
Reference in New Issue
Block a user