# A Cosine Similarity Algorithm Method for Fast and Accurate Monitoring of Dynamic Droplet Generation Processes

## Abstract

Droplet microfluidics has attracted significant interests in functional microcapsule synthesis, pharmaceuticals, fine chemicals, cosmetics and biomedical research. The low variability of performing chemical reactions inside droplets could benefit from improved homogeneity and reproducibility. Therefore, accurate and convenient methods are needed to monitor dynamic droplet generation processes. Here, a novel Cosine Similarity Algorithm (CSA) method was developed to monitor the droplet generation frequency accurately and rapidly. With a microscopic droplet generation video clip captured with a high-speed camera, droplet generation frequency can be computed accurately by calculating the cosine similarities between the frames in the video clip. Four kinds of dynamic droplet generation processes were investigated including (1) a stable condition in a single microfluidic channel, (2) a stable condition in multiple microfluidic channels, (3) a single microfluidic channel with artificial disturbances, and (4) microgel fabrication with or without artificial disturbances. For a video clip with 5,000 frames and a spatial resolution of 512 × 62 pixels, droplet generation frequency up to 4,707.9 Hz can be calculated in less than 1.70 s with an absolute relative calculation error less than 0.08%. Artificial disturbances in droplet generation processes can be precisely determined using the CSA method. This highly effective CSA method could be a powerful tool for further promoting the research of droplet microfluidics.

## Introduction

Recently, droplet microfluidics is becoming an enabling technology in synthesizing novel materials1,2, such as microgels3,4,5, microspheres6,7, microcapsules8 and quantum dots9,10, thus have broad impact in pharmaceutics11, fine chemicals12, cosmetics13 and biomedical research14,15. The production of these microscale particles has benefited from the highly uniform droplets generated with the droplet microfluidics16, as a low variability of performing chemical reactions inside the droplets could benefit from improved homogeneity and reproducibility17. Typically, the uniformity of a droplet generation process is evaluated by the particles’ size distributions after the completion of the process18,19. However, various parameters related to the dynamic droplet generation process will result in broader droplet size distributions20. Therefore, it is important to develop accurate and convenient methods to monitor dynamic droplet generation processes.

A series of electrical methods were proposed using dielectric properties of emulsions to monitor dynamic generation processes. One of the methods is to embed microelectrodes in microfluidic devices to sense the impedance variations of passing droplets. For instance, Niu et al. fabricated 3-D microelectrodes with multi-step photolithography in a microfluidic channel to measure droplet-induced impedance variations21. Elbuken et al. fabricated non-contact planar microelectrodes on a glass substrate through a lift-off process to measure impedance changes as droplets passing through the channel22. Also, radio frequency (RF) devices were applied to monitor droplet generation processes by sensing the changes in resonance frequencies. RF devices were capable of detecting subtle changes in dielectric properties in microfluidic channels23. Conchouso et al. used RF devices to monitor droplet generation processes in a multi-channel way16,24. Although these electrical methods were capable of monitoring both single and multi-channel droplet generation processes, the complexity of chip fabrication and system setup was increased by the requirement of embedded microelectrodes and specialized detection systems.

Another kind of approach to monitoring dynamic droplet generation process is microscopic imaging. These methods use droplet generation video clips acquired by a high-speed camera, which is widely used in a droplet microfluidics experimental system, including droplet generation25, observation26, and sorting27. To keep close tracking of droplets, the high-speed camera is configured at a frame rate over two times of droplet generation or motion frequency. Vladisavljević et al. and Park et al. monitored the droplet generation processes by manually analyzing the microscopic videos28,29. This laborious method is simple and straightforward but with limited accuracy. Beer et al. monitored droplet generation processes by calculating the changes in light intensity of an area covered by passing droplets30. However, this automatic method is not suitable for monitoring droplet generation processes in multiple channels. Basu proposed a method based on droplet morphometry and velocimetry (DMV) for monitoring droplet generation processes by recognizing droplet interfaces in every frame of the video31. Though the DMV method provided various parameters to monitor droplet generation processes, recognizing droplet interfaces in every video frame may require a sizeable computational resource, and the monitoring may not keep pace with droplet generation processes. In general, though microscopic imaging methods do not require specialized equipment or elaborate chip fabrication, they are not capable of monitoring dynamic droplet generation processes in an accurate and online manner.

Many progress has been made to monitor the dynamic droplet generation processes. However, accurate, convenient and online methods have rarely been described. In this paper, we proposed a novel cosine similarity algorithm (CSA) method for automatic monitoring of dynamic droplet generation processes. Through acquiring microscopic video clips of droplet generation processes, the CSA method was able to calculate droplet generation frequency distributions from the periodic changes of cosine similarities between video frames. Both differences among multiple channels and changes along the timeline could be closely monitored by the CSA method in a fast, convenient and accurate manner with differences among frequency peaks and changes in frequency distributions. To the best of our knowledge, this is the first time that cosine similarity has been applied to monitor dynamic droplet generation processes in droplet microfluidics, and this highly effective method could be a powerful tool for further promoting the research and development of droplet microfluidics.

