数据库型网站,遵义专业建站,网站被主流搜索引擎收录的网页数量是多少,微信微网站怎么进入环形缓冲数据结构#xff0c;就是如下图一样的一个收尾相接的列表 在index指针指到4时#xff0c;再往里添加数据#xff0c;index就会指向0#xff0c;并覆盖已有数据。
如何绘制Sin函数#xff0c;请看下面一篇文章
Unity中如何实现绘制Sin函数图像-CSDN博客
接下来要…环形缓冲数据结构就是如下图一样的一个收尾相接的列表 在index指针指到4时再往里添加数据index就会指向0并覆盖已有数据。
如何绘制Sin函数请看下面一篇文章
Unity中如何实现绘制Sin函数图像-CSDN博客
接下来要使用Sin函数来模拟输入使用噪声来模拟抖动代码如下
amplitude * Mathf.Sin(tau * frequency * x) Random.Range(0f,1f);
观察现在的正弦波 然后创建环形平滑类
public class SlidingAverage
{float[] buffer;float sum;int lastIndex;public SlidingAverage(int num_samples, float initial_value){buffer new float[num_samples];lastIndex 0;reset(initial_value);}public void reset(float value){sum value * buffer.Length;for (int i 0; i buffer.Length; i)buffer[i] value;}public void pushValue(float value){sum - buffer[lastIndex]; // subtract the oldest sample from the sum sum value; // add the new sample buffer[lastIndex] value; // store the new sample // advance the index and wrap it around lastIndex 1;if (lastIndex buffer.Length) lastIndex 0;}public float getSmoothedValue(){return sum / buffer.Length;}
}
使用平滑类
slidingAverage new SlidingAverage(10, 0); 下面是使用10个值平滑后的正弦波 可以看到抖动明显消除了perfect
参考链接
快速提示使用 “Ring Buffer” 数据结构平滑抖动值 |Envato Tuts (tutsplus.com)