Electrochemical and Biological Simulation for Microfluidics

My research as a graduate student focuses on biosensing applications using electrochemical impedimetric methods. Unlike mechatronic systems, these applications consider a dynamic environment at such a microscale, it is quite hard to perceive what is really going on when we merely recognize the change of physical property. I usually ask myself: What is the underlying mechanism? Tucked away from the limit of horizon of the human eye, we often see nothing happening when doing these experiments.

That is why simulation is so important! In this project, I performed 3 simulation tasks in order to visualize the changes of important physical properties for my study (impedimetric microfluidic chip for biosensing) using COMSOL Multiphysics.

The tasks are:

  1. Velocity field simulation inside microfluidic channel.
  2. Real-time molecule immobilization on gold surface.
  3. Electrochemical impedance spectroscopy (EIS) simulation.

The result of task 1 supports the hypotheses of task 2 and 3.

Physical Environment Setting

The simulation environment is set as the interior of a microfluidic channel with gold microelectrodes. See the film below for visualization.

The chip is fabricated using soft lithography and photolithography. The microfluidic channel has a width of 1mm and a height of 100μm at the center. The gold microelectrodes form a pair for square pads (300×300μm) at the center of the channel (Fig. 1).

Figure 1. Microfabrication process, dimensions, and microscopic view of the microfluidic electrode chip used in this project.

Velocity Field Simulation Inside Microfluidic Channel

The objective of this task is to simulate the fluid velocity field inside the channel on a sliced plane. Due to the fact that 3D simulation is time-consuming, if a 3D environment can be reduced to a 2D environment, then a large amount of time can be saved. By performing this task, it can be seen if dimension reduction modeling of task 2 and 3 are feasible.

Considering the physical nature of the microfluidic channel, a laminar flow model is implemented along with the Navier-Stokes equation:

$$\rho(\textbf{u}\cdot\nabla)\textbf{u}=\nabla\cdot[-pI+\mu(\nabla \textbf{u}+(\nabla \textbf{u})^T)]+F$$

, which means a balance between inertia (\(\rho(\textbf{u}\cdot\nabla)\textbf{u}\)), pressure (\(-pI\)), viscous (\(\mu(\nabla \textbf{u}+(\nabla \textbf{u})^T)\)) and external (\(F\)) forces. A stationary study is implemented (\(\rho \nabla \cdot \textbf{u}=0\)), and water is set as the fluid.

Fig. 2 shows the 3D velocity field inside the channel. A bigger arrow indicates a larger velocity magnitude. The reason that the velocity is faster at the center is because of the lower channel height.

Figure 2. 3D velocity field inside microfluidic channel.

Fig. 3 shows animated 2D velocity fields of sliced planes inside the channel. Due to laminar flow, velocities near the boundary get close to zero. However, the steady-state velocity reaches a constant value away from the boundary.

Figure 3. 2D velocity fields for xy and zy sliced planes.

A top view of the velocity field and the velocity at different x positions are shown in Fig. 4. It can be concluded that at the center of the channel where the microelectrodes lie, the fluid velocity stays constant, and subsequent tasks can be carried out using 2D models.

Figure 4. Top-view and x position-dependent velocity magnitude of fluid.

Real-time Molecule Immobilization on Gold Surface.

For microfluidic electrochemical biosensors, it is quite common that immobilization of sensing elements takes place at the center of the channel on electrode surfaces (e.g. Au). In this task, molecules are simulated to flow past the channel, and be immobilized on the electrode pad at the bottom center. A slice on the zy plane is used as the modeling geometry of this task (Fig. 5).

Figure 5. Modeling geometry used in task 2. A sliced area of the microfluidic channel with pad electrode at the bottom center is used.

Here, the molecules convect and diffuse near the surface, the rate of immobilization is determined by several factors including the inlet concentration (c0), diffusion coefficient (D), maximum surface molecule density (Γs). The convection-diffusion equation and transport-adsorption equation are used along with time-dependent study:

$${{\partial c} \over {\partial t}} + \nabla \cdot (-D\nabla c) + \textbf{u} \cdot \nabla c = R$$

$${{\partial c_s} \over {\partial t}} + \nabla \cdot (-D\nabla c_s) = k_{ads} c(\Gamma_s – c_s)-k_{des} c_s$$

For the transport-adsorption equation, it is assumed that the change of surface concentration plus the rate of surface diffusion equals the rate of Langmuir adsorption isotherm.

Fig. 6 shows the time-dependent surface concentration (cs) change when c0 = 1μM, and Fig. 7 shows the binding curve (probe density vs time) for different values of c0.

Figure 6. Time-dependent surface concentration (cs) change. t = 0~18hr.

Figure 7. Probe surface density (molecules/cm2) vs time (hr).