## Results and Discussion

### Schematic Diagram of the Cosine Similarity Algorithm (CSA)

Typically, cosine similarity is applied to characterize the similarity between two images, which is widely used in various image-processing applications, such as face recognition32 and template matching33. As shown in Fig. 1, the CSA method consists of four steps. First, a microscopic droplet generation video clip is captured at a constant frame rate with a high-speed camera. Second, frames of the same spatial resolution are extracted from the acquired video clip. Among these frames, one of them is designated as the reference frame. The cosine similarity is calculated between the reference frame and each frame in the video clip, including the reference frame with itself. Third, a periodic similarity vector is constructed to combine the calculated similarities with the frame indices in ascending order. Since a stable droplet generation process is highly periodic, the similarity vector oscillates with the periodic reappearance of the reference frame. Finally, cyclic auto-spectrum is calculated with fast Fourier transform (FFT) to obtain the frequency distribution of the similarity vector, through which the mean value and coefficient of variation (CV) of the droplet generation frequency can be calculated from the further spectral analysis.

### Principle of CSA

Mathematically, cosine similarity between two non-zero vectors a and b is defined as the cosine of the included angle 〈a, b34, which is given by equation (1):

$$S({\bf{a}},\,{\bf{b}})\triangleq \,\cos \langle {\bf{a}},\,{\bf{b}}\rangle =\frac{{{\bf{a}}}^{{\rm{T}}}{\bf{b}}}{{\rm{\Vert }}{\bf{a}}{\rm{\Vert }}{\rm{\Vert }}{\bf{b}}{\rm{\Vert }}}.$$
(1)

The range of cosine similarity is determined by the cosine function: S(a, b) [−1, 1]. The larger the |S(a, b)|, the higher the non-zero vectors a and b are linearly correlated (“similar”). For two grayscale frames with the same spatial resolution, cosine similarity can be used to characterize the similarity between the frames35. The grayscales of the pixels in each frame can be arranged into a grayscale vector in a specific order. For instance, for a grayscale frame (spatial resolution: m × n pixels) with index i in which the grayscale of pixels are defined as H(p, q, i), p = 1, 2, …, n, q = 1, 2, …, m, the grayscale vector h(i) can be defined as shown in equation (2):

$${\bf{h}}(i)\triangleq [\begin{array}{c}H(1,1,i)\\ H(1,2,i)\\ \vdots \\ H(1,m,i)\\ H(2,1,i)\\ H(2,2,i)\\ \vdots \\ H(2,m,i)\\ \vdots \\ H(p,q,i)\\ \vdots \\ H(n,1,i)\\ H(n,2,i)\\ \vdots \\ H(n,m,i)\end{array}].$$
(2)

Figure 2a illustrates a simplified example of four grayscale frames (spatial resolution: 2 × 1 pixels) with indices i = 1, 2, 3, 4. A grayscale vector of each frame can be defined according to equation (2). If frame 1 is designated as the reference frame (with index defined as r), then the cosine similarities between each of the four frames and the reference frame can be calculated as the cosines of the included angles illustrated in Fig. 2b. As shown in Fig. 2c, the highest similarity of 1.00 is between the reference frame and itself. The similarity between the reference frame and each frame is positively correlated with the calculated cosine similarity: the more similar the frames, the higher the cosine similarity.

Similarly illustrated in Fig. 2d, four grayscale frames (resolution: 512 × 62 pixels) with indices n1, n2, n3 and n4 are selected along the timeline of a droplet generation video clip. Frame 1 of the video clip is designated as the reference frame (with index r = 1), and the similarities between each of the four frames and the reference frame are calculated (Fig. 2e). Notably, the similarity between the reference frame and frame n4 (0.9999) is higher than those between the reference frame and the other frames (0.9902, 0.9855, 0.9906, respectively for frame n1, n2, and n3), indicating the reappearance of the reference frame along the droplet generation process.

Our hypothesis is that a stable droplet generation process is a highly periodic process. Once a reference frame is designated and the cosine similarities are calculated between the reference frame and each frame in the video clip, a cosine similarity vector is constructed with these calculated similarities. The value of the cosine similarity in the vector oscillates periodically. Thus, the oscillating frequency of the similarity vector, which is correlated with droplet generation frequency, can be derived from further spectral analysis. The detailed mathematic derivation can be obtained at supplementary methods in the supplementary information.

### Four kinds of dynamic droplet generation processes were monitored using CSA

With the novel CSA method, four kinds of dynamic droplet generation processes were monitored. The CSA method was applied (1) to calculate droplet generation frequency in a stable condition in a single microfluidic channel, (2) to calculate non-overlapping droplet generation frequencies in a stable condition in multiple microfluidic channels simultaneously, (3) to monitor the droplet generation process with artificial disturbances in a single microfluidic channel, and (4) to monitor pre-microgel droplet generation processes online.

### Case 1. Droplet generation process in a stable condition in a single microfluidic channel

