smoothing function

hi, I have to write a function that gets values from a main programm and I have to return a smoothed value. this is what I thought it should be, but somehow the outcome isn't right. I think the outcome is just the inputvalue devided by the windowsize. can someone give me a hint where I went wrong and\or what I am overseeing, because I feel rather stuck...
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
#define windowSize 17 
double smoothValue;
double sum;
double arr[windowSize];
int i=windowSize;

sum = 0.0;
if (i<windowSize)
	{
	i++;
	}
else
	{
	i = 0;
	}	
arr[i]=value;

for(int x=0; x<windowSize; x++)
 		{
 		sum += arr[x];
 		}
 		
smoothValue = (sum / windowSize);
	
return smoothValue;	
 	
I'm confused sorry mate.
None of this looks like mathematics to smooth a function.
Also this:
arr[i]=value;
from the snippet you've shown you have not defined the variable value, so it's difficult to advise because of this.

Providing the input function is fairly "well-behaved" in the first place, you could look at bezier curves or cubic splines perhaps?

Unless I have completely misunderstood your question. Apologies if I have.


edit: Do you actually mean you want to find the average from a group of values? That's what line 23 suggests to me.
Last edited on
Topic archived. No new replies allowed.