Here's a template class I wrote a while ago I call a WindowFilter. It is essentially a moving average as K5054 mentioned previously. In your case, you could set the size of the window to be 10 and it will give you the average of the last 10 samples. Best of luck with it.
#pragma once
#define WINDOWFILTER_H
#include <vector>
template< typename T >
class WindowFilter
{
public:
WindowFilter( int size=8 )
{
Resize( size );
}
void Resize( int newsize )
{
int sizenow = (int) m_Data.size();
if( newsize == sizenow )
return;
T newval = 0;
m_Data.resize( newsize, newval );
if( m_Count > newsize )
m_Count = newsize;
m_Sum = 0;
for( int n = 0; n < m_Count; ++n )
m_Sum += m_Data[ n ];
if( m_Last >= m_Count )
m_Last = m_Count - 1;
}
T Add( T newvalue )
{
int datasize = (int) m_Data.size();
int index = 0;
if( m_Count != 0 )
{
index = m_Last + 1;
if( index >= datasize )
index = 0;
}
T lastvalue = m_Data[ index ];
m_Sum -= lastvalue;
m_Data[ index ] = newvalue;
m_Sum += newvalue;
m_Last = index;
if( m_Count < datasize )
++m_Count;
return Result();
}
T Result() const
{
return m_Count ? m_Sum / m_Count : 0;
}
public:
using vdata = std::vector< T >;
vdata m_Data;
T m_Sum { 0 }; int m_Count { 0 }; int m_Last { -1 }; };
using dwinfilter = WindowFilter< double >;
using fwinfilter = WindowFilter< float >;