At concentrations above 0.1μM, the probe density almost saturates to a value of 9.6×1012 molecules/cm2 before immobilizing for 10 hours. The result highly resembles a typical binding curve, suggesting the possibility for computer simulating assisted optimization of in vitro parameters, which is really helpful for understanding underlying mechanisms for the system.

Electrochemical Impedance Spectroscopy (EIS) Simulation.

EIS is a rapid and label-free method for detection of bio-molecules, and is widely implemented on a variety of biosensors. In this task, I simulated EIS diagrams by changing the values of the heterogeneous rate constant (k0) and the double layer capacitance (Cdl). Both Cdl and k0 are affected by the immobilized surface molecule density on an electrode surface, and are important physical properties when analyzing EIS data. A slice on the xy plane is used as the modeling geometry of this task (Fig. 8).

Figure 8. Geometry being simulated for task 3. A 2D plane is sliced in the xy direction.

Here, a sinusoidal voltage wave is applied between the two electrodes (amplitude ≅ 5mV), and Bode plots and Nyquist plots can be drawn according to the measured impedance. According to the surface redox reaction, an equivalent circuit can be constructed. The equivalent circuit for this task is shown in Fig. 9.

Figure 9. Equivalent circuit used in my research and task 3.

Fick’s 2nd law and Butler-Volmer equation are used for simulation:

$${{\partial c}\over{\partial t}} = \nabla \cdot (D\nabla c)$$

$$j = nFk_0 (c_{Red} e^{ {(n-\alpha_c)F\eta} \over {RT} } – c_{Ox} e^{ {-\alpha_c F\eta} \over {RT} })$$

EIS plots are simulated for different values of k0 and Cdl (Fig. 10).

Figure 10. Bode and Nyquist plots for the simulated EIS data. k0 has a range from 0.001 to 0.1 (cm/s), and Cdl has a range from 0.01 to 100 (uF/cm2).

By undergoing this simulation project, I furthermore understood some fundamental interactions between the physical properties and outcome of my research to a new depth, and developed new concepts about how to improve it.

After completing this project, I also used COMSOL for simulating time-dependent concentration gradient variation of redox molecules in my 1st author journal paper “Diffusion impedance modeling for interdigitated array electrodes by conformal mapping and cylindrical finite length approximation”.

[Full report for this project]

Survival Rate Prediction Model for Startup Companies

This is an end semester project that I have done with my groupmates in college. In this study, we proposed a model to predict a startup company’s future condition using a deep multilayer perceptron (MLP) and decision tree. I mainly played the role for data quantification and literature review of this study. In our study, we built a prediction analysis model for startup companies. Furthermore, we identified what the key factors are and what influences will it have on the results. Our main hypothesis is that money, people and active days are the key factors. We built the prediction model from CrunchBase, which is the largest public database with relevant profiles about companies.

Data Quantification

For the data obtained, there are 4 groups of data that are quantified: country state, employee range, roles and countries. Regarding the states group (which only exists in USA and Canada), we think that different states have different impacts on the survival rate of a startup. A lookup table for scoring of states is defined [1][2][3]. The original data for employee quantities are a range between two numbers (e.g. 101-250). These are transformed into the average of the upper and lower bound. Employees of 10000+ are defined to be 15000. For the roles group, the data “company” is arbitrarily defined as 0.1 and “company, investor” is defined as 0.9. This is because we regard a company as wealthier and influential when it also plays a role of an investor, compared with only being a company. The other roles are transformed to 0.5. The impact of country on startup environment is also studied [4] and scores from 0.329 to 0.947 are given to countries that have above 300 startup companies in record.

Table 1. Company status and scores of 23 countries.

Country Closed Operating Acquired IPO  Score 
BRA4.7%90.1%4.5%0.6%0.329
ESP5.3%86.8%7.3%0.7%0.333
FIN3.6%82.9%12.6%0.9%0.340
ITA2.9%89.5%6.6%1.0%0.345
RUS6.0%87.5%4.7%1.8%0.379
KOR4.9%89.0%3.5%2.6%0.411
BEL4.3%80.6%12.3%2.8%0.419
NLD3.6%83.5%10.1%2.8%0.421
GBR5.2%81.4%10.5%2.9%0.423
DEU5.5%78.7%12.9%2.9%0.423
IRL5.8%78.9%12.0%3.3%0.443
DNK4.4%79.6%12.1%3.9%0.466
CHE2.7%83.3%10.0%4.0%0.471
SWE3.9%82.3%9.8%4.0%0.473
USA8.1%69.3%18.5%4.2%0.478
IND3.3%85.5%6.8%4.4%0.487
SGP3.2%85.5%6.5%4.8%0.507
FRA4.0%78.4%12.6%5.1%0.516
ISR5.4%74.7%13.7%6.2%0.563
JPN3.4%82.2%5.4%9.0%0.684
CAN5.0%70.6%13.3%11.1%0.769
CHN3.3%79.2%4.0%13.5%0.874
AUS3.3%77.1%4.4%15.3%0.947

