Data Structures | |
struct | EMAVG |
Defines the Exponential Moving Average (EMAVG) structure. More... | |
Functions | |
static void | EMAVG_reset (EMAVG *v) |
resets internal storage data More... | |
static void | EMAVG_config (EMAVG *v, float32_t multiplier) |
configures EMAVG module More... | |
static void | EMAVG_run (EMAVG *v, float in) |
Run EMAVG module. More... | |
Typedefs | |
typedef float | float32_t |
typedef long double | float64_t |
Macros | |
#define | C2000_IEEE754_TYPES |
The exponential moving average (EMAVG) API provides a set of functions that performs exponential moving average over data.
The math operation performed can be represented in time domain as follows:
Where in is the input data that is passed as an argument to the EMAVG function at sample instance 'n',
EMAVG.Out [n] is the exponential moving average output at time instance 'n',
EMAVG.Out [n-1] is the exponential moving average output at time instance 'n-1',
multiplier is the weighting factor used in exponential moving average
In z-domain the equation can be interpreted as
This can be seen as a special case for a Low Pass Filter, where pass band gain is equal to multiplier and filter time constant is (1-multiplier).
Note multiplier is always ≤ 1, hence (1-multiplier) is always a positive value. Also the lower the value of multiplier, the larger the time constant and more sluggish the response of the filter.
The following diagram illustrates the math function operated on in this block:
The block is used in the PFC software to get the average value of AC Line. The multiplier value for this can be estimated through two methods as follows:
Time Domain: The PFC stage runs at 100Khz and the input AC signal is 60Hz. As the average of the rectified sine signal is desired the effective frequency of the signal being averaged is 120Hz. This implies that (100Khz/120) = 833 samples in one half sine. For the average to be true representation the average needs to be taken over multiple sine halves (note: taking average over integral number of sine halves is not necessary). The multiplier value distributes the error equally over the number of samples for which average is taken. For AC line average a value of 4000 samples is chosen, as it averages roughly over 4 sine halves. Therefore:
Frequency Domain: Alternatively the multiplier value can be estimated from the z-domain representation as well. The signal is sampled at 100Khz and the frequency content is at 60Hz. Only the DC value is desired, therefore assuming a cut-off frequency of 5Hz the value can be estimated as follows:
For a first order approximation,
where T is the sampling period and solving the equation:
Comparing with the analog domain low pass filter, the following equation can be written:
The following is a sequence of steps that can be followed to use the EMAVG API library functions in an existing C program. For a set of code examples that illustrates the use of this library, see the examples in the Digial Power SDK.
Before you can using the library you must add the libraries directory path as a searchable directory in the project include options. This can be done by right-clicking on the project in the Project Explorer window, selecting "Properties". In the window that opens, navigate to "Build, C2000 Compiler, Include Options". In the include path
window, click on the green add directory path button on the right and enter the path to the Digital Power SDK libraries directory.
This allows CCS to search the entire directory for library files.
Once that is done you should follow these steps incorporate this library into your project:
There is only one module in this package, the APIs can be referenced at EMAVG. The module headers are located at emavg.h.
|
inlinestatic |