add convert to array with jit
This commit is contained in:
parent
a53d6f4a4e
commit
04ba55bbc5
@ -2,11 +2,12 @@ from stimuli.AbstractStimulus import AbstractStimulus
|
||||
import numpy as np
|
||||
from numba import jit, njit
|
||||
import time
|
||||
from warnings import warn
|
||||
|
||||
|
||||
class SinusAmplitudeModulationStimulus(AbstractStimulus):
|
||||
|
||||
def __init__(self, carrier_frequency, contrast, modulation_frequency, amplitude=1, start_time=0, duration=np.inf):
|
||||
def __init__(self, carrier_frequency, contrast, modulation_frequency, start_time=0, duration=np.inf, amplitude=1):
|
||||
self.contrast = contrast
|
||||
self.modulation_frequency = modulation_frequency
|
||||
self.amplitude = amplitude
|
||||
@ -56,16 +57,33 @@ def convert_to_array(carrier_freq, amplitude, modulation_freq, contrast, start_t
|
||||
return values
|
||||
|
||||
# if it is split into parts with and without amplitude modulation built it in parts:
|
||||
values = np.array(0)
|
||||
|
||||
values = np.array([])
|
||||
if time_start < start_time:
|
||||
carrier_before_am = np.sin(2 * np.pi * carrier_freq * np.arange(time_start, start_time, step_size / 1000))
|
||||
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:
|
||||
# time starts before the end of the am and ends after it was started
|
||||
if time_start < start_time+duration and time_start+total_time > start_time:
|
||||
if time_start+total_time > start_time+duration:
|
||||
carrier_during_am = np.sin(2 * np.pi * carrier_freq * np.arange(start_time, start_time+duration, step_size/1000))
|
||||
am = 1 + contrast * np.sin(2 * np.pi * modulation_freq * np.arange(start_time, start_time+duration, step_size/1000))
|
||||
np.concatenate(values, amplitude*am*carrier_during_am)
|
||||
if duration is np.inf:
|
||||
|
||||
carrier_during_am = np.sin(
|
||||
2 * np.pi * carrier_freq * np.arange(start_time, time_start+total_time, step_size / 1000))
|
||||
am = 1 + contrast * np.sin(
|
||||
2 * np.pi * modulation_freq * np.arange(start_time, time_start+total_time, step_size / 1000))
|
||||
else:
|
||||
carrier_during_am = np.sin(
|
||||
2 * np.pi * carrier_freq * np.arange(start_time, start_time + duration, step_size / 1000))
|
||||
am = 1 + contrast * np.sin(
|
||||
2 * np.pi * modulation_freq * np.arange(start_time, start_time + duration, step_size / 1000))
|
||||
values = np.concatenate((values, amplitude * am * carrier_during_am))
|
||||
|
||||
else:
|
||||
if contrast != 0:
|
||||
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:
|
||||
carrier_after_am = np.sin(2 * np.pi * carrier_freq * np.arange(start_time+duration, time_start+total_time, step_size/1000))
|
||||
values = np.concatenate((values, amplitude*carrier_after_am))
|
||||
|
||||
return values
|
||||
|
Loading…
Reference in New Issue
Block a user