Neural Network Implementation

The ANN runs on a Windows 10 OS (i7-8700k CPU) with DDR4 2666MHz 16G RAM and Nvidia GTX 1070 Ti GPU. Keras is used to construct the network, and three networks of multilayer perceptron (MLP) with different number of layers are designed for comparison. There are 4 outputs of the network, indicating the probabilities of the final status which are: (1) Closed, (2) Operating, (3) Acquired and (4) IPO.

Figure 1. MLP Structure of the 3 neural networks.

The three networks have respectively 2, 4 and 6 hidden layers, with each network all starting with a 1024-neuron hidden layer and ending with a 32-neuron hidden layer (Fig. 1). Table 2 shows the training results.

Table 2. Mean square error (MSE) and categorical cross-entropy loss for the 3 networks.

LossActivation Network 1 Network 2 Network 3 
MSEReLU0.6950.6940.689
MSEsigmoid0.6900.6900.691
MSElinear0.6920.6890.692
MSEtanh0.6880.6930.691
Cross-entropy loss ReLU0.6950.6910.690
Cross-entropy losssigmoid0.6920.6910.691
Cross-entropy losslinear0.6950.6920.690
Cross-entropy losstanh0.6910.6920.691

The results show that almost all results are close to 70% with few difference. In general, ReLU activation has a better result than sigmoid activation, while linear activation may outperform ReLU when the network is deep enough.

The neural network behaves like a black box. It is quite difficult to conclude significant insights just by looking at the trained parameters. However, regarding the importance for business, we used a decision tree to help us understand which factor is the most important and how important they are respectively.

Decision Tree Training

We tried three different depths of decision tree: 4 (Fig. 2), 6 (Fig. 3), and 10. We set the gain ratio to be the criterion, and the confidence to 0.1.

Figure 2. Decision tree of depth = 4.

Figure 3. Decision tree of depth = 6.

The results show that if a company is large enough to exceed 500 people, the close rates are low. In most cases, large companies are acquired by mergers and acquisitions. In addition to the number of employees, funding total amount also has a significant impact on whether a company eventually survives or closes.

Key Findings

Among the factors regarding the ability to survive of starting up companies, the factors such as the number of employees, funding total amount, and the active days have significant influences on the company’s survivability. On the contrary, the factors such as country, region or number of funding rounds do not have significant influences. Whether a company acts as an investor simultaneously will also have influences on whether the company will become an IPO or will be acquired.

Future Work

Our future work is expected to integrate the inspirative insight gained from our case study with the methodology of our own. Three items are listed as in the following:

  1. Construct a heterogeneous relationship network for survival rate prediction [5].
  2. Define a data path score according to HeteSim algorithm [6][7].
  3. Predict company survival rate using MLP, decision tree and other neural networks.
  4. Predict how much money a company will raise.

References

  1. Bill Murphy , The Start-up Hall of Shame (America’s 10 Worst States for Entrepreneurs), © 2018 Manuseto Ventures, inc.com/bill-murphy-jr/the-startup-hall-of-shame-americas-10-worst-states-for-entrepreneurs.html
  2. Bill Murphy , 10 Top States for Entrepreneurship and Innovation, © 2018 Manuseto Ventures, inc.com/bill-murphy-jr/ranking-the-10-top-states-for-entrepreneurship-and-innovation.html
  3. Enterprising States: States Innovate, © 2015 The U.S. Chamber of Commerce Foundation, www.uschamberfoundation.org/enterprisingstates/
    assets/files/Executive-Summary-OL.pdf
  4. Zameena Mejia, The top 10 best countries for entrepreneurs in 2018, © 2019 CNBC LLC,
    https://www.cnbc.com/2018/02/05/
    us-world-news-report-2018-top-10-best-countries-for-entrepreneurs.html
  5. Xiangxiang Zeng, You Li, Stephen C.H. Leung, Ziyu Lin, Xiangrong Liu, Investment behavior prediction in heterogeneous information network, Neurocomputing, Volume 217, 2016, Pages 125-132
  6. Sun, Y., & Han, J. (2012). Mining Heterogeneous Information Networks: Principles and Methodologies. Synthesis Lectures on Data Mining and Knowledge Discovery, 3(2), 1-159
  7. Shi, C., Kong, X., Huang, Y., Yu, P. S., & Wu, B. (2014). HeteSim: A General Framework for Relevance Measure in Heterogeneous Networks. IEEE Transactions on Knowledge and Data Engineering, 26(10), 2479-2492. [6702458].

Reinforcement Learning applied to Forex Trading

