在C#.net中计算信号的频率 [英] calculating frequency for signal in c# .net

查看:355
本文介绍了在C#.net中计算信号的频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我正在用c#.NET开发示波器的应用程序,我正在借助zedgraph控件绘制不同类型的波(正弦波,方波等).
我从示波器获取值并将其存储在大小为1024(字节数组)的缓冲区中,并且必须在运行时计算诸如时间段,频率,上升时间,下降时间等参数.
为此,我只需要提取整个信号的单个周期.另一个问题是值并不总是连续地上升或下降,平均值存储在缓冲区中是这样的[0,0,0,1,1,2,3 ,4,5,5,6,6,6,5,5,4,3,2,1,1,0,0,0 .....].信号不断从机器接收.
不确定波是否总是在零附近振荡.
谢谢
问候
Nilesh

Hello,
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.
I get values from oscilloscope and stored in a buffer of size 1024(byte array) and have to calculate parameters like time period, Frequency, rise time, fall time etc at run time.
for this purpose i have to extract only a single cycle of whole signal.one more problem is that values are not always rise or fall continuously mean values are stored in buffer like this[0,0,0,1,1,2,3,4,5,5,6,6,6,5,5,4,3,2,1,1,0,0,0..........]. signals are continuously receive from machine.
it is not sure that waves are always oscillating around zero.
Thanks
Regards
Nilesh

推荐答案

如果您确实需要频率,则波形是否在零附近振荡"(平均信号上移或下移)都没有关系. br/>
所有相关的算法都可以在这里找到:

http://en.wikipedia.org/wiki/Fourier_analysis [ http://en.wikipedia.org/wiki/Fourier_transform_spectroscopy [ http://en.wikipedia.org/wiki/Fast_Fourier_transform [ http://en.wikipedia.org/wiki/Fast_food_restaurant [ ^ ]或在这里:http://en.wikipedia.org/wiki/Fast_%26_Furious [
If you really need frequencies, it does not really matter if the waves are "oscillating around zero" or not (average signal shifted up or down).

All relevant algorithms can be found here:

http://en.wikipedia.org/wiki/Fourier_analysis[^],

http://en.wikipedia.org/wiki/Fourier_transform_spectroscopy[^],

http://en.wikipedia.org/wiki/Fast_Fourier_transform[^],

but not here: http://en.wikipedia.org/wiki/Fast_food_restaurant[^] or here: http://en.wikipedia.org/wiki/Fast_%26_Furious[^] :).


首先,没有示波器曾经使用过为我提供了整数样本,所以我假设您正在接收实数值,并且仅以整数为例.我还将假设采样信号是周期性的,即使该周期可能未知.

选择一个采样集,该采样集的起始点等于记录的最小值和最大值之间的中点,然后终止于信号再次与该值相交的下一个点.计算集合中的样本数,然后除以采样率.将其作为信号的周期,1/T =频率.计算此样本集的RMS值,然后除以2;这是信号的直流偏移.从样本中的每个点减去DC偏移以将值归一化为0轴.现在循环遍历样本以找到最大值和最小值,并找到信号值相对于峰值超过90%(上升)和10%(下降)的交叉点.将集合中的样本总数设为N,样本之间的每个步骤代表T/N秒.通过检查相对于归一化零交叉点的10%和90%样本的索引,您应该可以轻松地计算出采样信号的上升和下降时间.

FFT很方便,但是它们是用于频域分析的,而您要的是时域结果.除非您非常准确地知道每个样本集的初始条件和边界条件,否则从频域转换到时域将产生任意且不准确的结果.在这种情况下,比较容易进行时域计算,但是请确保以适当的速率采集示波器样本.我假设您可以控制范围"设置以及监视结果的能力.如果您采样的频率低于基本频率的两倍,则说明您正在丢失信息.如果您采样的数量远远超过此数量,则可能会出现混叠错误.按照我的描述进行初始计算,然后调整示波器"的扫描速率以适当的速率收集样本.
First off, no oscilloscope I''ve ever used gave me integer samples, so I''ll assume you are receiving real values and just used integers for a example. I''ll also assume that the sample signal is known to be periodic, even though the period may not be known.

Select a sample set beginning at an arbitrary crossing point equal to the midpoint between the minimum and maximum values recorded, and ending at the next point where the signal again crosses that value. Count the number of samples in the set and divide by the sample rate. Take this to be the period of the signal, and 1/T = frequency. Calculate the RMS value of this sample set and divide by 2; this is the DC offset of the signal. Subtract the DC offset from each point in the sample to normalize the values to the 0 axis. Now cycle through the samples to find the maxima and minima, and locate the crossing points where the signal values cross the 90% (rising) and 10% (falling) values, relative to the peaks. Taking the total number of samples in the set as N, each step between samples represents T/N seconds. By checking the indices of the 10% and 90% samples, relative to the normalized zero crossings, you should easily be able to calculate the rise and fall times of the sampled signal.

FFTs are handy, but they''re meant for frequency domain analyses, and you''re asking for time domain results. Unless you know very accurately the initial and boundary conditions for each sample set, converting from the frequency domain to the time domain will yield arbitrary and inaccurate results. Sticking to time domain calculations is easier in this case, but make sure that you take your oscilloscope samples at an appropriate rate. I assume that you have control over the ''scope settings, as well as the ability to monitor results. If you are sampling at less than twice the fundamental frequency, you''re losing information; if you sample at much more than that, you risk aliasing errors. Do the initial calculation as I''ve described, then adjust the sweep rate of the ''scope to collect samples at an appropriate rate.


这篇关于在C#.net中计算信号的频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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