
    N=4000; % N sets the number of neurons; we have used 4000

    % Sets up the parameters excitatory and inhibitory gaussians
    sigg_ex=1; %Sigma (or width) of the excitatory Gaussian. "Standard" value is 1
    amp_ex=1;   %Amplitude (or height) of the excitatory Gaussian. "Standard" value is 1
    sigg_inh1=1.6; %Sigma (or width) of the inhibitory Gaussian. "Standard" value is 1.6
    amp_inh=1; %Amplitude (or height) of the inhibitory Gaussian. "Standard" value is 1

    A=1;  % Decay term; we have used 1
    B=10.1; % Upper limit of x; we have used 10.1
    C=5;  % Lower limit of x; we have used 5
    


    GEX=gauss_ex_func(sigg_ex,amp_ex); % Creates the excitatory Gaussian using the excitatory Gaussian function and the sigg_ex and amp_ex parameters set above

    GINH1=gauss_inh_func(sigg_inh1,amp_inh);  % Creates the inhibitory Gaussian using the inhibitory Gaussian function and the sigg_inh and amp_inh parameters set above

    counter=0;
    ff=logspace(-1,2,200);  % Sets the spacial frequency range
    zz=-4:0.002:4;    % x-axis of sin graph, each degree contains 500 bins, meaning that the model spans about 8 degrees

    
    contrastsensitivity=zeros(size(ff)); % This allows us to create the contrast sensitivity vector
    
for f=ff  
    counter=counter+1; 
    sf=0.1*sin(2*pi*f*zz); % Creates the sinusoidal grating
  
    x=(B.*(conv(sf(1,:),GEX,'same'))-C.*(conv(sf(1,:),GINH1,'same')))./...
        (A+(conv(sf(1,:),GEX,'same'))+(conv(sf(1,:),GINH1,'same'))); % Neural activity equation
    
    xx=x(1,500:end-500);  % This eliminates the edge effect that results from convolution
    
    MN=min(xx,[],2);  % Finds minimum value of activity without edge effect (xx)
    MX=max(xx,[],2);  % Finds maximum value of activity without edge effect (xx)

    contrastsensitivity(counter)=MX-MN; % Creates a value that represents contrast sensitivity for each spatial frequency

end

% Plots sensitivity at each spatial frequency and standardizes axes
figure
plot(ff',contrastsensitivity,'Color','k','LineWidth',4)
xlabel('Spatial Frequency (cpd)')
ylabel('Sensitivity')
xlim([0 25])
ylim([0 3])
set(gca,'FontSize',22,'FontWeight','bold')

% Plots the separate excitatory and inhibitory Gaussians from the specified
% parameter values (for visualization purposes)
figure
hold on
exrangex=-5:0.1:5; % Sets the x-axis range
plot(exrangex,B*GEX,'LineWidth',4,'Color','r') % Plots the excitatory Gaussian
plot(exrangex,C*GINH1,'LineWidth',4,'Color','b') %Plots the inhibitory Gaussian

% Plots the receptive field created by the Difference of Gaussians method
figure
plot(exrangex,(B*GEX-C*GINH1),'Color','k','LineWidth',4)
set(gca,'FontSize',22,'FontWeight','bold')
xlabel('Degrees of Visual Angle')
ylabel('Model RF Amplitude')
xticklabels({-0.5 0 0.5})
ylim([-0.2 1.2])
hold on



%This is the function that establishes the Excitatory Gaussian

function GEX=gauss_ex_func(sigg_ex,amp_ex)

%rangex=round(-3*sigg_ex):0.1:round(3*sigg_ex);   % This is a vector x
% exrangex=round(-3*sigg_ex):0.1:round(3*sigg_ex); 
exrangex=-5:0.1:5;
y=(1/(sqrt(2*pi)*sigg_ex)) * exp(-0.5*((exrangex).^2./(sigg_ex.^2)));  % By putting in this vector, y will inherently be a vector as well
GEX=amp_ex*y/(sum(y));

end 


% This function allows the creation of the inhibitory Gaussian function

function GINH=gauss_inh_func(sigg_inh,amp_inh)

%rangex=round(-3*sigg_inh):0.1:round(3*sigg_inh);   % This is a vector x
% inhrangex=round(-3*sigg_inh):0.1:round(3*sigg_inh); % This is a vector x
inhrangex=-5:0.1:5;
z=(1/(sqrt(2*pi)*sigg_inh)) * exp(-0.5*((inhrangex).^2./(sigg_inh.^2)));  % By putting in this vector, y will inherently be a vector as well
GINH=amp_inh*z/(sum(z));
end