It is already well-known that in 2016, the computer program AlphaGo became the first Go AI to beat a world champion Go player in a five-game match. AlphaGo utilizes a combination of reinforcement learning and Monte Carlo tree search algorithm, enabling it to play against itself and for self-training. This no doubt inspired numerous people around the world, including me. After constructing the automated forex trading system, I decided to implement reinforcement learning for the trading model and acquire real-time self-adaptive ability to the forex environment.

Environment Setup

The model runs on a Windows 10 OS (i9-9900K CPU) with DDR4 2666MHz 16G RAM and NVIDIA GeForce RTX 2060 GPU. Tensorflow is used for constructing the artificial neural network (ANN), and a multilayer perceptron (MLP) is used. The code is modified from the Frozen-Lake example of reinforcement learning using Q-Networks. The model training process follows the Q-learning algorithm (off-policy TD control), which is illustrated in Fig. 1.

Figure 1. Algorithm for Q-learning and the agent-environment interaction in a Markov decision process (MDP) [1].

For each step, the agent first observes the current state, feeds the state values into the MLP and outputs an action that is estimated to attain the highest reward, performs that action on the environment, and fetches the true reward for correcting its parameters. The agent follows the epsilon-greedy policy (ε = 0.1) for striking a balance between exploration and exploitation.

State, Action and Reward

For the 1st generation, price values at certain time points and technical indicators are used for constructing the states. The technical indicators used are the exponential moving average (EMA) and Bollinger bands (N=20, k=2), and time frames of 1, 5 and 15min are used with the last 10 time points being recorded. A total number of 36 inputs are connected to the MLP.

There are three action values for the agent: buy, sell and do nothing. The action being taken by the agent is determined by the corresponding three outputs of the MLP, where sigmoid activation functions are used for mapping the outputs to a value range of 0 ~ 1, representing the probability of the agent taking that action.

For the reward function, the difference between the trade price (the price when a buy/sell action is taken) and the averaged future price is considered. If a buy action is taken, then the reward function is calculated by subtracting the averaged future price with the trade price; if a sell action is taken then the reward is calculated the other way around. For “do nothing” actions, the reward is 0. A spread is subtracted from the reward for buy/sell actions to obtain the final reward. This prevents the agent to perform actions that result in insignificant profit, which would likely lead to a loss for real trades (Fig. 2).

Figure 2. Reward calculation method for buy/sell actions.

Noisy Sine Function Test

For preliminary verification of effectiveness for the training model and methods, a noisy sine wave is generated with Brownian motion of offset and distortion in frequency. This means at a certain time point (min), the price is determined by the following equation:

$$P(t)=P_{bias} + P_{amp} sin{2\pi \over T}t+P_{noise}$$

where Pbias is an offset value with Brownian motion, Pamp is the price vibration amplitude, T is the period with fluctuating values, and Pnoise is the noise of the price with randomly generated values. (Note that the “price” mentioned here is defined as the exchange rate between two currencies)

Fig. 3 shows a randomly generated price vs time sequence within a range of 50,000 minutes with an initial values Pbias = 1.0, T = 120 min, Pamp = 0.005, and Pnoise amplitude = 0.001. Generally, the price seems to fluctuate randomly with no obvious highs or lows. However, if it is viewed close-up, waves with clear highs and lows can be observed (Fig. 4).

Figure 3. Price vs time of the noisy sine wave from 0 to 50,000 min.

Figure 4. Price vs time of the noisy sine wave from 20000 to 20600 min.

The whole time period is 1,000,000 min (approximately 700 days, or 2 years). Initially, a random time period is set for the environment. Every time the agent takes an action, there is a certain chance (= 1%) that the time will jump to another random point within the whole period. Otherwise, the time will move on to a random point which is around 1 ~ 2 day(s) in the future. This setting is expected to correspond to real conditions, where a profitable strategy can have stable earnings and can also adapt quickly to rapid changing environments.

Fig. 5 plots the cumulative profit for trading using the noisy sine wave signal for 50,000 steps. Although it took approximately 25,000 steps to make the model get “on track”, I recognize this result as an important start for implementing real data.

Figure 5. Cumulative profit from trading using a noisy sine wave signal.

Fundamental Analysis for Economic Events

Fundamental analysis is a tricky part in forex trading, since economic events not only correlate with each other, but also might have opposite effects on the price at different conditions. In this project, I extracted the events that are considered significant, and contain previous, forecast and actual values for analysis. Data from 14 countries of the past 10 years are downloaded and columns with incomplete values are abandoned, making a complete table of economic events.

Because different events have different impacts on forex, the price change after the occurrence of an event is monitored, and a correlation between each event and the seven major pairs (commodity pairs). Table 1 displays a portion of the correlation table for different economic events. The values are positive, which indicates the significance of an event on the currency pair. Here, a pair is denoted by the currency other than the USD (e.g. USD/JPY is denoted as JPY).

