3156|1

77

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

请教用单片机做相关算法的问题! [复制链接]

我现在要用单片机做个相关算法,但是今天用软件模拟,发现效果很不好.我的相关算法部分程序如下,希望大家指点下!谢谢!
//-----------------------------------------------------------------------------
// 相关算法函数
//-----------------------------------------------------------------------------
int Vspeed(unsigned char My_Num)
{
    unsigned int i,j;
        unsigned char temp_max;
        unsigned int xdata temp1[500];
    unsigned long int xdata temp2[450],temp3[50];

        for(i=0;i<50;i++)
        {
            for(j=i;j<500;j++)
                    temp1[j-i]=sensors[My_Num].speed_sample[2*j+1];           //temp1中存放下游采样数据

            for(j=0;j<450;j++)
                    temp2[j]=sensors[My_Num].speed_sample[2*j]*temp1[j];      //temp2中存放上游采样数据与下游采样数据的积
            temp3=Trapz(temp2);
        }
        temp_max=My_Max(temp3);
   return temp_max;
}

unsigned long Trapz(unsigned long int *art4)
{
    unsigned int i;
    unsigned long int temp_sum=0;
    for(i=0;i<450;i++)
        art4=art4+art4[i+1];
        for(i=0;i<450;i++)
        temp_sum+=art4;
    return temp_sum;
}

unsigned char My_Max(unsigned long int *art3)
{
    unsigned char i;
        unsigned char count=0;
    unsigned long int max_value=0;

    max_value=art3[5];
    count=5;
    for(i=5;i<40;i++)
    {
        if(max_value)
        {
            max_value=art3;
            count=i;
        }
    }
        return (count+1);
}

最新回复

在vc++环境下编了一个检验相关算法的程序,总是得不到正确的延迟点.程序如下: #include #include unsigned long Trapz(unsigned long int *art4); int My_Max(unsigned long int *art3); using namespace std; int main () {         int sy[450],xy[500];         float a,b;     int i,j;     int temp1[500];     unsigned long int temp2[450],temp3[50];         unsigned long int temp_max;     cout   详情 回复 发表于 2007-8-31 18:21
点赞 关注

回复
举报

69

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
在vc++环境下编了一个检验相关算法的程序,总是得不到正确的延迟点.程序如下:
#include
#include

unsigned long Trapz(unsigned long int *art4);
int My_Max(unsigned long int *art3);

using namespace std;

int main ()
{
        int sy[450],xy[500];
        float a,b;
    int i,j;
    int temp1[500];
    unsigned long int temp2[450],temp3[50];
        unsigned long int temp_max;

    cout << "上游采样值" <         for(i=0; i<450; i++)
        {
          a = sin(6.28318*i/450);
      a = (a+1)/2.4;
          sy = a*65536;
          cout << sy <<" ";
        }
    cout << endl;

              
    cout << "下游采样值" <         for(i=0; i<500; i++)
        {
          b = (i-20);
          b =b/450;
          b = b*6.28318;
          a = sin(b);
          a = (a+1)/2.4;
      xy = a*65536;
          cout < <<" ";
        }


        for(i=0;i<50;i++)
        {
            for(j=i;j<500;j++)
                    temp1[j-i]=xy[j];          //错位存放下游采样数据

                for(j=0;j<450;j++)
                    temp2[j]=sy[j]*temp1[j];   //temp2中存放上游采样数据与下游采样数据的积

                    temp3=Trapz(temp2);
                        cout << endl << i << " " << temp3;
        }

        temp_max=My_Max(temp3);
       
        cout << endl << temp_max;
    return 0;
}


unsigned long Trapz(unsigned long int *art4)
{
    unsigned int i;
    unsigned long int temp_sum=0;

    //for(i=449;i>0;i--)
        //art4=art4+art4[i-1];

        for(i=0;i<450;i++)
        temp_sum+=art4;

    return temp_sum;
}


int My_Max(unsigned long int *art3)
{
    int i;
        int count=0;
    unsigned long int max_value=0;

    max_value=art3[5];
    count=5;
    for(i=5;i<40;i++)
    {
        if(max_value)
        {
            max_value=art3;
            count=i;
        }
    }
        return (count+1);
}
 
 

回复
您需要登录后才可以回帖 登录 | 注册

查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/9 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表