Open Access Article
Ziwen
Zhao
*a,
Arunava
Naha
b,
Nikolaos
Kostopoulos
a and
Alina
Sekretareva
*a
aDepartment of Chemistry - Ångström, Uppsala University, 75120 Uppsala, Sweden. E-mail: ziwen.zhao@kemi.uu.se; alina.sekretareva@kemi.uu.se
bDepartment of Electrical Engineering, Uppsala University, 75120 Uppsala, Sweden
First published on 4th July 2024
Single-entity electrochemistry (SEE) is an emerging field within electrochemistry focused on investigating individual entities such as nanoparticles, bacteria, cells, or single molecules. Accurate identification and analysis of SEE signals require effective data processing methods for unbiased and automated feature extraction. In this study, we apply and compare two approaches for step detection in SEE data: discrete wavelet transforms (DWT) and convolutional neural networks (CNN).
Recently, we have reported an algorithm for automated processing of single-entity electrochemistry signals using machine learning and template-matching approaches.7 The algorithm enables rapid feature extraction for data containing spike-like signals, common in the nano-impact SEE approach.8 Here, we focus on another type of signal, namely, step-like or staircase signals. These signals are characterized by changes in the mean value level, typically as a function of time. In the case of nano-impact SEE, these changes occur due to interaction between individual entities and the electrode.8 Subsequent interactions lead to the buildup of entities on the electrode surface, which affects the surface area of the electrode and, therefore SNR, complicating data analysis.9
To the best of our knowledge, no algorithms have been reported for the analysis of staircase signals in nano-impact SEE. However, step detection algorithms, aiming at identifying regions of the data where the signal changes from one level to another, are common in many other fields.10–15 Additionally, several algorithms have been reported for the analysis of SEE nanopore data, which allow for the detection of abrupt changes in a signal caused by a nanopore blockade.16–20 Many of the reported step detection algorithms assume an instantaneous change in the signal with the slope of infinity and fit a series of step functions to the data based on this assumption.11–17 These algorithms are generally not well suited for data where signal changes occur gradually with variable linking segment slopes, a scenario often encountered in nano-impact SEE. Additionally, many of these algorithms consider the noise to be uncorrelated Gaussian white noise.11–14,16,17 In nano-impact SEE, the noise is correlated because the interaction of a single entity with the electrode changes the surface area of the electrode and, therefore, affects the noise level. Applying algorithms assuming uncorrelated noise to the data containing correlated noise can result in complications.
Considering the limitations of the reported step detection algorithms, here we apply and compare two approaches for step detection in SEE data: discrete wavelet transforms (DWT) and convolutional neural networks (CNN). The DWT method is commonly used for detecting abrupt changes.21 The DWT method applied in this work approximates the step signals using the Haar wavelet function. Our results obtained with the DWT and CNN methods demonstrate that for low-noise data containing steps with simple shapes characterised by purely step-function type jumps, the DWT can satisfactorily analyse the data. However, for noisy data containing signals with more complicated shapes, the CNN is more suitable for the data analysis, though more computationally costly.
![]() | ||
| Fig. 1 Discrete wavelet transform of the data. (A) Digitized data taken from ref. 22. (B) Approximation coefficient of the data. (C) Detail coefficient of the data. The line shows the step at 186 and a corresponding peak at 93 in the detail coefficient. | ||
In our analysis, we used the Discrete Wavelet Transform (DWT), which is governed by the following equation:
![]() | (1) |
. The DWT decomposes the target signal into signals of hierarchical frequencies, each half the length of the target signal. This process splits the signal into low and high-frequency components. When these components are summed within their respective groups, two sets of coefficients are obtained. The low-frequency component, known as the approximation coefficient, represents the smooth part of the data (Fig. 1(B)). Conversely, the high-frequency component, known as the detail coefficient, represents areas where the target signals are located (Fig. 1(C)).
To detect the step in the data, we applied the DWT using the Haar mother wavelet. The Haar wavelet, defined as a simple step-shaped function, is particularly effective for this purpose. The mathematical definition of the Haar wavelet is as follows:24,25
![]() | (2) |
The original signal and its low and high-frequency components, obtained through DWT, are depicted in Fig. 1(A–C). These signals are plotted against the data index, which is the sequence position of the data point. Notably, when there is a step at index i in the original signal, the high-frequency component has a corresponding peak at approximately i/2. The Haar wavelet, representing a signal with sharp changes, is strongly activated at these peaks, effectively capturing the rapid changes in the signal.21 Through DWT, the data are transformed into a signal with peaks that are easier to extract. In contrast to conventional methods that find peaks on the derivative of the target signal, the WT yields detail coefficients close to zero when there are no abrupt changes in the signal. Step detection is accomplished by identifying all the peaks in the detail coefficients without height threshold. The step position in the original signal can be obtained by multiplying the peak indices by two. By setting an appropriate window size (6 indices for the data in Fig. 1, though this value varies with the sampling frequency), a step can be defined as two times the peak indices ± half the window length. This process yields all step-like individual intervals.
To be able to distinguish step signals from noise, we set a height threshold for the identified steps, derived from the calculation of the blocking current (ΔI) using the following equation:22
![]() | (3) |
To improve the accuracy of the step detection, we incorporated a shallow Convolutional Neural Network (CNN)26 classifier into the algorithm. A CNN can be thought of as a collection of filters. Each filter is a small matrix that performs a convolution operation on the output of the previous layer. These filters are trained to extract features from their input data. The results of these convolutions, which are the extracted features, then serve as the input for the next layer. This process is repeated layer by layer. Eventually, the network outputs a probability value, indicating the likelihood that the input data belongs to a certain class. The workflow for using CNN to detect step signals involves several additional procedures, which are outlined below.
Next, a window length and a step height threshold were defined. This resulted in simulated step intervals. Each step interval was normalized to zero mean and unit variance, as shown in Fig. S1(B).† An equal number of non-step signals (negative signals) were then generated. Each negative signal has the same length as the step interval. Half of the negative signals were created from random Gaussian noise, while the other half were created by introducing an abrupt change point at the initial or final point of the step interval, as shown in Fig. S1(C).† These negative signals are also normalized to zero mean and unit variance. There are approximately 3000 steps and 3000 non-steps in the training set.
![]() | ||
| Fig. 3 The built CNN model. (A) The CNN model structure. Plotted with ref. 29. (B) Model validation on random signals. The model detects the possibility of whether the signal is a step or not a step. | ||
- Three 1D convolutional layers28 (Conv1–3D in Fig. 3(A)): these layers are designed to extract features from the input data. Each convolutional layer is followed by a batch normalization layer and a dropout layer. The batch normalization layer normalizes the output of the preceding convolutional layer, ensuring that the model trains efficiently. The dropout layer randomly sets a fraction of input units to 0 at each update during training time, which helps prevent overfitting.
- A global average pooling layer (Glob_Avg_Pool in Fig. 3(A)): this layer is added after the last convolutional layer. It reduces the number of parameters in the model, thereby simplifying the model structure and reducing the risk of overfitting. It also transforms the format of the input into a form that can be fed into the dense layer.
- A dense layer with 128 neurons: this layer is added after the global average pooling layer. It uses a ReLU (Rectified Linear Unit) activation function, which introduces non-linearity into the model, allowing it to learn more complex patterns. This layer is followed by another batch normalization layer and a dropout layer.
- A final dense layer: this layer uses a sigmoid activation function, which outputs the probability of the input data to be seen as a step.
The trained model is evaluated on randomly generated data, as shown in Fig. 3(B). The data in the first column incorporate abrupt change, while the data in the second column contain a step. As can be seen, the model predicts well the possibility of the signal being a step and, contrary to DWT, does not misassign an abrupt change to a step signal.
The detected steps were merged if the initial point and the maximum difference point of the current step and the next step were within 10% of the height threshold. If two steps were not qualified to be merged but the index of the initial point of the next step was within the current step, the overlapped points were averaged.
As the sampling frequency rises, the number of data points required for parameter extraction also increases. For low-frequency signals, a minimal number of points are used for calculation to ensure exclusion of the decay portion of the step. For signals with a higher sampling frequency, the quantity of data points selected for parameters extraction is increased to accommodate the increased data density (see Section 2.4). The parameters extracted from the initial 32 seconds of data using both methodologies are detailed in Table S1.†
At this stage, we can make a preliminary comparison between the two methods. The CNN method detected three fewer steps than the DWT method when using the same height threshold. Three false positives detected by the DWT method are due to its sensitivity to a sudden value change which is not necessarily a step (Fig. 2(B) marked with purple). The CNN method, on the other hand, is more robust in detecting steps. It only identifies a step when the upper and lower parts of the signal match a certain profile. Moreover, it offers more flexibility in terms of the shapes it can detect, as the training set can be adjusted to include more complex step shapes.
However, the CNN method requires more computational resources and time. For the same signal, the DWT method takes less than 1 second, while CNN needs background knowledge, and the training process requires higher computation costs. As the sampling frequency increases, the time required for the CNN method to detect steps also increases. Therefore, when choosing a detection method, there is a trade-off between accuracy and computational complexity.
To further analyse the data and compare the two methods, we employed a k-means unsupervised machine learning method.7 This method was used to cluster the ‘UpperSlope’, ‘LowerSlope’, and ‘StepHeight’ parameters. The optimal number of clusters was determined using the elbow method. We then compared the results of this clustering for the two detection methods mentioned earlier. The results are depicted in Fig. 5. In the 3D space, both methods form distinct clusters.30 However, the clusters generated by the DWT have larger variance compared to those from the CNN method, indicating that the CNN method has higher precision.
![]() | ||
| Fig. 5 3D plots comparing data clustered by k-means (colour coded), the 3 dimensions StepHeight, UpperSlope, and LowerSlope are separately normalized. (A) The DWT method. (B) The CNN method. | ||
000 data points containing 30 steps marked with red (Fig. 6(A)). The steps in the data with the high-frequency sampling have different profiles compared to those in the low-frequency data used for the analysis method development. In low-frequency measurements, a step can be simply defined as a current value dropping from one nearly fixed value to another. However, in high-frequency measurements, the upper fixed value decays with a certain slope to the lower fixed value, and both the upper and lower sides have additional slope and high noise. This complexity leads to the step being less well defined. In addition to the evident steps, there are also some steps with a height nearly equal to the noise level. Three such steps were therefore filtered out at this stage as they were difficult to distinguish from the noise resulting in 27 steps in total.
At high sampling frequencies, step detection becomes more challenging. Traditional methods, such as derivative detection, are no longer effective, as evidenced by the lack of clear peaks in the derivative shown in Fig. S3.† However, both methods developed in this study are capable of detecting the steps in such cases.
For the DWT, a single transform is no longer effective in detecting the steps. After three transforms, the spikes corresponding to the steps start to become visible (Fig. S4(E)†), and after five transforms, the spikes are clearly visible, as shown in Fig. S4(G).† Similar to low frequency data analysis all peaks were detected without height threshold. Each step interval was defined as the index on the original signal minus half the window length, plus 1.5 times the half window size. In this example, we used 60 as the window size, so an interval is defined as [index − 15, index + 45] to cover the long decay of the steps. By defining the height threshold for the step as 7 units (the value was chosen based on how the data for analysis were simulated), 26 steps were detected in the data, as shown in Fig. 6(B). One of the steps was missed by the method (inset in Fig. 6(B)). It is important to note that when applying the DWT method to a new data set the number of transforms needs to be adjusted. As the number of transforms increases, the loss of the high-frequency components may contain the desired steps.
For the CNN method step detection can be achieved by modifying the training set and slightly adjusting the structure of the model. The training set is shown in Fig. S5.† The fundamental structure of the CNN model remains unchanged, with the only modification being the adjustment of the input layer to 60 to accommodate the requirements of the input data, as the sequential layer output numbers vary accordingly. The model was trained for 300 epochs to facilitate easier adjustment of the decay length of the training set. The progression of the training set is depicted in Fig. S6(A).† The trained model is similar to the model used for the low-frequency data analysis (Fig. 3), with the exception that it neglects steps located at the beginning or end of the window Fig. S6(B).† This model was then applied to the high-frequency simulated data. Similar to low-frequency data analysis, the model was slid across the experimental data by iterating through all the data points. Each interval, with a window length of 60, was normalized to zero mean and unit variance. If the probability of a step exceeded 0.5, it was considered as a step. Interestingly, the model no longer requires height thresholding for detection. This may be due to the fact that the shape of the step was well trained in the training process. 27 steps were detected in total with the CNN model as shown in Fig. 6(C).
For each detected step, three parameters were extracted as outlined in Scheme 1. Similar to the low-frequency data, the ‘StepHeight’ is calculated as the mean difference between the first five points and the last five points within the step interval. The ‘UpperSlope’ and ‘LowerSlope’ parameters are calculated as the slope of the first ten points and the last ten points of the step interval, respectively. The parameters extracted by both methods are presented in Table S2.†
000 data points, the CNN method required twice the computational time of the DWT method (less than 1 second for DWT, and about 2 seconds for CNN). Additionally, the CNN method needs additional time to prepare the training set and train the model. The CNN method offers more flexibility in terms of the shapes it can detect, as the training set can be adjusted to include more complex step shapes. However, if the desired signal cannot be well simulated, the results obtained with the CNN method may not be satisfactory. Therefore, well-simulated physical data or real data should be used to train the CNN model.
Footnote |
| † Electronic supplementary information (ESI) available. See DOI: https://doi.org/10.1039/d4fd00130c |
| This journal is © The Royal Society of Chemistry 2025 |