Table 1. Correlation table between 14 events and 5 currency pairs. Here, a pair is abbreviated as the currency other than the USD.

Country Economic Event (Index)AUDCADEURGBPJPY
AUDCommodity Prices0.00313 0.00268 0.00266 0.00339 0.00278
AUDMI Inflation Expectations0.003380.001680.002170.002000.00266
AUDRBA Interest Rate Decision0.004280.002620.002580.002980.00225
EURManufacturing PMI0.003310.002840.002630.002980.00278
EURItalian CPI0.003150.003190.002950.003160.00255
EURServices PMI0.003410.002900.002930.002950.00284
EURCPI0.003040.002940.002620.003170.00241
EURGerman Unemployment Rate 0.003150.003150.002730.003130.00246
EURECB President Trichet Speaks0.003440.002480.003410.003020.00268
EURGerman Unemployment Change 0.003130.003130.002680.003070.00243
EURGerman Trade Balance0.003060.002550.003000.002840.00268
EURGerman Factory Orders0.002920.002650.003120.002800.00275
EURGerman Retail Sales0.003040.003040.003530.003100.00275
EURFrench Trade Balance0.003120.003120.002960.003010.00299

A total of 983 events are analyzed. However, due to the fact that a large portion of events have little influence on the price, only 125 events that have a relatively significant impact are selected as the inputs of the MLP.

Real Data Implementation Results

Per-minute exchange rate data of the seven currency pair is downloaded from histdata.com. A period from 2010 to 2019 is extracted, and blank values are filled by interpolation. This gives us a total of approximately 23 million records of price data (note that weekends have no forex data records), and is deemed sufficient for model training. The data is integrated into a table, and technical indices are calculated using ta, a technical analysis library for Python built on Pandas and Numpy.

Figure 6. EUR/USD exchange rate from 2010 to 2019.

Summing the inputs from technical analysis, fundamental analysis, and pure price data, a total of 1049 inputs are fed into the MLP. Within the hidden layers, ReLU activation is used, and a sigmoid activation function is used for the output layer. The output has a shape of 7×3, which represents the probability of the seven currency pairs and the three actions (buy, sell, do nothing).

Fig. 7 shows the accumulative profit from 2,000,000 steps in a single episode and its win rate (percentage of profitable trades within a moving average). An increasing spread value from 0.00001 to 0.00004 is applied, which the spread value starts from 0.00001 and increases by 0.00001 every 50,000 step. It can be seen that overall, the accumulative profit rises steadily. However, the win rate usually falls below the 50% line. How could a profitable trading strategy be possible? This is due to the fact that the average profit of a winning trade (=0.003736) is larger than the average loss of a losing trade (=0.003581). Thus, the overall result is a profitable trading strategy.

Figure 7. Accumulative profit and win rate from the training procedure of 2,000,000 steps.

Conclusion

In conclusion, a trading model for profitable forex trading is developed using reinforcement learning. The model can automatically adapt to dynamic environments to maximize its profits. Although for real conditions that have a larger spread, the model hasn’t achieved a stable and profitable result, the potential for optimizing is promising. In the future, I am planning to integrate this trading model with the automated forex trading system that I have made, and become a competitive player in this fascinating game of forex.

[Source code of RL model training section]

References

[1] R.S. Sutton, A.G. Barto, Reinforcement Learning: An Introduction, MIT Press2018.

Remote Commandable Self-Driving Toy Car

This project is an integration of computer vision, mechatronics, wireless communication (Bluetooth), database management, mobile app design, sensors and actuators, and is a final project of a course called Design of Automated Systems. I teamed up with two classmates for accomplishing this challenging task of constructing a remote commandable car that can automatically detect and find balls with different colors, then be manually navigated towards a certain location. My contributions to this project are coding the ball-tracking algorithm using OpenCV, utilizing the microcontroller Arduino for movement control, and wiring electric components to the hardware circuit (yellow shaded area in Fig. 1).

System Architecture

Fig. 1 illustrates the system architecture for this project. Raspberry Pi is used as the main computer. Node.js is installed for communicating with the MariaDB database, receiving ordering signals from a remote Android app, and commanding the ball-tracking C++ program.

Figure 1. System architecture of the remote commandable self-driving toy car.

A standard procedure for command and action of the system is as follows.

  1. Android user logins to Node.js server by verification of username and password through the database.
  2. The user sends target ball color to the server.
  3. The server sends command to “face_ball” program by bash.
  4. “face_ball” detects colored ball position by ball recognition algorithm.
  5. “face_ball” sends command to Arduino by serial USB.
  6. Arduino controls two servo motors for the car to move towards the target ball.
  7. After getting close enough, a fence is set to physically trap the ball.

Hardware Design

Fig. 2 shows a 3D drawing of the toy car. Components such as Arduino, Raspberry Pi (RPi) are fixed to the laser-cut acrylic board using plastic columns. Here, three servo motors are used. The first two controls the left/right wheel, and the third controls a trap that can lock the ball at the front of the car.