Using the CSA method, accurate calculation of droplet generation frequency’s mean value and CV can be obtained for a droplet generation process in a stable condition in a single microfluidic channel (Table S1). Typically, there are three different droplet generation modes in a stable droplet generation process, including squeezing, dripping and jetting36. As shown in Fig. 3a, two flow rate configurations (fixed flow rate ratio and fixed flow rates) were used to evaluate the performance of the CSA method in these droplet generation modes.

As shown in Fig. 3b, droplet generation frequency increased from 90.1 Hz to 4,707.9 Hz as the total oil and water flow rate increased from 1.5 mL/h to 22.5 mL/h, with an oil/water flow rate ratio fixed at 2:1. The droplet generation mode switched from squeezing to dripping, and then to jetting at critical droplet generation frequencies of 1,481.6–1,874.8 Hz and 3,287.3–3,614.2 Hz, respectively. When the water flow rate was fixed at 0.6 mL/h, droplet generation frequency increased from 67.3 Hz to 110.2 Hz in the squeezing mode as the oil/water flow rate ratio increased from 1:1 to 2:1. However, when the oil flow rate was fixed at 12 mL/h, droplet generation frequency increased from 892.0 Hz to 3,563.1 Hz in the dripping and jetting modes as the oil/water flow rate ratio decreased from 10:1 to 2:1.

With the CSA method, the calculation is fast and accurate. As shown in Fig. 4a, the average computational time was 1.63 s for a video clip with 5,000 frames at a resolution of 512 × 62 pixels, with a computation speed of about 3,000 frames per second (fps). As shown in Fig. 4b, the absolute relative calculation error of droplet generation frequency was less than 0.08% compared with that obtained by the manual counting-timing method. Figure 4c showed that the average CV of droplet generation frequency of the dripping mode was 0.35%, which was smaller than that of the squeezing and jetting modes, although the differences were not statistically significant. It suggested that droplets generated in the dripping mode were more uniform than those generated in the other two modes. This conclusion is in accordance with the average droplet diameter’s CV in the published literature37.

### Case 2. Droplet generation process in a stable condition in multiple microfluidic channels

The CSA method can also be used to evaluate droplet generation frequencies in a stable condition in multiple microfluidic channels (Table S2), a widely used droplet microfluidic technique for specific applications38,39.

As shown in Fig. 5a, three droplet generation processes with different flow rates (low, medium and high) in a stable condition in single microfluidic channels were analyzed with the CSA method, and the calculated droplet generation frequencies were 410.4 Hz, 1,584.3 Hz, and 1,921.0 Hz, respectively, with no overlapping in the cyclic auto spectrum. Next, to mimic the droplet generation process in multiple microfluidic channels, two video clips were reconstructed: a double-channel droplet generation process and a triple-channel droplet generation process. For a double-channel droplet generation process, two single-channel droplet generation video clips in a stable condition were combined to form a video clip of two parallel microfluidic channels with the same width. The CSA method generated an auto-spectrum with two distinctive peaks at 409.7 Hz and 1,578.5 Hz in a single run. For a triple-channel droplet generation process, three single-channel droplet generation video clips in a stable condition were zoomed, rotated and combined to form a video clip of three microfluidic channels with different widths and directions. The CSA method generated an auto-spectrum with three distinctive peaks at 409.7 Hz, 1,584.9 Hz, and 1,920.4 Hz in a single run. Therefore, the cyclic auto spectra of both configurations yielded droplet generation frequencies consistent with the corresponding single-channel droplet generation processes that made up the video clips.

The CSA method can obtain multiple droplet generation frequencies in a single run. The reason is that partial similarity between two frames contributes to the cosine similarity between them, so each of the microfluidic channels makes corresponding oscillating contributions to the similarity vector at their own, non-overlapping frequencies. These contributions will be converted into different frequency peaks in the cyclic auto-spectrum.

As shown in Fig. 5b, the average computational time of CSA was approximately proportional to the number of frames and spatial resolution of the video clip. For video clips with a spatial resolution of 512 × 62 pixels and 1,000 frames, which is 20% of the number of frames in case 1, the average computational time was 0.37 s, which was 23% of the computational time in case 1. The two reconstructed video clips increased the spatial resolution to about four and eight times of the original spatial resolution, resulting in an increase in computational time from 0.37 s to 1.60 s and 3.11 s respectively, which were 4.3 and 8.5 times of the computational time for a video clip with a spatial resolution of 512 × 62 pixels.

As shown in Fig. 5c, the absolute relative calculation error for the single microfluidic channels was less than 0.21%, and the error for the multiple microfluidic channels was less than 0.56%. The calculation results of the two droplet generation processes in multiple microfluidic channels were referred to the frequencies of their corresponding single-channel processes for the calculation of relative calculation error. Notably, the largest absolute relative error, in this case, was larger than that in case 1 (0.08%). This was due to the reduction of the number of frames in a video from 5,000 in case 1 to 1,000 in this case, which resulted in a reduction in the spectral resolution to 20% compared with that in case 1. Due to the reduction in spectral resolution, the absolute relative calculation error was accordingly expected to increase up to five times of the calculated error in case 140, which was 0.40% in this case. As shown in Fig. 5c, the absolute relative calculation error in this case for single-channel processes was less than 0.21%, which was less than the maximum error of 0.40%. Furthermore, since reconstruction of video clips did not result in a linear addition of similarity vectors, crosstalks between frequency components (both fundamental and harmonic frequencies) might result in an increase in the absolute relative calculation error, which could lead to an increase in the error from 0.21% to 0.56% for droplet generation processes in the multiple microfluidic channels.

