diff options
| -rw-r--r-- | filter-ewma2/ftnoir_ewma_filtercontrols.ui | 2 | ||||
| -rw-r--r-- | filter-ewma2/ftnoir_filter_ewma2.cpp | 21 | ||||
| -rw-r--r-- | filter-ewma2/ftnoir_filter_ewma2.h | 5 | ||||
| -rw-r--r-- | filter-ewma2/lang/nl_NL.ts | 2 | ||||
| -rw-r--r-- | filter-ewma2/lang/ru_RU.ts | 2 | ||||
| -rw-r--r-- | filter-ewma2/lang/stub.ts | 2 | ||||
| -rw-r--r-- | filter-ewma2/lang/zh_CN.ts | 2 | 
7 files changed, 18 insertions, 18 deletions
| diff --git a/filter-ewma2/ftnoir_ewma_filtercontrols.ui b/filter-ewma2/ftnoir_ewma_filtercontrols.ui index e0a98174..d7b42232 100644 --- a/filter-ewma2/ftnoir_ewma_filtercontrols.ui +++ b/filter-ewma2/ftnoir_ewma_filtercontrols.ui @@ -257,7 +257,7 @@ border-color: rgb(0, 0, 0);</string>  <html><head><meta name="qrichtext" content="1" /><style type="text/css">  p, li { white-space: pre-wrap; }  </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt; font-weight:600;">Give the filter up to 60 seconds to warm up and stop shaking.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt; font-weight:600;">Give the filter a few seconds to warm up and stop shaking.</span></p>  <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p>  <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Min:</span></p>  <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Defines the way the filter responds to fast movements;</span></p> diff --git a/filter-ewma2/ftnoir_filter_ewma2.cpp b/filter-ewma2/ftnoir_filter_ewma2.cpp index 25902280..686552ba 100644 --- a/filter-ewma2/ftnoir_filter_ewma2.cpp +++ b/filter-ewma2/ftnoir_filter_ewma2.cpp @@ -33,17 +33,17 @@ void ewma::filter(const double *input, double *output)      {          first_run = false;          timer.start(); -        for (int i=0;i<6;i++) -        { -            last_output[i] = input[i]; -            last_delta[i] = 0; -            last_noise[i] = 0; -        } +        noise_RC = 0.0; +        std::copy(input, input + 6, last_output); +        std::fill(last_delta, last_delta + 6, 0.0); +        std::fill(last_noise, last_noise + 6, 0.0); +        return;      }      // Get the time in seconds since last run and restart the timer.      const double dt = timer.elapsed_seconds();      timer.start();      // Calculate delta_alpha and noise_alpha from dt. +    noise_RC = std::min(noise_RC + dt, noise_RC_max);      double delta_alpha = dt/(dt + delta_RC);      double noise_alpha = dt/(dt + noise_RC); @@ -61,12 +61,12 @@ void ewma::filter(const double *input, double *output)          // Calculate the current and smoothed delta.          double input_value = input[i];          double delta = input_value - last_output[i]; -        if (fabs(delta) > half_turn) +        if (i >= 3 && fabs(delta) > half_turn)          {              delta -= copysign(full_turn, delta);              input_value -= copysign(full_turn, input_value);          } -        last_delta[i] = delta_alpha*delta + (1.0-delta_alpha)*last_delta[i]; +        last_delta[i] += delta_alpha * (delta - last_delta[i]);          // Calculate the current and smoothed noise variance.          double noise = last_delta[i]*last_delta[i];          last_noise[i] = noise_alpha*noise + (1.0-noise_alpha)*last_noise[i]; @@ -78,9 +78,8 @@ void ewma::filter(const double *input, double *output)          // Calculate the dynamic alpha.          double alpha = dt/(dt + RC);          // Calculate the new output position. -        output[i] = alpha*input_value + (1.0-alpha)*last_output[i]; -        if (fabs(output[i]) > half_turn) output[i] -= copysign(full_turn, output[i]); -        last_output[i] = output[i]; +        last_output[i] += alpha * (input_value - last_output[i]); +        output[i] = last_output[i];      }  } diff --git a/filter-ewma2/ftnoir_filter_ewma2.h b/filter-ewma2/ftnoir_filter_ewma2.h index 1cd30a6b..5698157d 100644 --- a/filter-ewma2/ftnoir_filter_ewma2.h +++ b/filter-ewma2/ftnoir_filter_ewma2.h @@ -28,9 +28,10 @@ public:      module_status initialize() override { return status_ok(); }  private:      // Deltas are smoothed over the last 1/60sec. -    const double delta_RC = 1./60; +    static constexpr double delta_RC = 1./60;      // Noise is smoothed over the last 60sec. -    const double noise_RC = 60.0; +    static constexpr double noise_RC_max = 60.0; +    double noise_RC = 0.0;      double last_delta[6];      double last_noise[6];      double last_output[6]; diff --git a/filter-ewma2/lang/nl_NL.ts b/filter-ewma2/lang/nl_NL.ts index b4153053..8c718b7d 100644 --- a/filter-ewma2/lang/nl_NL.ts +++ b/filter-ewma2/lang/nl_NL.ts @@ -28,7 +28,7 @@  <html><head><meta name="qrichtext" content="1" /><style type="text/css">  p, li { white-space: pre-wrap; }  </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt; font-weight:600;">Give the filter up to 60 seconds to warm up and stop shaking.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt; font-weight:600;">Give the filter a few seconds to warm up and stop shaking.</span></p>  <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p>  <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Min:</span></p>  <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Defines the way the filter responds to fast movements;</span></p> diff --git a/filter-ewma2/lang/ru_RU.ts b/filter-ewma2/lang/ru_RU.ts index f8517c87..14afb40e 100644 --- a/filter-ewma2/lang/ru_RU.ts +++ b/filter-ewma2/lang/ru_RU.ts @@ -28,7 +28,7 @@  <html><head><meta name="qrichtext" content="1" /><style type="text/css">  p, li { white-space: pre-wrap; }  </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt; font-weight:600;">Give the filter up to 60 seconds to warm up and stop shaking.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt; font-weight:600;">Give the filter a few seconds to warm up and stop shaking.</span></p>  <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p>  <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Min:</span></p>  <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Defines the way the filter responds to fast movements;</span></p> diff --git a/filter-ewma2/lang/stub.ts b/filter-ewma2/lang/stub.ts index dc39f91f..fcce862e 100644 --- a/filter-ewma2/lang/stub.ts +++ b/filter-ewma2/lang/stub.ts @@ -28,7 +28,7 @@  <html><head><meta name="qrichtext" content="1" /><style type="text/css">  p, li { white-space: pre-wrap; }  </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt; font-weight:600;">Give the filter up to 60 seconds to warm up and stop shaking.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt; font-weight:600;">Give the filter a few seconds to warm up and stop shaking.</span></p>  <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p>  <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Min:</span></p>  <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Defines the way the filter responds to fast movements;</span></p> diff --git a/filter-ewma2/lang/zh_CN.ts b/filter-ewma2/lang/zh_CN.ts index 89d82ec4..a384c45f 100644 --- a/filter-ewma2/lang/zh_CN.ts +++ b/filter-ewma2/lang/zh_CN.ts @@ -28,7 +28,7 @@  <html><head><meta name="qrichtext" content="1" /><style type="text/css">  p, li { white-space: pre-wrap; }  </style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:400; font-style:normal;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt; font-weight:600;">Give the filter up to 60 seconds to warm up and stop shaking.</span></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:10pt; font-weight:600;">Give the filter a few seconds to warm up and stop shaking.</span></p>  <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p>  <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Min:</span></p>  <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Defines the way the filter responds to fast movements;</span></p> | 
