%% 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
%Generates Figures 3 and 4
%%
%Figure 3
%Load model data, along with LMC voltage data from Jones_and_Gabbiani_2010
%for comparison. Note that the data is in volts, not millivolts. This
%will be converted when plotting
load('LMCFigureData.mat');
load('Jones_and_Gabbiani_2010_LMC_Data.mat');
close all
%Plot Figure 4
lmc_plots = figure(1);
%1st comparison: Delta_{t,L] = 0 ms
subplot(2,2,1);
hold on;
plot(t_LMC,V_LMC(:,1)*1e3,'LineWidth',1,'DisplayName','Model');
plot(Time,t0ms*1e3,'LineWidth',1,'DisplayName','Experiment');
legend;
xlabel('Time [s]');
ylabel({'LMC Membrane';'Potential, V_{LMC} [mV]'});
xlim([0,0.4]);
ylim([0,20]);
title('\Deltat_L = 0 ms');
%2nd comparison: Delta_{t,L] = 83 ms
subplot(2,2,2);
hold on;
plot(t_LMC,V_LMC(:,2)*1e3,'LineWidth',1,'DisplayName','Model');
plot(Time,t83ms*1e3,'LineWidth',1,'DisplayName','Experiment');
legend;
xlabel('Time [s]');
ylabel({'LMC Membrane';'Potential, V_{LMC} [mV]'});
xlim([0,0.4]);
ylim([0,20]);
title('\Deltat_L = 83 ms');
%3rd comparison: Delta_{t,L] = 183 ms
subplot(2,2,3);
hold on;
plot(t_LMC,V_LMC(:,3)*1e3,'LineWidth',1,'DisplayName','Model');
plot(Time,t183ms*1e3,'LineWidth',1,'DisplayName','Experiment');
legend;
xlabel('Time [s]');
ylabel({'LMC Membrane';'Potential, V_{LMC} [mV]'});
xlim([0,0.4]);
ylim([0,20]);
title('\Deltat_L = 183 ms');
%4th comparison: Delta_{t,L] = 350 ms
subplot(2,2,4);
hold on;
plot(t_LMC,V_LMC(:,4)*1e3,'LineWidth',1,'DisplayName','Model');
plot(Time,t350ms*1e3,'LineWidth',1,'DisplayName','Experiment');
legend;
xlabel('Time [s]');
ylabel({'LMC Membrane';'Potential, V_{LMC} [mV]'});
xlim([0,0.4]);
ylim([0,20]);
title('\Deltat_L = 350 ms');
set(lmc_plots,'Units','Inches');
pos = get(lmc_plots,'Position');
set(lmc_plots,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
savefig('lmc_plots');
saveas(gcf,'Fig3.pdf');
%%
%Figure 4
%Load model data, along with voltage clamp data from Jones_and_Gabbiani_2010
%for comparison
load('VoltageClampFigureData.mat');
load('Jones_and_Gabbiani_2010_Voltage_Clamp_Data.mat');
%Plot Figure 4
volt_clamp = figure(2);
%1st comparison: Delta_{t,L] = 0 ms
subplot(2,2,1);
hold on;
plot(t_out,I_out(:,1)*1e9,'LineWidth',1,'DisplayName','Model');
plot(t_exp,I_exp1*1e9,'LineWidth',1,'DisplayName','Experiment');
legend;
xlabel('Time [s]');
ylabel({'Input Current to';'Proximal LGMD [nA]'});
xlim([0,0.4]);
ylim([0,3]);
title('\Deltat_L = 0 ms');
%2nd comparison: Delta_{t,L] = 83 ms
subplot(2,2,2);
hold on;
plot(t_out,I_out(:,2)*1e9,'LineWidth',1,'DisplayName','Model');
plot(t_exp,I_exp2*1e9,'LineWidth',1,'DisplayName','Experiment');
legend;
xlabel('Time [s]');
ylabel({'Input Current to';'Proximal LGMD [nA]'});
xlim([0,0.4]);
ylim([0,3]);
title('\Deltat_L = 83 ms');
%3rd comparison: Delta_{t,L] = 183 ms
subplot(2,2,3);
hold on;
plot(t_out,I_out(:,3)*1e9,'LineWidth',1,'DisplayName','Model');
plot(t_exp,I_exp3*1e9,'LineWidth',1,'DisplayName','Experiment');
legend;
xlabel('Time [s]');
ylabel({'Input Current to';'Proximal LGMD [nA]'});
xlim([0,0.4]);
ylim([0,3]);
title('\Deltat_L = 183 ms');
%4th comparison: Delta_{t,L] = 350 ms
subplot(2,2,4);
hold on;
plot(t_out,I_out(:,4)*1e9,'LineWidth',1,'DisplayName','Model');
plot(t_exp,I_exp4*1e9,'LineWidth',1,'DisplayName','Experiment');
legend;
xlabel('Time [s]');
ylabel({'Input Current to';'Proximal LGMD [nA]'});
xlim([0,0.4]);
ylim([0,3]);
title('\Deltat_L = 350 ms');
set(volt_clamp,'Units','Inches');
pos = get(volt_clamp,'Position');
set(volt_clamp,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
savefig('volt_clamp');
saveas(gcf,'Fig4.pdf');