### Case 3. Droplet generation process with artificial disturbances in a single microfluidic channel

Using the CSA method, droplet generation process with artificial disturbances in a single microfluidic channel have been closely monitored, with the periods affected by the disturbances precisely determined (Table S3). Artificial disturbances can be introduced into droplet generation process by changing the oil or water flow rates, which resulted in droplet size variation, generation frequency and spacing41.

As shown in Fig. 6a, a droplet generation process with changing oil flow rates was used to investigate droplet generation process in a single channel with artificial disturbances. The whole process included three stable stages separated by two artificial disturbances, with each stable stage of 5.50 min and each disturbance stage of 5.00 s. As shown in Fig. 6b, changes in droplet generation frequency could be monitored closely at an interval as short as 2.50 s (the duration of the process in a video clip) with the CSA method. Over the course of the droplet generation process, droplet generation frequency’s mean value calculated with the CSA method synchronized with the measured mean droplet generation frequency without delay. As shown in Fig. 6c, an increase in droplet generation frequency’s CV was observed twice, from an average of 1.63% to 9.99%, which was consistent with the two periods affected by the disturbances. As shown in Fig. 6d, the average computational time was 1.64 s, which was not affected by the disturbances, because the CSA method did not differentiate any graphical feature in the video clip. As long as the disturbances did not affect the computational scale (for example, number of frames and spatial resolution), it did not affect the CSA computational time.

Thus, a droplet generation process with artificial disturbances can be closely monitored with the CSA method. The calculated mean frequency changes promptly after a change in the actual droplet generation frequency, and the CV indicated whether the droplet generation process is disturbed.

### Case 4. Pre-microgel droplet generation processes with or without artificial disturbances

Microgel is widely used in biology42,43,44 and material science45,46 because of its good biocompatibility and deformability47. Highly monodispersed pre-microgel droplets can be generated in a high-throughput manner48, and they serve as a prerequisite for the fabrication of highly monodispersed microgels49. Droplet generation frequency is a very effective parameter to closely monitor dynamic microgel generation processes.

As shown in Fig. 7a, two microgel generation processes were investigated with the CSA method: one without artificial disturbances, and the other with intentional interruptions of oil and water injection (once each) as artificial disturbances. The two processes were monitored based on both droplet generation frequency and droplet size (Table S4). Droplet generation frequency and its CV were monitored with the CSA method, and the droplet size and its CV were calculated with a custom Matlab program. Although the disturbances did not change the droplet diameter’s mean value drastically (116.1 μm and 117.2 μm for the two processes respectively, as shown in Table S5), they significantly increased the droplet diameter’s overall CV, from 2.77% to 6.59%, resulting in a wider size distribution and lower monodispersity.

As shown in Fig. 7b,c, droplet generation frequency’s CV varied synchronously with both periods affected by the interruptions of oil and water injection, while droplet diameter’s CV varied synchronously with the period affected by the interruption of oil injection only. Similar to case 3, the droplet generation frequency’s CV revealed all the disturbances. In the process without disturbance, the droplet generation frequency’s CV remained stable, and so did the droplet diameter’s CV. On the contrary, in the processes with artificial disturbances, the droplet generation frequency’s CV varied synchronously with both periods affected by the disturbances, but the droplet diameter’s CV did so with only one.

The reason why the changes in droplet diameter’s CV failed to reveal both disturbances is that the droplet diameter is mainly related to the oil flow rate50. During the interruption of water phase injection, droplet diameter did not undergo changes large enough for an obvious increase in droplet diameter’s CV. In contrast, droplet generation frequency is related to both oil and water flow rates50, and the interruption of oil or water injection managed to change droplet generation frequency to an extent large enough for an obvious increase in droplet generation frequency’s CV. In this way, droplet generation frequency’s CV serves as a better parameter than droplet diameter’s CV to indicate interruptions of oil or water injection, which may be encountered in various cases during a pre-microgel droplet generation process, including power failure, equipment glitches, depletion of oil or water phase and clogging of microfluidic channels.

