%% License Info
%A Model of Feedforward, Global, and Lateral Inhibition in the Locust Visual System.

%This model examines the architecture and function of inhibitory mechanisms in the 
%visual system of locusts, namely those involved in the processing of inputs to a
%key looming-sensitive neuron, the lobula giant movement detector (LGMD).

%Copyright (c) 2026, Erik Olson, Travis Wiens, and Jack Gray

%CITATION:
%When using the model code for scientific publications, cite the following work:
%Olson EGN, Wiens TK, Gray JR. A model of feedforward, global, and lateral inhibition 
%in the locust visual system predicts responses to looming stimuli. Biol Cybern. 2021 
%Jun;115(3):245-265. doi: 10.1007/s00422-021-00876-8. Epub 2021 May 16. PMID: 33997912.

%This program is free software: you can redistribute it and/or modify
%it under the terms of the GNU General Public License as published by
%the Free Software Foundation, either version 3 of the License, or
%(at your option) any later version.

%This program is distributed in the hope that it will be useful,
%but WITHOUT ANY WARRANTY; without even the implied warranty of
%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%GNU General Public License for more details.

%You should have received a copy of the GNU General Public License
%along with this program.  If not, see <https://www.gnu.org/licenses/>.

%Contact: erik.olson@usask.ca

%% Code
function [f,t_f] = subIterationFFIGrating(parFile,smoothing,inhibition_mod)
%This function performs a single grating trial, as required for the
%FFIGratingTrial function.

%load model parameters into the workspace
load(parFile);

%Overwrite inhibition values if needed
if not(isnan(inhibition_mod(1)))
    K_lat_m = inhibition_mod(1);
end

if not(isnan(inhibition_mod(2)))
    K_gl_m = inhibition_mod(2);
end

if not(isnan(inhibition_mod(3)))
    tau_lat = inhibition_mod(3);
end

options = simset('srcworkspace','current','ReturnWorkspaceOutputs','on');

results = sim("FFIGratingModel.slx",T_final,options);
t = results.yout{1}.Values.Time; %Access time data
y = results.yout{1}.Values.Data; %Access FFI output data
Simulink.sdi.clear;

[f,hist,t_f] = histoFiringRate(y,t,0.001,smoothing);
fprintf('sub-iteration complete\n');
end

