Electrochemical noise analysis to obtain the Rsn value via FFT using Excel

57 Eclética Química Journal, vol. 45, n. 4, 2020, 57-70 ISSN: 1678-4618 DOI: 10.26850/1678-4618eqj.v45.4.2020.p57-70 ABSTRACT: Electrochemical noise (EN) measurements are based on the fluctuations of the electrochemical potential and the current that occur during, for example, a corrosion process without an external signal perturbation. EN analysis (ENA) allows assessment of the type of corrosion and rapid determination of the corrosion rate. Microsoft Excel, an inexpensive and readily available software package, is an excellent tool for performing repetitive calculations, with automation that saves time for the users. It is a useful tool for the analysis of EN data using fast Fourier transform (FFT), a process that is often made repeatedly and, if not automated, is quite laborious. This work presents a step-by-step procedure using Excel to perform


Introduction
Electrochemical noise (EN) measurements concern the fluctuations of the electrochemical potential and the current that occur during corrosion processes, without applying an external signal perturbation. EN can be used to monitor the type of corrosion and to rapidly obtain the corrosion rate. The electrochemical potential and current noises are simultaneously measured either by coupling two nominally similar working electrodes connected by a zero-resistance ammeter (ZRA), so that the potential difference between the working electrodes is zero, or by measuring with respect to a reference electrode [1][2][3] . In EN studies, the electrochemical noise resistance (Rn), determined as the standard deviation of the potential noise divided by the standard deviation of the electrical current noise, is generally considered as an estimation of the corrosion rate 1 .
Time domain analysis does not lead directly to comparative values of corrosion rates between systems being studied, hence necessitating frequency domain analysis. In the frequency domain, the power spectral density (PSD) is useful for predicting the corrosion mechanism and, in some cases, has been used in calculating noise impedance. PSD plots are computed using algorithms such as fast Fourier transforms (FFT) 2 , which are advantageous when repetitive signals are measured, and the data sets acquired have large numbers of sampling points. The square root of the ratio of the voltage PSD to the current PSD, as a function of frequency, enables calculation of the low frequency noise impedance, Rsn.
Excel software is an excellent tool for performing repetitive calculations, with automation providing considerable saving of time for users. In order to automate a repetitive task, a macro is recorded using the Macro Recorder in Excel 4 , applying the desired format, which can then be replayed whenever needed. An example of this is the possibility of its use, still little explored, for the treatment of electrochemical noise data using FFT, a process that is usually performed repeatedly and is quite laborious, if not automated. Therefore, this work presents a stepby-step procedure for performing these calculations using Excel software, automating the process of obtaining the spectral electrochemical noise resistance, 0 , using experimental potential and current noise data recorded for chalcopyrite in the laboratory. The 0 value is calculated, as proposed by Mansfeld and Lee 5 , using Eq. 1: with where ( ) and ( ) are the power spectral density of the potential, E(t), and the current density, i(t), respectively, in the frequency domain f.
In the practical process, 0 is determined by the linear regression of ( ( )) . ( ) at the "plateau" in the low frequency region, as suggested in the literature 3 , covering a minimum of 10 frequency points. The straight-line equation fitted is evaluated using the lowest frequency of the recorded data, with the result being the 0 value.
In this work, the PSD calculation employs Eq. 3 6 : where ( ) is the Fourier transform of x(t), given by Eq. 5, T is the experimental time ( = , where N is the number of experimental data points and is the time interval between measurements), and the number 2 indicates that only positive frequencies are considered, since the Fourier transform can also apply to negative frequencies.
The Fourier transform of a function x(t) is defined by Eq. 4: where 2 = −1 is the imaginary unit and, among other properties, converts the time domain into a frequency domain. Since the signals are considered in the time interval between 0 and T, the Fourier transform calculations are made from the integral, according to Eq. 5: with the integral being numerically calculated by Eq. 6, called a discrete Fourier transform 6 : where = is the frequency related to the m-th sampling point and x is the function to be transformed (in this case, the potential E and the current density i). The FFT is an algorithm that optimizes the calculations by making them faster, compared to the discrete Fourier transform, and for its use the data set should contain a number of points equal to a power of 2 (for example, 2048 = 2 11 ). In Excel, this algorithm is implemented using the "Fourier Analysis" function. Note that Eq. 2, for calculation of ( ), involves the ratio between PSDE and PSDi, so the factor 2/T of Eq. 3 will be canceled in the operation. Hence, in this work, PSDE and PSDi will be obtained using Eq. 7: since ( ) is a complex number, and the modulus of a complex number z = a + bj is given by | | = √ 2 + 2 , so | | 2 = 2 + 2 .
As the goal of this work is to provide a routine to obtain 0 using Excel software, we indicate the criterion that will be used for delimiting the frequency region, without elaborating on any particular merits of this procedure, leaving it to the ENA user to select the criterion most suitable for the study being undertaken. In addition to describing how the value of 0 can be calculated using Excel, the results are compared with those obtained for the same set of experimental data using Origin ® software.

