-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLevelEstimator.cpp
More file actions
40 lines (34 loc) · 803 Bytes
/
LevelEstimator.cpp
File metadata and controls
40 lines (34 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// LevelEstimator.cpp
// DSPLibrary
//
// Created by Mayank on 9/11/12.
// Copyright (c) 2012 Mayank Sanganeria. All rights reserved.
//
#include "LevelEstimator.h"
LevelEstimator::LevelEstimator()
{
// default to pass-through
this->a1 = 0; // relese coeffs
this->b0 = 1;
reset();
}
void LevelEstimator::setTau(double tau, double fs)
{
a1 = exp( -1.0 / ( tau * fs ) );
b0 = 1 - a1;
}
void LevelEstimator::reset()
{ // reset filter state
levelEstimate = 0;
}
void LevelEstimator::process (double input, double& output)
{
levelEstimate += b0 * ( fabs( input ) - levelEstimate );
output = levelEstimate;
}
void LevelEstimator::process (float input, float& output)
{
levelEstimate += b0 * ( fabs( input ) - levelEstimate );
output = levelEstimate;
}