y=A*sin(wt+φ)+δ 正弦函数 t:时间变量 y:函数值 其它为常量 现在 ,你应该是知道 y 和t ,求出w就可以知道它的周期,你可以用多组y,t拟合函数,然后用T=2π/w求得周期
“直接比较得到数据的大小,确定波峰,然后根据波峰和波峰间的距离求怎么做”分析你得到的数据,如果一个值比它前后的值都大,那么它就是波峰(a[i]>a[i-1] And a[i]>a[i+1],则a[i]处就是波峰)。第一次波峰出现的时间/位置记为T1; 分析后面的数据,找出下一个相邻波峰出现的时间/位置,记为T2。 T2 - T1 就是你要的周期。
Private Function peak_data(ByVal data1 As Single) As Single Dim d As Integer Dim cnt As Integer Dim a As Integer Dim y() As Single Dim x() As Integer d = 0 y(d) = data1 d = d + 1 '记数 For a = 1 To d If y(a) > y(a - 1) And y(a) > y(a + 1) Then '判断 cnt = cnt + 1 '波峰个数 x(cnt) = a '保存位置 End If Next period= x(cnt)-x(1)/cnt End Function这样??y(d) = data1总是提示下标越界
ByVal data1 As Single 只传过来一个数值怎么分析周期?如果每次传一个,固定每秒传若干条数据的话,那你需要先把传来的数据保存到y()中,积累一定时间之后才能分析出来。
单片机采集信号,数据通过串口传到PC,VB进行处理
那Com口传来的数据肯定不只一个吧?ByVal data1 As Single,只有一个点,其它点的数据呢?
当然不止一个,我搞错了,应该这样?byref y() as single,
Private Function peak_data(Byref y() As Single ,n as integer) As Single Dim d As Integer Dim cnt As Integer Dim a As Integer Dim x() As Integer For a = 1 To 499 If y(a) > y(a - 1) And y(a) > y(a + 1) Then '判断 cnt = cnt + 1 '波峰个数 x(cnt) = a '保存位置 End If Next peak_data=cnt End Function for i=1 to 499 resp_data(i)=data'数据存入数组 next 调用时:resp=peak_data(resp_data(),499)
如果data1是接收到的数据,那起码也应该是这样Private Function peak_data(ByVal data1() As Single) As Single Dim cnt As Integer Dim a As Integer Dim y() As Single Dim x() As Integer cnt = 0 y = data1 For a = 1 To UBound(y) - 1 If y(a) > y(a - 1) And y(a) > y(a + 1) Then '判断 cnt = cnt + 1 '波峰个数 ReDim Preserve x(cnt) x(cnt) = a '保存位置 End If Next period = (x(cnt) - x(1)) / (cnt - 1) End Function
那设采样频率为f,T = period/f 就是严格意义上的时间周期了。
For c = 1 To 500 data(c) = d_oldxy(1) Next p= peak_data(respdata()) 以上调用的时候 怎么出现这一部分:period = (x(cnt) - x(1)) / (cnt - 1)下标越界呢
For c = 1 To 500 data(c) = d_oldxy(1) Next p= peak_data(respdata()) respdata()的声明和赋值在哪里?只看到对data()的操作,没有看到对respdata的操作。莫非你是说 p= peak_data(data()) 另外注意两个问题,一是data(c) = d_oldxy(1) ,难道数组里面所有值都一样? 还有注意数组的下标是从0还是从1开始,处理数据的时候两边要统一。
For c=1 To 500 data1(c)= d_oldxy(1) Next p=peak_data(data1()) d_oldxy(1)是画图用的纵坐标,也就是数据了 上面不能把那些数据赋给数组??不明白为什么??????
data1(c)= d_oldxy(1),500个数据全部等于d_oldxy(1)这一个值?
d_oldxy(1)中的数据也是变化的啊,保存到.txt文件中的值也是变化的啊
晕死了~ For c=1 To 500 data1(c)= d_oldxy(1) Next 这个循环中d_oldxy(1)的值根本就没变,在哪变化的?
在VB中看到的波形是一正弦波,试了一下,总是测不出来.
正弦函数
t:时间变量
y:函数值
其它为常量
现在 ,你应该是知道 y 和t ,求出w就可以知道它的周期,你可以用多组y,t拟合函数,然后用T=2π/w求得周期
分析后面的数据,找出下一个相邻波峰出现的时间/位置,记为T2。
T2 - T1 就是你要的周期。
Dim d As Integer
Dim cnt As Integer
Dim a As Integer
Dim y() As Single
Dim x() As Integer
d = 0
y(d) = data1
d = d + 1 '记数
For a = 1 To d
If y(a) > y(a - 1) And y(a) > y(a + 1) Then '判断
cnt = cnt + 1 '波峰个数
x(cnt) = a '保存位置
End If
Next
period= x(cnt)-x(1)/cnt
End Function这样??y(d) = data1总是提示下标越界
y(d) = data1
y(a) > y(a - 1) And y(a) > y(a + 1)这样当然不行了。先将你说的数据批量读到y()数组中去。
只传过来一个数值怎么分析周期?如果每次传一个,固定每秒传若干条数据的话,那你需要先把传来的数据保存到y()中,积累一定时间之后才能分析出来。
Dim d As Integer
Dim cnt As Integer
Dim a As Integer
Dim x() As Integer
For a = 1 To 499
If y(a) > y(a - 1) And y(a) > y(a + 1) Then '判断
cnt = cnt + 1 '波峰个数
x(cnt) = a '保存位置
End If
Next
peak_data=cnt
End Function
for i=1 to 499
resp_data(i)=data'数据存入数组
next
调用时:resp=peak_data(resp_data(),499)
Dim cnt As Integer
Dim a As Integer
Dim y() As Single
Dim x() As Integer
cnt = 0
y = data1
For a = 1 To UBound(y) - 1
If y(a) > y(a - 1) And y(a) > y(a + 1) Then '判断
cnt = cnt + 1 '波峰个数
ReDim Preserve x(cnt)
x(cnt) = a '保存位置
End If
Next
period = (x(cnt) - x(1)) / (cnt - 1)
End Function
data(c) = d_oldxy(1)
Next
p= peak_data(respdata())
以上调用的时候 怎么出现这一部分:period = (x(cnt) - x(1)) / (cnt - 1)下标越界呢
data(c) = d_oldxy(1)
Next
p= peak_data(respdata()) respdata()的声明和赋值在哪里?只看到对data()的操作,没有看到对respdata的操作。莫非你是说
p= peak_data(data()) 另外注意两个问题,一是data(c) = d_oldxy(1) ,难道数组里面所有值都一样?
还有注意数组的下标是从0还是从1开始,处理数据的时候两边要统一。
data1(c)= d_oldxy(1)
Next
p=peak_data(data1()) d_oldxy(1)是画图用的纵坐标,也就是数据了
上面不能把那些数据赋给数组??不明白为什么??????
For c=1 To 500
data1(c)= d_oldxy(1)
Next
这个循环中d_oldxy(1)的值根本就没变,在哪变化的?
............
Picture1.Line (x0,y1 * 4)-(x0 + 1, picture * 4), RGB(255, 255, 255)画图部分......
k=k+1
y(k)=y1
x(k)=x0
x0=x0+1
y1=picture