Methodology
The Excel commands presented in this guide follow the 2010/2013 versions of the software. If another version is used, it would be necessary to check the equivalent commands. It is recommended to use the configuration with a dot as the decimal separator, since the original data is generated in this format. To make the change from comma to dot, follow these commands: File → Options → Advanced → Editing options → Use system separators → make the change.
This analysis considered 2048 points of an experimental data set obtained in the low frequency region, but the routine can be applied to any other number of points, as long as the number is a power of 2. The experimental data were arranged in three columns, considering time (t) in seconds (s), potential (E) in volts (V), and current (I) in amperes (A), in a worksheet named Data. It is possible that the experimental data set could have more than 2048 points, so it is important to count the number of data points in the spreadsheet (Formulas → Insert Function → COUNT → OK → select a set of data (column) → OK), in order to leave only 2048 points, deleting the points in excess in the high frequency region. An example of an input spreadsheet is shown in Fig. 1. Considering that it is often necessary to remove the drift before analyzing the data 7,8 , this guide suggests a polynomial removal procedure. For this, graphs are constructed of potential or current against time, adding a trendline that provides the best fit to the data. This can be performed using the following commands: position the cursor on the graph and press the right button of the mouse → Add Trendline → Polynomial → choose the order that provides the best fit → mark Display Equation on chart → Close. Note that the polynomial orders for potential and current may be different each other. Format the graph and trendline, as desired. Fig. 2 shows examples.  In order to remove the drift, create new columns with the following parameters: time (t); potential value from the trendline (yE(t)), using the polynomial coefficients given by the potential fit; current value from the trendline (yI(t)), using the polynomial coefficients given by the current fit; and the differences between the experimental and fitted values for potential and current (E(t) -yE(t) and I(t) -yI(t), respectively), as shown in Fig. 3. It is recommended to construct graphs of potential and current after removing the drift, in order to visualize the results and confirm that the values are near y = 0. Figure 4 shows an example. In many cases, it is necessary to use appropriate windows to improve the quality of treatment by FFT. This guide uses the Hann window 6,9 , which is one of the most suitable. It is defined by the function: where N is the total number of points used (in this case, 2048) and n is the position of each experimental point, initiating at zero. This function must be multiplied by the values of E(t) -yE(t) and I(t) -yI(t), which are calculated as described above. Figure 5 shows the Data spreadsheet updated so far, where a column with numbers n was created (column T) to apply the Hann window (columns U and V) and the value of N (fixed, in this case given in cell D2). Note that to fix a cell, just click on it, and press the F4 key on the keyboard.  Therefore, if the Hann window is not applied, the data of columns O, R, and S should be directly used in the analysis; if the Hann window is applied, the data of columns O, U, and V should be used.
Once the input data are organized, insert a new worksheet in the spreadsheet, in this example named Analysis, to perform the calculations. The step-by-step procedures for building the Analysis worksheet are presented below.
Save the spreadsheet with extension .xlsm (Excel Macro Enabled Workbook). Copy the input data (columns O, R, and S of the Data worksheet, if the Hann window is not used in the input data, or columns O, U, and V, if it is used) and paste from the 5 th or 6 th row of the first column (A) of the Analysis worksheet, in order to leave the starting lines for captions, comments, and new data to be inserted. We suggest, for example, that the number of data points (N) is informed at the beginning of column A, the time interval between measurements ( t  ) in column B, the electrode area (cm 2 ) in column C, and a scale factor with magnitude of 10 2 or 10 3 in column D, as this information will be used in future calculations. We also suggest using Excel facilities to count the number of data and the value of t  , which will minimize errors. The electrode area and the scale factor must be entered manually, as they are values known by the user.
It is important to note that Excel works internally with 14 significant digits. Therefore, since the input data values can be very small, especially for the current data, some values may be considered null and the FFT calculation may fail. A way to overcome this issue is to introduce a scale factor at the beginning of the spreadsheet (in this example, in cell D2), which is used to multiply the current density values before calculating the FFT, increasing the values to the required order of magnitude (10 2 , 10 3 , ...). After the calculations, the scale factor is removed by means of a division. However, it is not necessary to perform this calculation manually since it is included in the automation of the FFT calculations. It is necessary to insert the scale factor according to the order of magnitude of i (which in this case is 14 13 10 or 10 −− , consequently requiring a correction with minimal order of 10 3 ). Figure 6 shows this procedure. The calculations presented here are performed using Hann window and current density (i, in A cm -2 ), so the experimental data related to current are divided by the electrode area, placing the result (=C6/$C$2) in column D. Note that as the electrode area is constant, it must be fixed when dividing.
In column E, list the input data (n = 0, 1, 2, 3, ...) used for calculating the frequency (in Hz). The frequencies will be calculated in column F, using the formula: Although there is no zero frequency, it is necessary to start at n = 0 for the FFT calculation. To insert the formula, position the cursor in the desired cell (in the example, F6) and do: =E6/($A$2*$B$2). Note that N and t  are fixed, so it is necessary to fix these values, which in the example are in cells A2 and B2. Remember to copy a formula for all cells in the column, just positioning the cursor at the lower right corner of the cell to be copied and, when a cross appears, double-click. An example of the spreadsheet up to this step is shown in Fig. 6.  To calculate the FFTE of the potential, place the cursor in column G, aligned to the data, and follow the commands: Data → Data Analysis → Fourier Analysis → OK. A window similar to the one shown in Fig. 7 appears and, in the Input Range option, select the data from the Potential column (in the example, the data from column B). As an output option, choose "Output Range" and click on the cell where it is desired to place the FFTE values (in the example, cell G6). Click OK and all the FFTE values are calculated.  Repeat the same procedure to generate a column with FFTi (to calculate the FFT of the current density data), changing only the Input data to column D, and the output location to cell H6.
The result of the FFT is a complex number, so in order to perform the following calculations, it is necessary to separate the real and the imaginary parts into different columns. To do this, place the cursor on the next free column, aligned to the data (in the example, I6), and follow the commands for the real part: Formulas → Insert Function → IMREAL → click on the cell of the complex number (G6) and then on OK. The command window is shown in Fig. 8. Then, drag the formula to all the data (doubleclick on the little cross in the lower right corner of the cell). Do the same for the column of the imaginary part, using the function IMAGINARY. After performing the procedure for the potential and current data, a spreadsheet similar to the one shown in Fig. 9 is obtained. The PSDE of the potential is calculated using Eq. 7, which must be introduced in the next free column (M). In this example, it is: =I6^2+J6^2. Drag to all cells in the column and repeat the procedure to calculate the PSDi of the current, which should be entered in column N.
In the next free column (O), where sn R is calculated using Eq. 2, type: =SQRT(M6/N6) and drag to all cells in the column.
To calculate the slope and linear coefficients of the line obtained by the linear regression of log ( ) . log ( ) sn R vs f , it is necessary to calculate the logarithms (base 10) for these two columns. To do this, in the next two free columns (P and Q) do: =LOG10(F6) and =LOG10(O6), respectively, and drag to the entire columns. Note that as the first frequency value is f = 0, its logarithm cannot be calculated, so the expression "#NUM!" appears in cell P6. This is not a problem, as this point can be excluded during graph construction. Figure 10 shows the example in progress. This work presents a way to build the graph in Excel by adding a slider on the abscissa axis to define the region of linear regression. This selection is important for the final result of the analysis and can be performed by following the steps below. However, it is also desirable that the user should be able to see the entire graph in a background, together with the interval chosen for linear regression and using a logarithmic scale, in order to facilitate interpretation of the results, observing the results as frequency, rather than logarithm of frequency. Therefore, the graph is constructed using a logarithmic scale.
Firstly, insert two slider bars in an empty region on the worksheet, using the following commands: Developer → Insert → Scroll Bar (in Form Controls box) → choose the place where you want to put the bars, click, and drag the mouse horizontally. The bars must be placed in a position where there is space to put a graph above them (Fig. 11).  Position the cursor in a cell next to the bars (in the example, T16) and type a name for the cell in the identification space (upper left corner of the worksheet), for example, "Start_Point", as shown in Fig. 12. Repeat the procedure in the cell below, naming it "End_Point". On the left side of these cells, it is recommended to write the words "Initial index" and "Final index", to indicate that the cells on the right show the positions (n) of the first and last points used in the linear fit. With this procedure, these cells have the function of variables for delimitation of the graph, using the slider.  Click with the right button of the mouse on each bar, select the option "Format Control" and configure each bar according to the information in  It is then necessary to declare the variables not linked to cells, in order to store the data range to be plotted. For this, the OFFSET function is used, so that they have a dynamic behavior, following the commands: Formulas → Name Manager → New. A name is then typed for the first variable. In this example, Range_X is suggested. Then type the expression: =OFFSET(Ref_X_Plot; Start_Point; -10; End_Point-Start_Point; 1) in the option "Refers to" in the box → OK. Figure 15 shows this procedure.  Repeat the procedure for the other variables, as shown below: Name: Range_X_Lin → Refers to: =OFFSET(Ref_X_Plot; Start_Point; 0; End_Point-Start_Point; 1) Name: Range_Y → Refers to: =OFFSET(Ref_X_Plot; Start_Point; -1; End_Point-Start_Point; 1) Name: Range_Y_Lin → Refers to: =OFFSET(Ref_X_Plot; Start_Point; 1; End_Point-Start_Point: 1) Now, clicking on "Name Manager", a window similar to the one shown in Fig. 16 opens. It is now possible to make the graph. Place the cursor in an empty cell, click on "Insert" (in the ribbon) and, in the Charts group, choose preferentially the option "Scatter with Straight Lines" (Fig. 17). This command generates a clean graph area. Press the right mouse button on the area of that graph and select the option "Select Data". In the dialog box that opens, select the option "Add" (Fig. 18) and a new dialog box (Edit Series) appears. In the "Series X values" option, select the frequency data (except f = 0), and in the "Series Y values" option, select the data for sn R , except the value corresponding to f = 0. Click OK in both windows and the graph appears, with a linear scale. To change the scale of the graph to logarithmic, press the right mouse button on the scale of the axes → Format Axis → Logarithmic scale (Base 10). Do this for both axes. Change the color of the data to a light color, as it is overlaid by the region that is chosen for analysis. To do this, click on the graph with the right mouse button, select Format Data Series → Line Color → Solid Line, and choose a light color, as shown in Fig. 19. Also format the window type, line thickness, axis scale, font, etc., as desired by the user. A new data string must be inserted in the graph to overlay the data selected by the scroll bars. To do this, click with the right mouse button on the graph area and select the options: Select Data → Add. Fill the fields "Series X values" and "Series Y values", as shown in Fig. 20, and click on OK. A new box "Select Data Source" appears; click on OK. Following the procedure shown above, choose a dark color for this second data stream.
For the purposes of this work, it is necessary to add a trendline, which is used to perform the linear fit of the experimental data to a mathematical function (linear regression), using the least squares method. To do this linear regression, click with the right mouse button on the new data sequence (the darkest graph) and choose the option "Add Trendline". Click on "Power", as shown in Fig. 21, since the graph axes are on a logarithmic scale and the logarithm properties transform powers into products, so the result is a line. Change the properties "Line Color" and "Line Style", as desired. Position the graph above the slider bars. If highlighting is desired, select the cells behind the graph, color them, and describe the function of the control, in order to facilitate its use. Figure 22 shows an example.
Note that the purpose of the slider bars (placed below the graph) is to delimit the region that will be fitted by the trendline, which can be done by clicking on the arrows (to move 1 point each click), or on the bar itself (to move 10 points for each click). It is also possible to click on the vertical mark and drag.  The angular and linear coefficients of the fitted line must be inserted in a cell since they are used to calculate 0 sn R . Hence, the cursor is placed in the cell where the slope is to be located (in this example, T8), typing: =SLOPE(Range_Y_Lin; Range_X_Lin). In the cell where the intercept or linear coefficient is to be inserted (in this example, T9), type: =INTERCEPT(Range_Y_Lin; Range_X_Lin).
In the cell where it is desired to insert the calculation of y using the first value of x (lowest value of the experimental frequency), in this example named 0 log ( ) sn R , type: =(REF_X_Plot)*T8+T9, since REF_X_Plot is the cell that indicates the first x value used in the plot, and T8 and T9 are the cells in which the slope and y-intercept values of the trendline were calculated, respectively. If different cells are used, then the same logic should be followed. To facilitate visualization of the initial and final values of the fitted region, the following formulae can be inserted in cells next to the graph: =INDEX(F7:F2053; Start_Point + 1), for the initial value of the frequency range, and =INDEX(F7:F2053; End_Point), for the end value of the frequency range. Figure 23 illustrates the example being used in this work. Once the spreadsheet is built, the goal is to use it to automate the work, performing the analysis of the quantity of data sets it is desired to study, simply by replacing the input data. However, the FFT function does not update automatically with the replacement of the input data. Hence, it is necessary to either manually delete and redo the values calculated by the FFT, every time a new set of input data is used, or implement a macro, which is an Excel feature for automatically performing programmed tasks. This can be done as follows: On the ribbon, click Developer → Visual Basic. In the window that appears in the left part of the screen, right-click on Microsoft Excel Objects → Insert → Module, as shown in Fig. 24. This creates a workspace. Place the cursor in it and enter the codes described below (note that the cells indicated in the codes refer to the current example). Thus, G6 is the cell where the initial value of FFTE is positioned, while cells B6 to B2053 contain the range of potential data, E. Analogously, H6 is the cell where the FFTi values start, while cells D6 to D2053 contain the current data, i. It should be noted that multiplication by the scale factor, mentioned previously, is already included in this macro. Next, click where it is desired to create the button, dragging the cursor to form a rectangle. Release the mouse when the desired size is reached. At this point, a window called Assign Macro opens. Click on Button 1 and then OK (Fig. 26). Every time the input data is changed, click on the FFT button to remake the FFTE and FFTi calculations. All other calculations are automatically updated.
The procedure presented above was also performed without Hann window. The results obtained with Excel were compared with those obtained with Origin ® (see the Supplementary  Information 1), a software package widely used by chemists, using the same experimental data and the same linear regression frequency region. The results are presented in Tab. 1.

Conclusions
The routine developed in Excel, an inexpensive program available to all students and professionals from different areas, was effective for calculation of the spectral electrochemical noise resistance value, 0 , according to the FFT method. It was possible to obtain the values rapidly, saving time when performing repetitive calculations for analysis of the results from a large number of experiments.