# Plant Electrical Signal Classification Based on Waveform Similarity
## 3 Materials and Methods
### Our Proposed Method
#### 3.1.2 Recognizing Algorithm for Plant Electrical Signals  
The APs of plant are aperiodic, and artifacts are similar to APs in shape. For this reason, we have to utilize the time domain processing approach. The AP will become more apparent by performing the first-order derivative for the raw signal. In other words, the first-order derivative algorithm allows us to identify features of AP that are not obvious in the original signal. To recognize AP of plant, our method also considers the both biphasic and monophasic original signal by extracellular recording. Here, monophasic signal is characterized by deflection in one direction, e.g., positive or negative phases [79]. If there are both positive and negative phases to this response, it is referred to as a biphasic signal [80; 81].  
To determine the starting point, end point, and peak point of signal, the noise peaks threshold is initiated as 0.1 mV/s at first. Then after every first-order derivative, the noise peaks threshold is updated by the following method. We set the new noise peaks threshold as the sum of 0.75\(\times\) old noise peaks threshold and 0.25\(\times\) average of new noise peaks.  
Using noise peaks threshold, we can obtain all peaks and zero-crossing points which are applied to determine AP peak points, and then search and mark the starting point and end point of AP peak waveform. Based on the information, all waveforms similar to AP can be extracted from raw signal whether they are biphasic or monophasic.  
Figure 1: Processing flow of recognizing and classifying AP.  
```
The AP recognition algorithm (Algorithm 1) is as follows:
``` Input: Raw signal is represented by ST Output: Waveforms similar to AP ```
``` BEGIN 1. DS = Take derivative of ST by a five order central difference algorithm // Derivative. 2. Noise_Threshold = 0.1 // Initialize noise threshold. 3. PV = findpeaks(DS) // A search algorithm to find the peaks and valleys in DS. 4. For i=1:N // N is the number of peaks or valleys in PV. 5. IF amplitude of PV(i) < Noise_Threshold THEN N_Peaks = PV(i); // If peak amplitude is below Noise_Threshold, then add it into N_Peaks. 6. Else S_Peaks = PV(i); // If peak amplitude is above Noise_Threshold, then add it into S_Peaks. 7. ENDIF 8. END 9. Noise_Threshold = 0.75\(\times\)Noise_Threshold + 0.25\(\times\)mean(N_Peaks) // Update noise threshold 10. For i=1:NS // INS is the number of peaks in S_Peaks 11. S_Peaks_left_Position(i) = Search the left part of S_Peaks(i) // Search for start point on the left of S_Peaks(i) 12. S_Peaks_right_Position(i) = Search the right part of S_Peaks(i) // Search for end point on the right of S_Peaks(i) 13. END 14. For i=1:NS-1 //NS is the number of peaks in S_Peaks 15. IF S_Peaks_left_Position(i+1) < S_Peaks_right_Position(i) // For overlap AP signals, separate them by resetting the end position of last AP and start position of next AP. 16. THEN L = S_Peaks_right_Position(i) - S_Peaks_left_Position(i+1); L1 = L -\(\left\lfloor L/2\right\rfloor\); S_Peaks_right_Position(i) = S_Peaks_right_Position(i) - L1; S_Peaks_left_Position(i+1) = S_Peaks_left_Position(i+1) + L2 ; 17. ENDIF 18. END 19. For i=1:NS-1 //NS is the number of peaks in S_Peaks 20. IF Amplitude(S_Peaks(i)) < 5 mv&&Duration(S_Peaks(i))<1s // remove the s_peak point if they meet these conditions 21. THEN Remove S_Peaks(i) 22. ENDIF 23. END 24. For i=1:NS'-1 // NS' is the number of peaks in S_Peaks 25. IF S_Peaks_left_Position(i+1) == S_Peaks_right_Position(i) | | S_Peaks_left_Position(i+1) == S_Peaks_right_Position(i) + 1 // For adjacent monophasic AP signals, merge them into one APs. 26. THEN // Merge the two APs into one AP  S_Peaks_right_Position(i) = S_Peaks_right_Position(i+1); Delete S_Peaks(i+1), S_Peaks_left_Position(i+1) and S_Peaks_right_Position(i+1). 27. ENDIF 28. END 29. END
```  
**Algorithm 1**AP extraction.