## 3 Software Triggering Strategies
### DC Signal-Based Triggers  
Three different algorithms based on DC signals have been implemented. They use thresholds based on a predefined reference value of the signal (_DC Reference trigger_), the difference of mean values (_DC Delta trigger_), and the derivative (_DC Slope trigger_). These triggers should be sufficient to detect most of the expected power quality events in DC networks [18]. As this section describes the implemented algorithms, a summary of the parameters and variables used in those algorithms is given in Table 1.  
The _DC Reference trigger_ uses the subsampled (200 kS/s from 4 MS/s) DC signal to compute the average of the data in a configured time window. The subsampling has been implemented for a lighter and more agile performance. Once the average is obtained, the threshold value is easy to choose, considering the nominal value of the DC bus for the voltage channel and the maximum expected current for the current channel. An adjustable tolerance is added to both thresholds to allow certain signal variations. The pseudo-code for this trigger can be seen in Algorithm 1. The _DC Delta trigger_ calculates the mean values for two consecutive equal-length time windows of samples using the same subsampling as the _DC Reference trigger_ trigger. Then, it compares the difference between both average values, firing the trigger when this difference is bigger than a configurable threshold value. The pseudo-code in Algorithm 2 describes this trigger. Finally, the _DC Slope trigger_ has been implemented modularly with a call to a generic derivative function which uses as parameters the waveform data and the time value when computing the derivative. This modularity allows different approaches to calculate the derivative of noisy signals. The Optimised Sampling Frequency (OSF) approach [19] has been used in this work. The pseudo-code of Algorithm 3 shows how this trigger was implemented. \begin{table}
\begin{tabular}{p{113.8 pt} p{113.8 pt}} \hline \hline
**Name** & **Definition** \\ \hline
**Variables** & \\ \hline subsampled\_waveform\_sample & The last sample of the subsampled waveform \\ wf\_index & The index of the current sample in the subsampled \\  & waveform array \\ wf\_ref\_accumulated & Temporary variable used to accumulate values \\  & in order to calculate the mean value \\ computed\_mean & The mean value calculated over the time window \\ wf\_delta\_accumulated & Temporary variable used to accumulate values \\  & in order to calculate the mean value \\ previous\_mean & The previous mean value calculated \\ current\_derivative & The derivative (slope) calculated with the last points \\ \hline
**Parameters** & \\ \hline threshold\_lo & The lower level threshold for the _DC Reference_ \\  & _trigger_[\(V\)] \\ threshold\_hi & The higher level threshold for the _DC Reference_ \\  & _trigger_[\(V\)] \\ window\_ref\_size & The size of the time window for the mean \\  & computation in the _DC Reference trigger_ \\  & [number of samples] \\ threshold\_delta & The threshold of the of the mean variation for the \\  & _DC Delta trigger_[\(V\)] \\ window\_delta\_size & The size of the time window for the mean \\  & computation in the _DC Delta trigger_[\(number of samples] \\ threshold\_derivative & The threshold of the slope for the _DC Slope_ \\  & _trigger_[\(V/ms\)] \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Algorithm variables and parameters. This method calculates the signal derivative using values in a time window defined as a multiple of the sampling period providing a lightweight derivative computation robust against noise. The width of the time window is selected, considering the noise present in the actual signals. A wider window will give a better noise rejection at the expense of a delay in the triggering. It is worth noting that, given the amount of memory in the PC, the circular buffer can be of the order of the seconds, and a delay of microseconds is negligible in this context.