努力工作,建立一个幸福的家庭。
分类: 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;
}