The current CSA method is an online approach, which updates computational results of droplet generation frequency at a designated interval (for example, every 2.50 s). It should be a great improvement if the CSA method could monitor droplet generation frequency in real time. In order to achieve real-time droplet generation frequency monitoring, a few modifications are needed for the CSA method. First, two data buffers with specific sizes are set up to store captured video frames and the cosine similarities between the respective video frames and the reference frame. The calculated cosine similarities form a similarity vector. Both data buffers are “first in, first out” (FIFO) buffers. For instance, a FIFO data buffer is configured to store 5,000 video frames maximally. Before the data buffer is filled up with 5,000 video frames, there is a build-up phase in which newly captured video frames are stored in the data buffer continuously. Once the data buffer is full of 5,000 video frames, it switches to a real-time phase with the “first in, first out” principle. For instance, a 5,001st video frame is stored into the data buffer synchronized with the deletion of the 1st video frame. The same principle is also applied for the data buffer storing respective calculated cosine similarity between the newly acquired frame and the reference frame. During the build-up phase, the number of data buffer with calculated cosine similarities increases, but the calculated cyclic auto-spectrum and droplet generation frequency have limited accuracy due to insufficient data. While during the real-time phase, the droplet generation frequency calculation is updated with each newly captured video frame. Without the two FIFO data buffers, the computational time of similarity vector is O(NFramesR) in terms of time complexity (NFrames: the number of video frames, R: the spatial resolution of each frame), and the computational time of cyclic auto-spectrum of the similarity vector is O(NFrameslog2NFrames) in terms of time complexity51. Therefore, the computational time for droplet generation frequency is mainly determined by the calculation of the similarity vector, not the calculation of cyclic auto-spectrum. With the aid of the two FIFO data buffers, the computational time for droplet generation frequency is greatly reduced to 1/5,000 of that without using the two data buffers, since only one cosine similarity needs to be calculated per update when using the data buffers, while 5,000 cosine similarities need to be calculated per update otherwise. We did a repetition of ten computations during the real-time phase, and the computational time was 2.92 × 10−4 ± 2.31 × 10−5 s, which saved about 99.98% the average computational time (1.76 s) without these two data buffers. For a time lapse of 5 × 10−4 between two frames at the frame rate of 2,000 fps, the computational time 2.92 × 10−4 ± 2.31 × 10−5 s is short enough to achieve real-time droplet generation frequency monitoring. We believe the modified CSA method can be applied to droplet frequency calculation at higher frame rates with the increased capability of the high-speed camera and computational resource. The current report can provide impetus toward real-time calculation of droplet generation frequency for a closer monitoring of dynamic droplet generation processes.

## Conclusions

In summary, a novel Cosine Similarity Algorithm (CSA) method was developed to monitor dynamic droplet generation processes. With a microscopic droplet generation video clip at a constant frame rate captured by a high-speed camera, four kinds of dynamic droplet generation processes were monitored. Single-channel droplet generation processes were monitored in about 1.63 s on average with an absolute relative calculation error less than 0.08%. Three different stages of droplet generation, squeezing, jetting and dripping, could be differentiated using droplet generation frequency’s CV calculated by the CSA method. Multi-channel droplet generation processes were monitored in 0.36–3.11 s with an absolute relative calculation error less than 0.56%. Meanwhile, the periods affected by the disturbances were accurately determined by droplet generation frequency’s CV. For pre-microgel droplet generation processes with or without artificial disturbances, the results of dynamic monitoring conformed with droplet size uniformities along the timeline. The experimental results demonstrated the effectiveness of the CSA method for monitoring dynamic droplet generation processes in an accurate, convenient and online manner. The CSA method could be a powerful tool for further promoting the research and development of the droplet microfluidics.

## Materials and Methods

### Materials and reagents

PDMS (polydimethylsiloxane) base and its curing reagent (Slygard 184) were purchased from Dow Corning (Midland, MI). Aquapel was purchased from PPG Industries (Pittsburgh, PA). Novec 7500 was purchased from 3 M Inc. (St. Paul, MN). FluoroSurfactant was purchased from RAN Biotechnologies (Beverly, MA). Brilliant blue was purchased from Shanghai Dyestuff Research Institute Co. Ltd. (Shanghai, China). Acrylamide, bis-acrylamide, APS (ammonium persulfate) and TEMED (tetramethylethylenediamine) were purchased from Aladdin Reagent Inc. (Shanghai, China).

### Fabrication of droplet generation chip

The droplet generation chip was designed as a flow-focusing droplet generator whose nozzle was 70 μm wide and 70 μm high. The droplet generation chip was fabricated with standard soft lithography as described earlier52. Briefly, PDMS base and its curing agent were thoroughly mixed and degassed in a vacuum oven (BZF-30, Shanghai Boxun Industry & Commerce Co. Ltd., China). Next, the mixture was cast onto an SU-8 mold fabricated with conventional photolithography (CapitalBio Corporation, China) and cured at 80 °C for 55 min in an oven (DFZ, Beijing Zhongxingweiye Instrument Co. Ltd., China). Then, the PDMS slab was peeled off the SU-8 mold, punched for inlets and outlets, and bonded to a glass substrate with oxygen plasma treatment (Femto, Diener Electronic, Germany).

### Droplet generating and monitoring platform

A conventional droplet generating and monitoring platform was established as described earlier (Fig. 8)53. The droplet generation chip was placed on the stage of an inverted microscope (XDS-1B, Chongqing Optical Instrument Corporation, China). Two syringe pumps (LSP02-1B, Longer Precision Pump Co. Ltd., China) were used to inject the oil phase and the water phase into droplet generation chip through the inlets. Video clips of the droplet generation processes were captured with a high-speed camera (MotionBlitz EoSens 1, Mikrotron, Germany).

