从值缓冲区中提取单个波周期 [英] Extract single cycle of a wave from a buffer of values

查看:100
本文介绍了从值缓冲区中提取单个波周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用c#.NET开发一个示波器应用程序,我正在借助zedgraph控件绘制不同类型的波(正弦波,方波等).
我的值存储在大小为1024的缓冲区中,我需要从wave获取单个周期,这意味着我只需要从wave获取数组中单个周期的值即可.

谢谢!

I am developing an application for an oscilloscope in c# .NET, I am drawing different kinds of waves (sine, square etc..) with the help of zedgraph control.
My values are stored in a buffer of size 1024 and I need to get a single cycle from a wave which means I have to get the values from a wave only for a single cycle from array.

Thank you!

推荐答案

如果您的波始终在零附近振荡,那将非常容易.
您要做的就是扫描数组以查找零的第一个过渡,
即从正变负或从负变正(这些转换中的哪一个实际上是不相关的).第一个过渡是循环的起点.
然后,您需要以相同的方式找到2 nd 和3 rd 过渡.第二个过渡是在半个周期间隔,第三个过渡是周期的终点.
如果要提取更多的循环,请记住第三个过渡,并将其作为下一个要提取的循环的起点.

现在,对于您的数据可能不会在零附近振荡的情况:
只需在下面的伪代码中将其标准化即可:

If your waves are always oscillating around zero it would be quite easy.
All you had to do was scan the array for the first transition of zero,
i.e. going from positive to negative or from negative to positive (which of these transitions is actually irrelevant). The first transition is the starting point of the cycle.
Then you need to find the 2nd and 3rd transition in the same fashion. The second transition is at the half cycle interval and the third transistion is the end point of your cycle.
If want to extract more cycles remember the third transition and take that as the starting point of the next cycle to extract.

Now for the case where your data might not oscillate around zero:
Just normalize it like this in the following pseudo code:

double total = 0.0;
// Sum total of all values in buffeer
foreach(OscillatorValue ov in oscillatorValues)
{
    total += ov.Value;
}
// Calculate average of buffer
double average = total / oscillatorValues.Length;
// Normalize the buffer by subtracting the average
foreach(OscillatorValue ov in oscillatorValues)
{
    ov.Value -= average;
}



一些提示:
-当您从缓冲区的开头开始并且不知道wave的先前状态时,在某些情况下,您可能希望将此起点也视为过渡.

-规范化应该在缓冲区的副本上进行.

-如果不确定波是否在零附近振荡,请始终在搜索周期之前进行归一化.

那应该可以帮助您入门. :)

问候,

曼弗雷德(Manfred)



A couple of hints:
- When you start at the beginning of the buffer and have no knowledge of the previous state of the wave, there are cases you might want to consider this start also as a transition.

- The normalization should be done on a copy of your buffer.

- Alway normalize before searching for a cycle if you can''t be sure if the wave oscillates around zero.

That should help you get started. :)

Regards,

Manfred


这篇关于从值缓冲区中提取单个波周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