C语言测正弦波周期

DCACFFT 2008-09-22 02:41:32
有做过在C中测正弦波周期的吗?程序该怎么写啊?谢谢
...全文
325 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
hichi2000 2008-09-29
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 DCACFFT 的回复:]
我用VB做的
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 '波峰个数
Re…
[/Quote]
C语言版的如下:


double Sin_period(double signal[],int size){
double top_cnt=0;/*波峰个数*/
int first_top;/*一个波峰出现的时间*/
int last_top;/*后一个波峰出现的时间*/

double result=0
int index;

for(index=1;index<n-1;index++){
if(signal[index]>signal[index-1] && signal[index]>signal[index+1]){/*到波峰*/
top_cnt++;
if(1==top_cnt)first_top=index;/*记下第一个波峰的时间*/
last_top=index;
}
}
if(signal[0]=signal[last_top]){/*第一个位置为波峰的情况*/
first_top=0;
top_cnt++;
}
if(signal[index]==signal[last_top]){/*最后一个位置为波峰的情况*/
last_top=index;
top_cnt++;
}

if(top_cnt>1)/*防止除以0*/result=((last_top-first_top)*1.0)/(top_cnt-1);/*均值*/

return result;
}


qiu5208 2008-09-29
  • 打赏
  • 举报
回复
我照搬了一遍,你参考,
用vb编程就是爽了,好怀念.
#include<stdio.h>
float peak_data(float data1[],int n)'数组的个数只能从外部传入.
{int cnt;
int a;
float y[];
int *x=(int*) malloc(n*2);/*动态分配内存空间*/
cut=0;
y=data1;
for(a=1;a>(n-1);a++)
if (y[a]>y[a-1] && y[a]>y[a+1])
{cut++;
*(x+cut)=a;
}
return (*(x+cut)-*(x+1))/(--cut)
}

qiu5208 2008-09-29
  • 打赏
  • 举报
回复
刚学c,想帮你翻译vb,当是不通啊.
c中数组的个数不能用函数得到,只能从参数传进来.
DCACFFT 2008-09-28
  • 打赏
  • 举报
回复
自己顶
xiansizhe 2008-09-22
  • 打赏
  • 举报
回复
ding
DCACFFT 2008-09-22
  • 打赏
  • 举报
回复
我用VB做的
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
但是对C不大了解,不知怎么表达
wangdeqie 2008-09-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 DCACFFT 的回复:]
没人?加分也可以啊。
[/Quote]

不是分数的问题,也不是不帮你,其实这是个数学问题,是按着数学公式一步步写的!
DCACFFT 2008-09-22
  • 打赏
  • 举报
回复
没人?加分也可以啊。
wangdeqie 2008-09-22
  • 打赏
  • 举报
回复
虽然没做过,感觉应该就是根据计算公式写相应的代码即可
太乙 2008-09-22
  • 打赏
  • 举报
回复
友情up~~
e_sharp 2008-09-22
  • 打赏
  • 举报
回复
UP
e_sharp 2008-09-22
  • 打赏
  • 举报
回复
UP

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