Skip to content

Commit

Permalink
Fixed minor bug in code
Browse files Browse the repository at this point in the history
Updated indentation
  • Loading branch information
pjpei committed Oct 10, 2024
1 parent f17f26f commit f442e79
Showing 1 changed file with 17 additions and 40 deletions.
57 changes: 17 additions & 40 deletions src/main/common/lulu.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
#endif /* __ARM_ACLE */
#include <fenv.h>

void luluFilterInit(luluFilter_t *filter, int N)
{
if (N > 15)
{
void luluFilterInit(luluFilter_t *filter, int N) {
if (N > 15) {
N = 15;
}
if (N < 1)
{
if (N < 1) {
N = 1;
}
filter->N = N;
Expand All @@ -34,25 +31,20 @@ void luluFilterInit(luluFilter_t *filter, int N)
memset(filter->luluInterimB, 0, sizeof(float) * (filter->windowSize));
}

FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, int windowSize)
{
FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, int windowSize) {
register float curVal = 0;
register float curValB = 0;
for (int N = 1; N <= filterN; N++)
{
for (int N = 1; N <= filterN; N++) {
int indexNeg = (index + windowSize - 2 * N) % windowSize;
register int curIndex = (indexNeg + 1) % windowSize;
register float prevVal = series[indexNeg];
register float prevValB = seriesB[indexNeg];
register int indexPos = (curIndex + N) % windowSize;
for (int i = windowSize - 2 * N; i < windowSize - N; i++)
{
if (indexPos >= windowSize)
{
for (int i = windowSize - 2 * N; i < windowSize - N; i++) {
if (indexPos >= windowSize) {
indexPos = 0;
}
if (curIndex >= windowSize)
{
if (curIndex >= windowSize) {
curIndex = 0;
}

Expand All @@ -61,18 +53,13 @@ FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, i
register float nextVal = series[indexPos];
register float nextValB = seriesB[indexPos];

if (prevVal < curVal && curVal > nextVal)
{
if (prevVal < curVal && curVal > nextVal) {
float maxValue = MAX(prevVal, nextVal);

series[curIndex] = maxValue;
}

if (prevValB < curValB && curValB > nextValB)
{
if (prevValB < curValB && curValB > nextValB) {
float maxValue = MAX(prevValB, nextValB);

curVal = maxValue;
seriesB[curIndex] = maxValue;
}
prevVal = curVal;
Expand All @@ -85,14 +72,11 @@ FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, i
prevVal = series[indexNeg];
prevValB = seriesB[indexNeg];
indexPos = (curIndex + N) % windowSize;
for (int i = windowSize - 2 * N; i < windowSize - N; i++)
{
if (indexPos >= windowSize)
{
for (int i = windowSize - 2 * N; i < windowSize - N; i++) {
if (indexPos >= windowSize) {
indexPos = 0;
}
if (curIndex >= windowSize)
{
if (curIndex >= windowSize) {
curIndex = 0;
}

Expand All @@ -101,18 +85,13 @@ FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, i
register float nextVal = series[indexPos];
register float nextValB = seriesB[indexPos];

if (prevVal > curVal && curVal < nextVal)
{
if (prevVal > curVal && curVal < nextVal) {
float minValue = MIN(prevVal, nextVal);

curVal = minValue;
series[curIndex] = minValue;
}

if (prevValB > curValB && curValB < nextValB)
{
if (prevValB > curValB && curValB < nextValB) {
float minValue = MIN(prevValB, nextValB);
curValB = minValue;
seriesB[curIndex] = minValue;
}
prevVal = curVal;
Expand All @@ -124,8 +103,7 @@ FAST_CODE float fixRoad(float *series, float *seriesB, int index, int filterN, i
return (curVal - curValB) / 2;
}

FAST_CODE float luluFilterPartialApply(luluFilter_t *filter, float input)
{
FAST_CODE float luluFilterPartialApply(luluFilter_t *filter, float input) {
// This is the value N of the LULU filter.
register int filterN = filter->N;
// This is the total window size for the rolling buffer
Expand All @@ -140,8 +118,7 @@ FAST_CODE float luluFilterPartialApply(luluFilter_t *filter, float input)
return fixRoad(filter->luluInterim, filter->luluInterimB, windowIndex, filterN, filterWindow);
}

FAST_CODE float luluFilterApply(luluFilter_t *filter, float input)
{
FAST_CODE float luluFilterApply(luluFilter_t *filter, float input) {
// This is the UL filter
float resultA = luluFilterPartialApply(filter, input);
// We use the median interpretation of this filter to remove bias in the output
Expand Down

0 comments on commit f442e79

Please sign in to comment.