diff options
author | Donovan Baarda <abo@minkirri.apana.org.au> | 2014-10-21 11:05:25 +1100 |
---|---|---|
committer | Donovan Baarda <abo@minkirri.apana.org.au> | 2014-10-22 17:18:56 +1100 |
commit | 7c6fa40b5f91619f811ee31773df947fa6e04b1b (patch) | |
tree | 339a4daf7ab51c63fabf7517f440dfdf1ba605c7 | |
parent | 82e5b48f0f0c1667c089d6c7e02e80085f999482 (diff) |
Rename filter() arguments to "input" and "output".
Rename delta, noise, and output state attributes to last_* for consistency.
-rw-r--r-- | ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp | 22 | ||||
-rw-r--r-- | ftnoir_filter_ewma2/ftnoir_filter_ewma2.h | 9 |
2 files changed, 14 insertions, 17 deletions
diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp index 8520eb71..cdf18263 100644 --- a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp +++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.cpp @@ -37,16 +37,15 @@ void FTNoIR_Filter::reset() timer.invalidate(); } -void FTNoIR_Filter::filter(const double *target_camera_position, - double *new_camera_position) +void FTNoIR_Filter::filter(const double *input, double *output) { // Start the timer and initialise filter state if it's not running. if (!timer.isValid()) { timer.start(); for (int i=0;i<6;i++) { - output[i] = target_camera_position[i]; - delta[i] = 0.0; - noise[i] = 0.0; + last_output[i] = input[i]; + last_delta[i] = 0.0; + last_noise[i] = 0.0; } } // Get the time in seconds since last run and restart the timer. @@ -57,13 +56,13 @@ void FTNoIR_Filter::filter(const double *target_camera_position, // Calculate the new camera position. for (int i=0;i<6;i++) { // Calculate the current and smoothed delta. - double new_delta = target_camera_position[i]-output[i]; - delta[i] = delta_alpha*new_delta + (1.0-delta_alpha)*delta[i]; + double delta = input[i] - last_output[i]; + last_delta[i] = delta_alpha*delta + (1.0-delta_alpha)*last_delta[i]; // Calculate the current and smoothed noise variance. - double new_noise = delta[i]*delta[i]; - noise[i] = noise_alpha*new_noise + (1.0-noise_alpha)*noise[i]; + double noise = last_delta[i]*last_delta[i]; + last_noise[i] = noise_alpha*noise + (1.0-noise_alpha)*last_noise[i]; // Normalise the noise between 0->1 for 0->9 variances (0->3 stddevs). - double norm_noise = std::min<double>(new_noise/(9.0*noise[i]), 1.0); + double norm_noise = std::min<double>(noise/(9.0*last_noise[i]), 1.0); // Calculate the smoothing 0.0->1.0 from the normalized noise. // TODO(abo): change kSmoothingScaleCurve to a float where 1.0 is sqrt(norm_noise). double smoothing = 1.0 - pow(norm_noise, s.kSmoothingScaleCurve/20.0); @@ -73,8 +72,7 @@ void FTNoIR_Filter::filter(const double *target_camera_position, // Calculate the dynamic alpha. double alpha = dt/(dt + RC); // Calculate the new output position. - output[i] = alpha*target_camera_position[i] + (1.0-alpha)*output[i]; - new_camera_position[i] = output[i]; + output[i] = last_output[i] = alpha*input[i] + (1.0-alpha)*last_output[i]; } } diff --git a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h index d311d0e5..73c0df99 100644 --- a/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h +++ b/ftnoir_filter_ewma2/ftnoir_filter_ewma2.h @@ -26,17 +26,16 @@ class FTNoIR_Filter : public IFilter public: FTNoIR_Filter(); void reset(); - void filter(const double *target_camera_position, - double *new_camera_position); + void filter(const double *input, double *output); void receiveSettings(); private: // Deltas are smoothed over the last 1/60sec (16ms). const double delta_RC = 0.016; // Noise is smoothed over the last 60sec. const double noise_RC = 60.0; - double delta[6]; - double noise[6]; - double output[6]; + double last_delta[6]; + double last_noise[6]; + double last_output[6]; QElapsedTimer timer; settings s; }; |