Figure 2. 3D illustration of the remote commandable toy car.

Figure 3. Preliminary version of the toy car.

Ball-Tracking Program

The main objective of the ball-tracking program is to navigate the toy car towards a target ball, and trap it with a fence connected to the toy car. The flowchart for image recognition of the ball is shown in Fig. 4.

Figure 4. Flowchart for the ball detection algorithm.

Using the above algorithm, rapid detection of the target ball can be realized. Here’s a demonstration of the program recognizing a ball being thrown in the air in real-time.

For movement control of the toy car, the Arduino will either turn left, turn right, or move straight according to the control algorithm shown in Fig. 5.

Figure 5. Flowchart for the ball-trapping algorithm.

[Source code for the ball-tracking program]

Arduino Commands

Fig. 6 shows the commands available for controlling the toy car using Arduino.

Figure 6. Available commands for Arduino.

Here’s a clip for automated control of the toy car. A red ball is defined as the target and is trapped by the car using a fence.

Android App Design

The app is designed using MIT App Inventor, which implements a block-based programming method in which developers can create procedures by dragging predefined blocks together to for performing a certain function. Fig. 7 shows an image containing the complete code for the Android app. The user interface and flowchart for direct control of the toy car is shown in Fig. 8.

Figure 7. Complete block code for the Android app (click for magnified view).

Figure 8. App interface (left) and Arduino control flowchart (right).

Here’s a demonstration for the remote commandable toy car. The car automatically detects a green ball, moves near, and traps it. Then it is manually controlled to avoid obstacles and reach a yellow-colored area at the end.

Electrochemical Impedance Modeling Programs

I started to use a technique called electrochemical impedance spectroscopy (EIS) for biosensing since my undergraduate research. For analyzing EIS data, an equivalent circuit must be constructed for modeling the reaction mechanism. Physical parameters can be extracted by fitting the data using the model. However, for most software, the circuit elements being provided and their corresponding combined circuit couldn’t necessarily meet my needs for finding the physical parameters in a symmetric electrode system. Therefore, I developed a circuit fitting program for customized analysis of impedance data. The fitting and impedance calculation program are used in a first-author journal paper of mine. In the following paragraphs, the development of the fitting program, another program that assists data visualization, and a program for calculating the diffusion impedance of interdigitated array (IDA) electrodes are detailed.

Figure 1. (a) The Nyquist plot for visualizing impedance values, and (b) an equivalent circuit with several circuit elements for modeling electrode surface reactions.

Electrochemical Impedance Circuit Fitting Program

The algorithm for finding all the element parameters in a given circuit is by implementing the Levenberg-Marquardt non-linear fitting method. This is a general and popular method for solving the minimum value of function E(x), where

$$E(x)={1 \over 2} \sum_{i=1}^m [f_i(x)]^2 $$

For impedance data fitting, a complex non-linear least square process (CNLS) is implemented, and the above equation can be specialized as

$$S=\sum_{i=1}^{N_f} [w_{i,\mathrm{Re}}( \mathrm{Re}(Z_{i,cal}) – \mathrm{Re}(Z_{i,exp}) )^2+w_{i,\mathrm{Im}}( \mathrm{Im}(Z_{i,cal}) – \mathrm{Im}(Z_{i,exp}) )^2]$$

where S is the weighted sum of squares of error, Nf is the number of frequencies within an experiment, Zi is the impedance of the i–th frequency, and wi,Re and wi,Im are the statistical weights for the real and imaginary parts of the impedance of the i–th frequency. The subscript exp indicates experimental value and the subscript cal indicates the calculated value while fitting.

For any kind of circuit, Zi,cal can be calculated by the set of element parameters and the frequency (e.g. R for a resistor, C and f for a capacitor), then S can be calculated using its defined equation. By minimizing S, the fitted element parameters can be modified so that the result impedance (Zi,cal) can be as close as possible to the experimental value (Zi,exp). Fig. 2 shows an example for a non-linear curve fitting process.

