From 46e97d5da394aed103b6e41336699c7209fb03b0 Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Wed, 15 Jul 2020 18:13:06 +0200 Subject: Added ndpi_data_window_variance() and ndpi_data_window_stddev() API calls --- src/lib/ndpi_analyze.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/lib') diff --git a/src/lib/ndpi_analyze.c b/src/lib/ndpi_analyze.c index 4b4fbf72b..7d4aa5f47 100644 --- a/src/lib/ndpi_analyze.c +++ b/src/lib/ndpi_analyze.c @@ -157,6 +157,32 @@ float ndpi_data_window_average(struct ndpi_analyze_struct *s) { /* ********************************************************************************* */ +/* Compute the variance only on the sliding window */ +float ndpi_data_window_variance(struct ndpi_analyze_struct *s) { + if(s->num_values_array_len) { + float sum = 0.0, avg = ndpi_data_window_average(s); + u_int16_t i, n = ndpi_min(s->num_data_entries, s->num_values_array_len); + + if(n == 0) + return(0); + + for(i=0; ivalues[i]-avg, 2); + + return((float)sum / (float)n); + } else + return(0); +} + +/* ********************************************************************************* */ + +/* Compute the variance only on the sliding window */ +float ndpi_data_window_stddev(struct ndpi_analyze_struct *s) { + return(sqrt(ndpi_data_window_variance(s))); +} + + /* ********************************************************************************* */ + /* Compute entropy on the last sliding window values */ -- cgit v1.2.3