-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
1,475 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
function create_stimulus_file | ||
% Generate stimulus files for SNT experiment | ||
|
||
%%%%%%%%%%%%%%%%% | ||
N_blocks = 3; % Number of blocks to calculate | ||
% EXP_TYPE = 'exp_1'; % | ||
EXP_TYPE = 'exp_2'; % | ||
|
||
|
||
% Define the stimuli in each experiment - In each block (of the N_blocks) | ||
% we will have each stimulus once, in a pseudorandom order | ||
% switch statement for experiment type | ||
switch EXP_TYPE | ||
case 'exp_1' | ||
Stimuli{1} = 'MU_1'; | ||
Stimuli{2} = 'MU_2'; | ||
Stimuli{3} = 'MU_3'; | ||
Stimuli{4} = 'FU_1'; | ||
Stimuli{5} = 'FU_2'; | ||
Stimuli{6} = 'FU_3'; | ||
case 'exp_2' | ||
Stimuli{1} = 'PU_1'; | ||
Stimuli{2} = 'PU_2'; | ||
Stimuli{3} = 'PU_3'; | ||
Stimuli{4} = 'MU_1'; | ||
Stimuli{5} = 'MU_2'; | ||
Stimuli{6} = 'MU_3'; | ||
Stimuli{7} = 'FU_1'; | ||
Stimuli{8} = 'FU_2'; | ||
Stimuli{9} = 'FU_3'; | ||
end | ||
|
||
[BASE_P,~,~] = fileparts(mfilename('fullpath')); | ||
STIM_FILE_PATH = [BASE_P filesep 'stimulus_files']; | ||
if ~exist(STIM_FILE_PATH,'dir') | ||
mkdir(STIM_FILE_PATH); | ||
end | ||
datestring = datestr(now,1); | ||
fname = [STIM_FILE_PATH filesep 'stimfile_' datestring '.txt']; | ||
|
||
|
||
|
||
if exist(fname,'file') | ||
ButtonName=questdlg('File exists, overwrite?', ... | ||
'make pseudo file', ... | ||
'No','Yes','No'); | ||
switch ButtonName | ||
case 'No' | ||
return | ||
end % switch | ||
end | ||
|
||
|
||
fid = fopen(fname,'w'); | ||
|
||
% shuffle the random number generator (to avoid repeats in different MATLAB sessions) | ||
rng('shuffle') | ||
|
||
% Write stimuli to file | ||
for i = 1:N_blocks | ||
ords = randperm(length(Stimuli)); | ||
for j = 1:length(ords) | ||
fprintf(fid,'%s\r\n',Stimuli{ords(j)}); | ||
end | ||
fprintf(fid,['\r\n\r\n']); | ||
end | ||
|
||
|
||
fclose(fid); | ||
|
||
return | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function [SOUND_chan,VNO_chan,VALVE_chan ] = generate_single_SNT_stim_scan(Params) | ||
% Generate a single SNT stimulation train | ||
|
||
% param fields are | ||
% SR sampling rate in Hz | ||
SR = Params.SR; | ||
|
||
samples_VNO_stim_duration = Params.VNO_stim_duration * SR; | ||
%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
% generate VNO stimulation train | ||
VNO_period_samples = ceil(SR / Params.VNO_stim_frequency) ;% in samples | ||
VNO_n_cycles = ceil(samples_VNO_stim_duration/VNO_period_samples); | ||
% positive, inter and negative pulse times in samples: | ||
VNO_ps = ceil(SR*Params.VNO_stim_pulse_width/1000); | ||
VNO_ips = ceil(SR*Params.VNO_stim_interphase_delay/1000); | ||
VNO_samples_per_pulse = 2*VNO_ps + VNO_ips; | ||
VNO_samples_between_pulses = VNO_period_samples - VNO_samples_per_pulse; | ||
VNO_one_pulse = [zeros(1,VNO_samples_between_pulses) -Params.VNO_stim_amplitude*ones(1,VNO_ps) zeros(1,VNO_ips) Params.VNO_stim_amplitude*ones(1,VNO_ps)]; | ||
VNO_stim_train = repmat(VNO_one_pulse,1,VNO_n_cycles); | ||
VNO_stim_train = VNO_stim_train(1:samples_VNO_stim_duration); | ||
VNO_stim_train = [VNO_stim_train(1:(end-5)) zeros(1,5)]; | ||
|
||
|
||
trial_ints(1) = samples_VNO_stim_duration; | ||
|
||
|
||
SOUND_chan = 0*ones(1,sum(trial_ints(1))) ; | ||
VNO_chan = VNO_stim_train ; | ||
VALVE_chan = 0*ones(1,sum(trial_ints(1))) ; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
function [SOUND_chan,VNO_chan,VALVE_chan apply_sample] = generate_single_VNS_trial_scan(Params) | ||
% Generate output signals according to selected trial parameters | ||
% YBS 2017 | ||
|
||
% param fields are | ||
% SR sampling rate in Hz | ||
SR = Params.SR; | ||
digoutV = 3.3; % scale factor for the valve channel | ||
|
||
|
||
[apply_sound,clean_sound, end_sound] = generate_trial_sounds(SR); | ||
|
||
samples_apply_sound = length(apply_sound); | ||
samples_clean_sound = length(clean_sound); | ||
samples_end_sound = length(end_sound); | ||
samples_ES_stim_to_apply_delay = 0; % Params.ES_stim_to_apply_delay * SR; | ||
samples_ES_stim_duration = 0; % Params.ES_stim_duration * SR; | ||
samples_application_to_stim_delay = Params.application_to_stim_delay * SR; | ||
samples_ES_stim_to_VNO_stim_delay = 0; % Params.ES_stim_to_VNO_stim_delay * SR; | ||
samples_VNO_stim_duration = Params.VNO_stim_duration * SR; | ||
samples_stim_to_wash_delay = Params.stim_to_wash_delay * SR; | ||
samples_wash_start_to_wash_stim_delay = Params.wash_start_to_wash_stim_delay * SR; | ||
samples_wash_stim_to_wash_end_delay = Params.wash_stim_to_wash_end_delay * SR; | ||
|
||
apply_sample = samples_apply_sound; | ||
|
||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
% generate VNO stimulation train | ||
VNO_period_samples = ceil(SR / Params.VNO_stim_frequency) ;% in samples | ||
VNO_n_cycles = ceil(samples_VNO_stim_duration/VNO_period_samples); | ||
% positive, inter and negative pulse times in samples: | ||
VNO_ps = ceil(SR*Params.VNO_stim_pulse_width/1000); | ||
VNO_ips = ceil(SR*Params.VNO_stim_interphase_delay/1000); | ||
VNO_samples_per_pulse = 2*VNO_ps + VNO_ips; | ||
VNO_samples_between_pulses = VNO_period_samples - VNO_samples_per_pulse; | ||
VNO_one_pulse = [zeros(1,VNO_samples_between_pulses) -Params.VNO_stim_amplitude*ones(1,VNO_ps) zeros(1,VNO_ips) Params.VNO_stim_amplitude*ones(1,VNO_ps)]; | ||
VNO_stim_train = repmat(VNO_one_pulse,1,VNO_n_cycles); | ||
VNO_stim_train = VNO_stim_train(1:samples_VNO_stim_duration); | ||
|
||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
% generate ES external stimulation train | ||
ES_stim_train = []; | ||
|
||
|
||
trial_ints(1) = samples_apply_sound - samples_ES_stim_to_apply_delay; | ||
trial_ints(2) = samples_ES_stim_to_apply_delay; | ||
trial_ints(3) = samples_ES_stim_duration - samples_ES_stim_to_apply_delay; | ||
trial_ints(4) = samples_application_to_stim_delay - samples_ES_stim_to_VNO_stim_delay - trial_ints(3); | ||
trial_ints(5) = samples_ES_stim_to_VNO_stim_delay; | ||
trial_ints(6) = samples_VNO_stim_duration; | ||
trial_ints(7) = samples_ES_stim_duration - trial_ints(5) - trial_ints(6); | ||
trial_ints(8) = samples_stim_to_wash_delay - trial_ints(7) - trial_ints(6) - samples_clean_sound; | ||
trial_ints(9) = samples_clean_sound; | ||
trial_ints(10) = samples_wash_start_to_wash_stim_delay; | ||
trial_ints(11) = samples_VNO_stim_duration; | ||
trial_ints(12) = samples_wash_stim_to_wash_end_delay - samples_VNO_stim_duration; | ||
trial_ints(13) = samples_end_sound; | ||
|
||
|
||
|
||
SOUND_chan = [apply_sound zeros(1,sum(trial_ints([3:8]))) clean_sound zeros(1,sum(trial_ints([10:12]))-samples_end_sound) end_sound zeros(1,sum(trial_ints([13])))] ; | ||
VNO_chan = [zeros(1,sum(trial_ints([1:5]))) VNO_stim_train zeros(1,sum(trial_ints([7:10]))) VNO_stim_train zeros(1,sum(trial_ints([12:13])))] ; | ||
VALVE_chan = [zeros(1,sum(trial_ints([1:9]))) digoutV * ones(1,sum(trial_ints([10:12]))) zeros(1,sum(trial_ints([13])))]; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function [SOUND_chan,VNO_chan,VALVE_chan]=generate_single_washvalve_scan(valveState) | ||
% open and close the valve - simply changing output level | ||
% YBS - 2017 | ||
|
||
digoutV = 3.3; | ||
|
||
if strcmp(valveState,'close') | ||
samples_valve_duration=ones(1,100); | ||
elseif strcmp(valveState,'open') | ||
samples_valve_duration=zeros(1,100); | ||
end | ||
SOUND_chan = 0*samples_valve_duration ; | ||
VNO_chan = 0*samples_valve_duration ; | ||
VALVE_chan = samples_valve_duration*digoutV ; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
function [apply_sound clean_sound end_sound] = generate_trial_sounds(SR) | ||
% generate sounds for queing the user for stimulus application | ||
% YBS 2017 | ||
|
||
|
||
% Define the sound segment lengths | ||
% Sound factors for all sound waveforms generated | ||
sound_amp = 5; | ||
sound_offset = 0; | ||
% apply sound parameters | ||
apply_sound_dur_per_step = 1; | ||
apply_sound_freq = 2*[130.81 146.83 164.81 174.61 196 220 246.94 261.63]; | ||
|
||
% generate initial sound signal | ||
apply_sound = []; | ||
duration = apply_sound_dur_per_step * ones(size(apply_sound_freq)); % in seconds %duration = [1 0.5 1 1 1 0.5 0.2 0.5 1] | ||
for i = 1:length(apply_sound_freq) | ||
samps_per_cycle = floor(SR/apply_sound_freq(i)); | ||
one_cycle = sin(linspace(0, 2*pi, samps_per_cycle)); | ||
cycles_per_second = SR/length(one_cycle); | ||
apply_sound = [apply_sound repmat(one_cycle,[1 ceil(cycles_per_second*duration(i))]) ]; | ||
end | ||
% to shift voltage so that INTAN board can read it | ||
apply_sound = sound_amp*apply_sound + sound_offset; | ||
|
||
% clean sound parameters | ||
clean_sound_duration = 0.5; | ||
clean_sound_freq = fliplr(apply_sound_freq); | ||
clean_sound = []; | ||
duration = clean_sound_duration * ones(size(clean_sound_freq)); % in seconds %duration = [1 0.5 1 1 1 0.5 0.2 0.5 1] | ||
for i = 1:length(clean_sound_freq) | ||
samps_per_cycle = floor(SR/clean_sound_freq(i)); | ||
one_cycle = sin(linspace(0, 2*pi, samps_per_cycle)); | ||
cycles_per_second = SR/length(one_cycle); | ||
clean_sound = [clean_sound repmat(one_cycle,1,ceil(cycles_per_second*duration(i)))]; | ||
end | ||
clean_sound = sound_amp*clean_sound +sound_offset; | ||
|
||
% End of trial sound | ||
end_sound_duration = 0.1; | ||
end_sound_freq = fliplr(2 * [130.81 146.83 164.81 174.61 196 ]); | ||
end_sound_signal = []; | ||
duration = end_sound_duration * ones(size(end_sound_freq)); % in seconds %duration = [1 0.5 1 1 1 0.5 0.2 0.5 1] | ||
for i = 1:length(end_sound_freq) | ||
samps_per_cycle = floor(SR/end_sound_freq(i)); | ||
one_cycle = sin(linspace(0, 2*pi, samps_per_cycle)); | ||
cycles_per_second = SR/length(one_cycle); | ||
end_sound_signal = [end_sound_signal repmat(one_cycle,[1 ceil(cycles_per_second*duration(i))]) ]; | ||
end | ||
end_sound = sound_amp*end_sound_signal + sound_offset; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function Stimuli = read_stimulus_file(fname) | ||
% Read stimuli from stimulus file and return as char array | ||
|
||
fid = fopen(fname,'r'); | ||
|
||
k = 0; | ||
while 1 | ||
tline = fgetl(fid); % This is the file name line | ||
if ~ischar(tline), break, end | ||
if ~isempty(tline) % ignore empty lines | ||
k = k + 1; | ||
Stimuli{k} = tline; | ||
end | ||
end | ||
|
||
|
||
fclose(fid); |