### Droplet generation experiments

In the pre-microgel droplet generation experiment, crosslinker premix was used as the oil phase, 2% (w/w) FluoroSurfactant and 0.4% (v/v) TEMED dissolved in Novec 7500. Meanwhile, acrylamide premix was used as the water phase, consisting of 6.2% (w/v) acrylamide, 0.18% (w/v) bis-acrylamide, 0.3% (w/v) APS and 7% (w/v) brilliant blue dissolved in double-distilled (DI) water. In the other droplet generation experiments, Novec 7500 was used as the oil phase, and 7% (w/v) brilliant blue dissolved in DI water was used as the water phase to visualize the droplets. In all experiments, the droplets were generated with the droplet generation chip by injecting the oil and water phases at designated flow rates (Table S1S4) into the designated inlets. The spatial resolution of the video clip was set at 512 × 62 pixels, and the frame rate of the high-speed camera was configured to over five times of droplet generation frequencies. The microscopic video clips were acquired with the high-speed camera at designated time points from the start of droplet generation (Table S1S4). 5,000 frames in each acquired video clip were selected and saved in H264 coding format. The video clips acquired with the high-speed camera were converted to AVI files with the VideoWriter module in Matlab (Mathworks Inc., Natick, MA).

### Reconstruction of video clips

Video clips for droplet generation process in multiple channels were reconstructed from the video clips from droplet generation process in a single channel with Premiere Pro CS6 (Adobe Inc., Mountain View, CA). The first 1,000 frames of each video clip were selected. For a video clip for droplet generation process in two channels, two single-channel video clips were reconstructed to form a video clip with two parallel microfluidic channels of the same width, resulting in a two-channel droplet generation video clip with a spatial resolution of 512 × 256 pixels. For a video clip for droplet generation process in three channels, three single-channel video clips were reconstructed by zooming (110%, 200%, and 150%, respectively), rotating (−13°, 3°, and 147°, respectively) to form a video clip with three microfluidic channels of different widths and directions, resulting in a three-channel droplet generation video clip with a spatial resolution of 512 × 512 pixels. For the other droplet generation processes, no reconstruction was required.

### Processing of monitor results

The mean frequencies and their CVs of each droplet generation process were automatically calculated with a customized Matlab program based on the CSA method. Meanwhile, droplet diameter CVs of the pre-microgel droplets were automatically analyzed with another customized Matlab program based on droplet interface recognition in microscopic images acquired after the droplet generation processes.

### Data availability Statement

The datasets generated during and/or analyzed during the current study are available from the corresponding author on reasonable request.

## References

1. 1.

Wang, J. T., Wang, J. & Han, J. J. Fabrication of advanced particles and particle-based materials assisted by droplet-based microfluidics. Small 7, 1728–1754 (2011).

2. 2.

Günther, A. & Jensen, K. F. Multiphase microfluidics: from flow characteristics to chemical and materials synthesis. Lab Chip 6, 1487–1503 (2006).

3. 3.

Rossow, T. et al. Controlled synthesis of cell-laden microgels by radical-free gelation in droplet microfluidics. J Am Chem Soc 134, 4983–4989 (2012).

4. 4.

Priest, C., Herminghaus, S. & Seemann, R. Generation of monodisperse gel emulsions in a microfluidic device. Appl Phys Lett 88, 024106 (2006).

5. 5.

Choi, C.-H. et al. Generation of monodisperse alginate microbeads and in situ encapsulation of cell in microfluidic device. Biomed Microdevices 9, 855–862 (2007).

6. 6.

Xu, S. et al. Generation of monodisperse particles by using microfluidics: control over size, shape, and composition. Angew Chem Int Edit 117, 734–738 (2005).

7. 7.

Nisisako, T. & Torii, T. Microfluidic large-scale integration on a chip for mass production of monodisperse droplets and particles. Lab Chip 8, 287–293 (2008).

8. 8.

Zhang, J. et al. One-step fabrication of supramolecular microcapsules from microfluidic droplets. Science 335, 690–694 (2012).

9. 9.

Zhao, Y. et al. Microfluidic generation of multifunctional quantum dot barcode particles. J Am Chem Soc 133, 8790–8793 (2011).

10. 10.

Ji, X.-H. et al. On-demand preparation of quantum dot-encoded microparticles using a droplet microfluidic system. Lab Chip 11, 2561–2568 (2011).

11. 11.

Vladisavljević, G. T. et al. Industrial lab-on-a-chip: Design, applications and scale-up for drug discovery and delivery. Adv Drug Deliver Rev 65, 1626–1663 (2013).

12. 12.

Toprakcioglu, Z., Levin, A. & Knowles, T. Hierarchical biomolecular emulsions using 3-D microfluidics with uniform surface chemistry. Biomacromolecules 18, 3642–3651 (2017).

13. 13.

Kong, L. et al. Biocompatible microcapsules with a water core templated from single emulsions. Chinese Chem Lett 28, 1897–1900 (2017).