Figure 2. A non-linear curve fitting process (source: https://en.wikipedia.org/wiki/Gauss%E2%80%93Newton_algorithm).

A program written in C language is designed using the open-source numerical analysis library ALGLIB® to implement numerical integrations and calculations. ALGLIB is also used for non-linear least squares fitting of EIS data using Levenberg-Marquardt method. Several circuit elements for EIS data fitting are available in this program, which are shown in Table 1. Detailed methods for calculating the IDA diffusion element is shown in my first-author paper.

Table 1. Available circuit elements in the fitting program.

A circuit description code is defined to express equivalent circuits. Elements, including whole blocks inside parentheses, are either in series or parallel with each other. Those inside an odd number of pair of parentheses are in parallel with each other, and those inside an even number of pair of parentheses are in series. Fig. 3 shows a circuit equivalent to the description code of “R(RC)(R(RC))”.

Figure 3. Circuit description code and its corresponding circuit. Equivalent parts are marked by identical colored blocks.

Figure 4. Snapshot of the equivalent circuit fitting program.

[Download equivalent circuit fitting program (Runs on Windows 64-bit environment)]

[Source code for the equivalent circuit fitting program]

Real-time Impedance Plotting Program

It is reasonable that an element in a circuit contributes to the impedance change to a certain degree. For instance, a resistor has an influence on the real part of impedance, and a capacitor affects its imaginary part. However, when the circuit consists of elements with serial or parallel combinations, it can be quite difficult to imagine how the shape of impedance data would change according to each element.

Therefore, I wrote a program for plotting impedance data in real-time using Processing language. After entering the circuit description code into the program, a Nyquist plot, total impedance Bode plot, and phase angle bode plot is generated. The user can use horizontal bars to control the value of a specific element. By changing its value, the impedance would be calculated immediately, and the plot would be drawn out in real-time.

Figure 5. User interface for the real-time impedance plotting program.

Here’s a clip for demonstrating the real-time impedance plotting program.

[Source code for real-time impedance plotting program]

IDA Diffusion Impedance Calculation Program

The IDA diffusion element is a novel element for parameterizing the diffusion impedance of an IDA electrode using its shape factor (we/w), magnitude of the admittance (Y0), and the dimensionless frequency (w2ω/D). However, complex functions are required for calculating its value, such as the Bessel function, the complete elliptic integral of the second kind, and definite integrals.

Due to calculation difficulties, a program is written for calculating the IDA diffusion impedance. The program consists of two files “settings.txt” and “IDA_diff_Z.exe”. “settings.txt” is of the format below:

These contain all the 12 parameters for the usage of this program. A detailed description is listed in order below:

  1. If [output to txt file] is 0, then calculated impedances will be shown directly on screen. If it is 1, then the values will be saved to the file “Z_diffusion_IDA.txt”.
  2. The maximum frequency for impedance calculation can be set after [max freq (Hz)].
  3. The minimum frequency for impedance calculation can be set after [min freq (Hz)].
  4. The number of frequency points within a decade can be set (e.g. If [points per decade] is set to 5, then frequencies calculated between 101 and 100Hz will be 101, 100.8, 100.6, 100.4, 100.2 and 100Hz.)
  5. we can be set after [electrode bandwidth we (um)].
  6. wg can be set after [gap width wg (um)].
  7. l can be set after [electrode length l (mm)].
  8. N can be set after [number of bands N].
  9. D can be set after [diffusion coefficient D (m^2/s)].
  10. C* can be set after [bulk concentration C* (mM)].
  11. n can be set after [number of electrons n].
  12. T can be set after [temperature T (K)].

After setting the 12 parameters, put “settings.txt” and “IDA_diff_Z.exe” in the same directory and open “IDA_diff_Z.exe”. Impedances will be automatically calculated and printed in the defined format (Fig. 6). ※The program can only be run in a Windows 64-bit environment.

Figure 6. An example output of the IDA diffusion impedance calculation program.

[Download IDA diffusion impedance calculation program]

Minesweeper AI

I got addicted to Minesweeper the first few days when I started playing this awesome puzzle game. Solving the game faster every few times gives me great satisfaction of self-fulfillment. However, for the “expert” board setting, where 99 mines are hidden within a 16×30 square grid, I had never obtained a score lower than 100 seconds. Curious of what the fastest solving rate is the one can achieve, I designed a Minesweeper AI program that can automatically play the Windows Minesweeper game.

C language is used for programming, and the algorithm flowchart is displayed in Fig. 1.

Figure 1. Algorithm flowchart of the Minesweeper AI program.

Here breadth-first-search (BFS) is used to search for uncovered squares on the grid, and a queue is used for saving uncovered squares to be analyzed. A game-playing optimized algorithm is written inside the program, and OpenCV is used to take a snapshot of the Minesweeper window region and process the image for subsequent calculations. Mouse movement and click actions are realized by including the windows.h header.

The usage of the program is relatively simple. The user should only execute the Minesweeper game program, and modify the game setting beforehand. After opening the AI .exe file, the program will automatically locate the Minesweeper game, calculate the dimensions, then start playing. If a mine is accidentally clicked, the program will continue to play the next game until a fully uncovered board is achieved.

Here is a clip demonstrating the Minesweeper AI playing an expert level game and winning in 7 seconds. It failed on the first try almost at the end, but succeeded on the second try.

[Download program for the Minesweeper AI (Can only run on a windows 64-bit OS)]

Linear Algebra Calculation using Integrated Circuits

Even the simplest thing we recognize may seem increasingly difficult in another point of view. Take a simple arithmetic operation for example, if one wants to calculate the function y = ax + b with given a and b, he simply multiplies any number x with a, then adds b, and gets the answer. What if no multiplication and addition can be used? How can the calculation even be possible?

Computers can actually finish the task by implementing three fundamental logic operations: AND, OR, and NOT. Most of them can do these operations within a nanosecond. In this project, I constructed a circuit for performing a simple linear algebra calculation (Fig. 1) using only basic logic and storage circuits (Fig. 2) that can be realized using standard cells.

Figure 1. Formula to be calculated. (x0, x1, x2 are all 6 bit 2’s complementary integers)

Figure 2. Basic logic and storage circuits. (Note that other circuits (e.g. NAND, XOR) are also used in this project)

Here, x0, x1 and x2 equal the three 6-bit integer inputs (2’s complementary), so there are a total of 18 Boolean input values. The output is stored in a 16-bit integer. Therefore, the goal for this project is to construct a circuit that connects all of the 18 inputs and the 16 outputs, and perform the calculation.

To make it harder, three stages of pipelines are carried out. This means that calculations are divided into three parts, and the most time-consuming part contains the critical path of the whole circuit. Fig. 3 shows an illustration of the designed circuit.

Figure 3. Logic circuit diagram for realizing the arithmetic operation (Fig. 1) of this project.

Verilog is used for simulating the results, and the circuit is written as a spice sub-circuit model. Because the D flip-flop is used, the critical time is defined as the clock cycle of the D flip-flop. Moreover, the number of transistors are defined for every basic logic circuit, so the total number of transistors can be calculated, and is named the “area” of the whole circuit.

Fig. 4 shows the simulation results of the circuit. It can be seen that only 1.3305 nanosecond is used for a half clock cycle of the circuit. This means that the circuit can continuously output calculation results every 2.661 nanosecond, which is really fast!

Figure 4. Simulation results using Verilog.

Having the experience of using absolutely no arithmetic operations for calculating a linear algebra problem really significantly broadened my insight towards digital IC design. This project inspired me to understand that even the most insignificant elements possess the potential to be combined and make up the world that we live in.

[Verilog Source Code for Logic Circuit]

Robot Arm Control

It’s easy for us to point at a certain coordinate in space. That’s mainly because we simply locate the point with our eyes, and continuously check if our finger is pointing at that very spot. It surely will be more difficult without using eyes, and this is the case for robot arm control with no image feedback.

Think of a two arm robot (Fig. 1). We usually want to reach a certain point on the x-y plane. The problem is only the angle of the joints can be controlled. How can we correlate the joint angles of a robot with its tip coordinate? Things get harder when it comes to 3D space, and even harder considering its rotation.

In this project, I created a program that can calculate the every joint angle of the 6-arm robot IRB140 for positioning it at a given (x, y, z) coordinate and rotation.

Figure 1. Dimensions of the IRB140 robot (unit: mm) [1].

The problem for reversing an operation from the specified coordinate and rotation to every rotation angle of an arm joint lies in the field of inverse manipulator kinematics. There may be multiple solutions that lead to the same result. Thus, I implemented the Pieper’s solution [2] for solving the joint angles for the IRB140 robot.

Here’s a video demonstration for precision control of the IRB140 by only giving the joint angles as the input. The robot follows a trail surrounding a paper box with the tip of the last arm always pointing at the center of the box.

[Source code for robot arm control program]

1. ABB, IRB140 product specification, 2019, https://library.e.abb.com/public/2893a5756d204e19aba0d37c2a2cadc6/3HAC041346%20PS%20IRB%20140-en.pdf
2. Craig, J.J., Introduction to Robotics: Mechanics & Control. 1986: Addison-Wesley Publishing Company.

Guess the Number AI

After completing the first two projects of the Guess the Number series (Guess the Number (Windows) and Guess the Number (iOS)), I made an AI that can play this game at a high-human level.

It has been proven that at most 7 turns are needed to guess the answer, with a best average game length of 5.21 turns. For this game, all the possible combinations (e.g. “0123”, “7381” …) can be saved into a 1D array. After each guess, the possible combinations for the answer will be reduced. Therefore, the algorithm of the program is written for finding a number that will minimize the maximum possible combinations left. The time complexity for each turn is O(n3), and an average of 5 turns of guessing if needed for an arbitrarily chosen number.

For using the program, the user must first choose a 4-digit answer (e.g. “0123”), and input the two numbers [A] and [B] according to the game rules and the numbers guessed by the program. For instance, if the answer is “1357”, and the AI guesses “3127”, the user must input 1 2 ([A] = 1, [B] = 2).

Here’s a demonstration of the AI program guessing the answer “8192” in 5 guesses:

[Download Guess the Number AI program]

[Source code for the Guess the Number AI program]