BackgroundThe bidirectional brain-machine interfaces algorithms are machines that decode neural response in order to control the external device and encode position of artificial limb to proper electrical stimulation, so that the interface between brain and machine closes. Most BMI researchers typically consider four basic elements: recording technology to extract brain activity, decoding algorithm to translate brain activity to the predicted movement of the external device, external device (prosthetic limb such as a robotic arm), and encoding interface to convert the motion of the external machine to set of the electrical stimulation of the brain. New methodIn this paper, we develop a novel approach for bidirectional brain-machine interface (BMI). First, we propose a neural network model for sensory cortex (S1) connected to the neural network model of motor cortex (M1) considering the topographic mapping between S1 and M1. We use 4-box model in S1 and 4-box in M1 so that each box contains 500 neurons. Individual boxes include inhibitory and excitatory neurons and synapses. Next, we develop a new BMI algorithm based on neural activity. The main concept of this BMI algorithm is to close the loop between brain and mechaical external device. ResultsThe sensory interface as encoding algorithm convert the location of the external device (artificial limb) into the electrical stimulation which excite the S1 model. The motor interface as decoding algorithm convert neural recordings from the M1 model into a force which causes the movement of the external device. We present the simulation results for the on line BMI which means that there is a real time information exchange between 9 boxes and 4 boxes of S1-M1 network model and the external device. Also, off line information exchange between brain of five anesthetized rats and externnal device was performed. The proposed BMI algorithm has succeeded in controlling the movement of the mechanical arm towards the target area on simulation and experimental data, so that the BMI algorithm shows acceptable WTPE and the average number of iterations of the algorithm in reaching artificial limb to the target region.Comparison with existing methods and Conclusions: In order to confirm the simulation results the 9-box model of S1-M1 network was developed and the valid “spike train” algorithm, which has good results on real data, is used to compare the performance accuracy of the proposed BMI algorithm versus “spike train” algorithm on simulation and off line experimental data of anesthetized rats. Quantitative and qualitative results confirm the proper performance of the proposed algorithm compared to algorithm “spike train” on simulations and experimental data.