14. 14.

Klein, A. M. et al. Droplet barcoding for single-cell transcriptomics applied to embryonic stem cells. Cell 161, 1187–1201 (2015).

15. 15.

Allazetta, S. & Lutolf, M. P. Stem cell niche engineering through droplet microfluidics. Curr Opin Biotech 35, 86–93 (2015).

16. 16.

Conchouso, D. et al. Comparison of capacitive and radio frequency resonator sensors for monitoring parallelized droplet microfluidic production. Lab Chip 16, 3210–3219 (2016).

17. 17.

Phillips, T. W., Lignos, I. G., Maceiczyk, R. M., Demello, A. J. & Demello, J. C. Nanocrystal synthesis in microfluidic reactors: where next? Lab Chip 14, 3172–3180 (2014).

18. 18.

Haeberle, S., Zengerle, R. & Ducrée, J. Centrifugal generation and manipulation of droplet emulsions. Microfluid Nanofluid 3, 65–75 (2007).

19. 19.

Kim, Y., Lee, H., Kim, J., Joo, J. & Cheong, I. Hydrogel adsorbents of poly(N-isopropylacrylamide-co-methacryloyloxymethyl-12-crown-4) for Li+ recovery prepared by droplet microfluidics. RSC Adv 5, 10656–10661 (2015).

20. 20.

Wong, D. & Ren, C. L. Microfluidic droplet trapping, splitting and merging with feedback controls and state space modelling. Lab Chip 16, 3317 (2016).

21. 21.

Niu, X., Zhang, M., Peng, S., Wen, W. & Sheng, P. Real-time detection, control, and sorting of microfluidic droplets. Biomicrofluidics 1, 44101 (2007).

22. 22.

Elbuken, C., Glawdel, T., Chan, D. & Ren, C. L. Detection of microdroplet size and speed using capacitive sensors. Sens Actuat A-Phys 171, 55–62 (2011).

23. 23.

Song, C. & Wang, P. A radio frequency device for measurement of minute dielectric property changes in microfluidic channels. Appl Phys Lett 94, 023901 (2009).

24. 24.

Conchouso, D., Mckerrichter, G., Castro, D., Arevalo, A. & Foulds, I. In COMSOL Conference, Grenoble, France (2015).

25. 25.

Kemna, E. W. et al. High-yield cell ordering and deterministic cell-in-droplet encapsulation using Dean flow in a curved microchannel. Lab Chip 12, 2881–2887 (2012).

26. 26.

Ng, E. X., Miller, M. A., Jing, T., Lauffenburger, D. A. & Chen, C.-H. Low-volume multiplexed proteolytic activity assay and inhibitor analysis through a pico-injector array. Lab Chip 15, 1153–1159 (2015).

27. 27.

Sciambi, A. & Abate, A. R. Accurate microfluidic sorting of droplets at 30 kHz. Lab Chip 15, 47–51 (2015).

28. 28.

Vladisavljević, G. T., Kobayashi, I. & Nakajima, M. Effect of dispersed phase viscosity on maximum droplet generation frequency in microchannel emulsification using asymmetric straight-through channels. Microfluid Nanofluid 10, 1199–1209 (2011).

29. 29.

Park, S.-Y., Wu, T.-H., Chen, Y., Teitell, M. A. & Chiou, P.-Y. High-speed droplet generation on demand driven by pulse laser-induced cavitation. Lab Chip 11, 1010–1012 (2011).

30. 30.

Beer, N. R., Rose, K. A. & Kennedy, I. M. Observed velocity fluctuations in monodisperse droplet generators. Lab Chip 9, 838–840 (2009).

31. 31.

Basu, A. S. Droplet morphometry and velocimetry (DMV): a video processing software for time-resolved, label-free tracking of droplet parameters. Lab Chip 13, 1892–1901 (2013).

32. 32.

Liu, C. & Wechsler, H. Gabor feature based classification using the enhanced fisher linear discriminant model for face recognition. IEEE T Image Process 11, 467–476 (2002).

33. 33.

Goshtasby, A., Gage, S. H. & Bartholic, J. F. A two-stage cross correlation approach to template matching. IEEE T Pattern Anal, 374–378 (1984).

34. 34.

Fred, A., de Marsico, M. & Figueiredo, M. Pattern recognition: applications and methods: 4 th international conference, ICPRAM, revised selected papers. 115 (Springer, 2016).

35. 35.

Krim, H. & Hamza, A. B. Geometric methods in signal and image analysis. 82 (Cambridge University Press, 2015).

36. 36.

Roberts, C. C. et al. Comparison of monodisperse droplet generation in flow-focusing devices with hydrophilic and hydrophobic surfaces. Lab Chip 12, 1540–1547 (2012).

37. 37.

Ghosh, S., Kurup, G., Lee, M., Lee, A. & Ahn, C. In 19th International Conference on Solid-State Sensors, Actuators and Microsystems (TRANSDUCERS) 1758–1761 (IEEE, 2017).

38. 38.

