Skip to content

Commit 7c38a54

Browse files
committed
smf.h: Use formulae from ewma.h.
1 parent 932cef4 commit 7c38a54

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

smf.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,16 @@ struct smf_state {
3030
double g0, m0, m1, c0, c1;
3131
};
3232

33-
#define SMF_RISE_TIME(x) (0.349/((x)/1000.0))
33+
#define SMF_RISE_TIME(x) ((x)/1000.0/2.1972) /* 10%-90% rise time in ms (one pole only) */
3434

3535
static inline void smf_reset(struct smf_state *state)
3636
{
3737
state->m0 = state->m1 = 0.0;
3838
}
3939

40-
static inline void smf_asym_init(struct smf_state *state, double fs, double f0, double sens_rise, double sens_fall)
40+
static inline void smf_asym_init(struct smf_state *state, double fs, double tc, double sens_rise, double sens_fall)
4141
{
42-
const double gc = tan(M_PI*(f0/fs));
43-
state->g0 = 2.0*gc/(1.0+gc);
42+
state->g0 = 1.0-exp(-1.0/(fs*tc));
4443
state->c0 = sens_rise*4.0;
4544
state->c1 = sens_fall*4.0;
4645
smf_reset(state);
@@ -54,9 +53,9 @@ static inline void smf_init(struct smf_state *state, double fs, double f0, doubl
5453
static inline double smf_run_c(struct smf_state *state, double s, const double c)
5554
{
5655
double g = state->g0 + c*fabs(state->m0 - state->m1);
57-
if (g > 1.0) g = 1.0;
58-
state->m0 = state->m0 + g*(s - state->m0);
59-
state->m1 = state->m1 + g*(state->m0 - state->m1);
56+
if (g > 0.39) g = 0.39;
57+
state->m0 = g*(s - state->m0) + state->m0;
58+
state->m1 = g*(state->m0 - state->m1) + state->m1;
6059
return state->m1;
6160
}
6261

0 commit comments

Comments
 (0)