%Instruction of using Motor uNit INnervation process Generator
%(mNing) to simulate the innervation process of a pool of motoneurons
%The package is written in an object oriented fashion. Two main data
%structures are used: "network" and "para".
%The first top-level structure "Network" is the structure
%containing various parameters of the motoneuron pools. Three sub-structure
%exists within "network":
%1) neurons: the individual neurons. Neurons itself is also a structure,
%and its fields are the various parameters in the HH model, such as the
%contances of potassium, sodium, and leak current, the reversal potential,
%etc. There are several fields that are of particular interest within this
% a) vna: the reversal potential of Na+. it determins the recruitment
% threshold of the neuron. The larger this value, the lower the
% recruitment threshold.
% b) inpbias: the bias current, or base current of the neuron. Determines
% the mean firing rate of the neuron.
% c) inpsigma: the STD of the input current. Determines the variance of
% the firing rate of the neuron.
% d) cdfuncid: The type of Common Input (CI) to the neuorn. This field is
% an integer (an ID), which corresponds to one of the Common Input
% functions defined in "network.cdfunc". If it is 0, then there is no CI
% to this neuron.
% e) inp: the input current to this neuron. This will be generated during
% the simulation using related parameters by the runtine called
%2) synapse: the synapse matrix of the network. Generate by routine "MNNsynapse.m";
%3) cdfunc: the common input function that is responsible for the COMMON
%DRIVE effect within the MN pool. Itself is alos a structure array with the
% a) type: an integer that determines the type, 1 means generate on the
% fly; 2 means using a stored data;
% b) rms: the rms value of the CI function. it should be zero if "type"
% is set to 2;
% c) name: the full path of the stored data file;
% d) func: the CI function. This will be generate by the routine
%The second top-level structure "para" is the structure containing various simulation parametres:
%1) duration: the duration of the simulation, in sec
%2) stepsize: the stepsize of the ODE solver, in msec
%3) trial_num: repeatation of simulations
%4) resultfilepath: the path where to store the simulation results
%5) resultfilename: the common file name for the simulation result files
%This is a sample script of using the various functions in mNing package to
%simulate a MN pool of 11 MNs. In this pool, MN(1) is the common excitor
%for the other 10 MNs. MN(2:6) and MN(7:11) are two MN groups, each have a
%CI of their own. There is a recruitment order within each of the group.
%Written by Ning Jiang, Institute of Biomedical Engineering, Univesity of New
%Brunswick, NB, Canada, E3B 5A3.
%Date: Nov 19, 2006
%% Loading neuron template
%% Creating the "neuron" structure
%size of the pool
%range of Vna--->range of recruitment level
%creating MN objects in a batch model. The common excitor is set to have
%the lowest recruitment threshold.
%The first group MN(2:6)
%The second group MN(7:11)
%% Creating the synaptic matrix
%Updating the ODE functions. This should be done when ever the network
%structure changes, such as parameter changes in any of the "neurons"
%substructure, or the synapse matrix. However, the changes of CI functions
%does not necessarily mean an update of "simulation", since it is not a
%% Defining CD functions
%number of CD functions
%creating the sub-structure of 'cdfun' for later use
% .type: is the type of cdfuns --> 1: created On the fly during simulation.
% it requires non zero value of the field 'rms';
% 2: use saved funcs. it requires the field 'name'
% to be a valid pathname/filename
% .rms: the rms value of the CD fun. if type is 1; it is 0 if type is 2;
% .name: the path/filename of the stored cdfun data if type is 1; "N/A" if type
% is 1
%Or if pre-stored CI data is to be used:
%Assigning the CI func IDs to individual MNs; the field "cdfunid" in each
%neuron corresponds to the field "cdfunc" in network. If "cdfuncid" is zero,
%meaning there is no cdfun to that neuron. If "cdfuncid" is some non-zero
%number N, meaning the CI func to this neuron is the the cdfun number N.
%In this example, MN(2:6) have a CI func ID of 1, and MN(7:11) have a CI func ID of 2:
%assigncd=ones(1,nMN); %all have the same CI function
%assigncd=zeros(1,nMN); %no CI functions at all
%% Setting up simulation parameters
%the integration stepsize for the ODE solver, in msec
%duration of simulation, in sec
%full path of result data
%% begin simulation
%% Displaying the simulation results
% The input currents to each MN
% The firing times of each MN