MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.
Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.
/**
* Zero-Latency Exponential Moving Average.
*/
float zlema(float* vals, int numVals, int currentSample)
{
static float factor = 0;
static int lag = 0;
static float lastema = 0;
float ema;
if(currentSample <= 1)
{
ema = vals[0];
factor = 2.0 / (((float) numVals) + 1.0);
lag = (numVals - 1) / 2;
}
else
{
ema = (factor * ((2.0 * vals[0]) - vals[lag])) +
((1.0 - factor) * lastema);
lastema = ema;
}
return ema;
}
...
static long cs0 = 0;
for(int cnt = NUM_AVERAGE_VALS - 1; cnt > 0; cnt--)
{
m_arrAct0AverageVals[cnt] = m_arrAct0AverageVals[cnt-1];
}
m_arrAct0AverageVals[0] = lPos;
float lPosNew = zlema(m_arrAct0AverageVals, NUM_AVERAGE_VALS, cs0);
cs0++;
...
Would be extremely grateful if someone with a better understanding of the math could please sanity check this for me to see if I've got anything slightly wrong?float y[NUM_VALS -1];
float dy;
float A;
y[0] = 0;
for (int cnt = 1; cnt < NUM_VALS; cnt++){
dy = (u[cnt] - y[cnt-1])/A;
y[cnt] = y[cnt-1] + dy;
}
function NextOutput(float input,float A){
static float dy = 0;
static float y = 0;
dy = (input - y)/A;
y = y + dy;
return y;
}
Copy-of-Low-Pass-Filter.xls
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Table function | 6 | 54 | |
An API detour question | 7 | 93 | |
Memory going from 12gb to 64gb or 96gb. worth it? | 15 | 202 | |
What's wrong with the delete function in this program for queue using array? | 8 | 26 |
Join the community of 500,000 technology professionals and ask your questions.