Jeong, H. H., Yelleswarapu, V. R., Yadavali, S., Issadore, D. & Lee, D. Kilo-scale droplet generation in three-dimensional monolithic elastomer device (3D MED). Lab Chip 15, 4387–4392 (2015).

39. 39.

Amstad, E. et al. Parallelization of microfluidic flow-focusing devices. Phys Rev E 95, 043105 (2017).

40. 40.

Gasior, M. & Gonzalez, J. In AIP Conference Proc eedings 276–285 (AIP, 2004).

41. 41.

Ward, T., Faivre, M., Abkarian, M. & Stone, H. A. Microfluidic flow focusing: drop size and scaling in pressure versus flow-rate-driven pumping. Electrophoresis 26, 3716–3724 (2005).

42. 42.

Leng, X., Zhang, W., Wang, C., Cui, L. & Yang, C. J. Agarose droplet microfluidics for highly parallel and efficient single molecule emulsion PCR. Lab Chip 10, 2841–2843 (2010).

43. 43.

Guan, Y. & Zhang, Y. PNIPAM microgels for biomedical applications: from dispersed particles to 3D assemblies. Soft Matter 7, 6375–6384 (2011).

44. 44.

Peppas, N. A. Biomedical applications of hydrogels handbook. (Springer Science & Business Media, 2010).

45. 45.

Lyon, L. A., Meng, Z., Singh, N., Sorrell, C. D. & John, A. S. Thermoresponsive microgel-based materials. Chem Soc Rev 38, 865–874 (2009).

46. 46.

Zhao, Y. et al. Bioinspired multifunctional Janus particles for droplet manipulation. J Am Chem Soc 135, 54–57 (2012).

47. 47.

Lyon, L. A. & Serpe, M. J. Hydrogel micro and nanoparticles. 2065 (John Wiley & Sons, 2012).

48. 48.

Tumarkin, E. & Kumacheva, E. Microfluidic generation of microgels from synthetic and natural polymers. Chem Soc Rev 38, 2161–2168 (2009).

49. 49.

Kim, J. W., Utada, A. S., Fernández‐Nieves, A., Hu, Z. & Weitz, D. A. Fabrication of monodisperse gel shells and functional microgels in microfluidic devices. Angew Chem Int Edit 119, 1851–1854 (2007).

50. 50.

Yobas, L., Martens, S., Ong, W.-L. & Ranganathan, N. High-performance flow-focusing geometry for spontaneous generation of monodispersed droplets. Lab Chip 6, 1073–1079 (2006).

51. 51.

Borgioli, R. Fast Fourier transform correlation versus direct discrete time correlation. P IEEE 56, 1602–1604 (1968).

52. 52.

Xia, Y. & Whitesides, G. M. Soft lithography. Annu Rev Mater Sci 28, 153–184 (1998).

53. 53.

Mazutis, L. et al. Single-cell analysis and sorting using droplet-based microfluidics. Nat Protoc 8, 870–891 (2013).

## Acknowledgements

This work was financially supported by the National Natural Science Foundation of China (Grant no. 81572083 and 81772288) and the Fund from TargetingOne Corporation (Grant no. 20162000009).

## Author information

Authors

### Contributions

Xiurui Zhu, Gaoshan Jing and Yong Guo conceived the idea, discussed the results, and prepared the manuscript. Xiurui Zhu developed the algorithm, performed the related experiments, collected the data, and prepared the software in the supplementary information. Xiurui Zhu, Shisheng Su, and Mingzhu Fu improved the algorithm performance. Xiurui Zhu and Junyuan Liu contributed to the mathematical proof in the supplementary information. Lingxiang Zhu, Wenjun Yang, Gaoshan Jing and Yong Guo provided financial support to the project.

### Corresponding authors

Correspondence to Gaoshan Jing or Yong Guo.

## Ethics declarations

### Competing Interests

The authors declare no competing interests.

Publisher's note: Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

## Rights and permissions

Reprints and Permissions

Zhu, X., Su, S., Fu, M. et al. A Cosine Similarity Algorithm Method for Fast and Accurate Monitoring of Dynamic Droplet Generation Processes. Sci Rep 8, 9967 (2018). https://doi.org/10.1038/s41598-018-28270-8

• Accepted:

• Published:

• ### Extracting Association Rules of Turkish Retail Company from Online Transactions: Case Study

• Elif Şafak Sivri
•  & Mustafa Cem Kasapbaşı

Düzce Üniversitesi Bilim ve Teknoloji Dergisi (2019)

• ### A real-time cosine similarity algorithm method for continuous monitoring of dynamic droplet generation processes

• Xiurui Zhu
• , Shisheng Su
• , Baoxia Liu
• , Lingxiang Zhu
• , Wenjun Yang
• , Na Gao
• , Gaoshan Jing
•  & Yong Guo

• ### Asynchronous generation of oil droplets using a microfluidic flow focusing system

• Peter Thurgood
• , Sara Baratchi
• , Aram Arash
• , Elena Pirogova
• , Aaron R. Jex
•  & Khashayar Khoshmanesh

Scientific Reports (2019)