Chinaunix首页 | 论坛 | 博客
  • 博客访问: 435858
  • 博文数量: 111
  • 博客积分: 4290
  • 博客等级: 上校
  • 技术积分: 1301
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-24 14:22
个人简介

努力工作,建立一个幸福的家庭。

文章分类

全部博文(111)

文章存档

2015年(4)

2013年(9)

2012年(6)

2011年(17)

2010年(69)

2009年(6)

分类: WINDOWS

2010-05-17 11:27:44

/*
* Copyright 2009,dengwei
* FileName: ARMA.c
* Crrent version: 1.0
* Editor: dengwei
* Abstract: ARMA model distinguish
 */

#include
#include

#define MAX 1024
#define NAX 100

int at[MAX] = {0};  /*initialize randome sequence*/

int main(void)
{
   int *Pat,*Pxt,*Prt,*Ppt;

   int *CreatAt(int max);
   int *CreatXt(int at[],int  max);
   int *CreatRt(int *Xt,int max);
   int *CreatAutoPt(int *Rt,int max);
   int CheckMA(int *mt,int max);

   Pat = CreatAt(MAX);
   system("pause");
   printf("\n");

   Pxt = CreatXt(Pat,MAX);
   system("pause");
   printf("\n");

   Prt = CreatRt(Pxt,MAX);
   system("pause");
   printf("\n");

  /*  printf("RT=%d\n",*Prt); */
  /*  system("pause"); */

   Ppt = CreatAutoPt(Prt,MAX);
   system("pause");
   printf("\n");

   CheckMA(Ppt,MAX);
   system("pause");
   printf("\n");

   getchar();
   return 0;
}

/**********************************
name:CreatAt
function:creat the rand sequence
**********************************/
int *CreatAt(int max)
{
   int *pt;
   int i;


   for( i=0; i   {
      at[i] = rand()%100;
      printf("at[ i ]=%d\t",at[i]);
   }
   pt=at;
   printf(" random numbers from 0 to 99\n\n");
   return pt;
}

/*******************************************
name:CreatXt
function:Creat 1024 point
******************************************/
int *CreatXt(int at[],int max)
{
   int *pt;
   int i;
   int Xt[MAX] = {0};

   for (i=0;i   {
    Xt[i+1] = 0.3*Xt[i]+at[i]+at[i+1];
    printf(" Xt[i]=%d\t  ",Xt[i]);
   }

   pt=Xt;

   return pt;
}

/*********************************************
name:CreatRt
function:Generate sample covariance
*********************************************/
int*CreatRt(int *Xt,int max)
{
   int *pt = 0;
   int sum = 0;
   int Rt[MAX] = {0} ;
   int i,k;

   for(i=0;i<1024;i++)
   {
     Rt[i] = *(Xt++) ;
   }

   for(k=0;k   {
      for(i=0;i      {
        sum = (1/(MAX-k))*Rt[i]*Rt[i+k];
        *pt = sum + *pt;
       }
      pt++;
   }

   for(i=1;i   {
     printf(" Rt =  %d\t",*pt--);
   }

 /*  pt = pt-1024;  */

   pt++;
   printf("RT=%d\n",*pt);
   return pt;

}

/****************************************
* name: CreatAutoPt
* functoin:genenate sample autocorrelative function
******************************************/
int*CreatAutoPt(int*Rt,int max)
{
    int i;
    int Rt0 = 0;
    int *pt1,*pt2;

    Rt0 = *Rt;
    pt2 = Rt;
    pt2++;

    for(i=1;i    {
      *pt1 = *pt2/Rt0;
      pt2++;
      pt1++;
     }

    for(i=1;i    {
     if(i==200) system("pause");
     printf(" Pt =  %d\t",*pt1--);      /* /* unsuccess */ */
    }

   /* pt = pt-1023;  */

     return pt1;
}

/*************************************
*function name:CheckMA
*function:Check MA sequence
**************************************/
int CheckMA(int *mt,int max)
{
  int i,q,term = 0;
  float count = 0;
  int *pt;
  pt = mt;

  do{
      for(q=0;q      {
          for(i=0;i          {
           if(abs(*pt) <= 1/MAX)
           { count++;  }
            pt++;
           }
           pt = mt+q;
           count = (float)count/NAX;
           if(count>0.68 && count<0.69)
           {
             printf("MA's step is q=%d\t",q);
             return q;
           }
       }

       term++;
    }
  while(term<1024);
  return 0;
}

阅读(6547) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-06-24 12:20:09

你好,我想要这个段程序的全部,可是你这里好像还没有全贴出来的,可以给我发个全的吗?谢谢!it042@sina.com