*********************************************************/
float Similarity(int Sample[Vectors_Num],int
Pattern[Vectors_Num])
{
int counter=0;
int i;
for(i=0;i
#include
#include
/*abs()*/
#define Threshold_Match
0.8
/*match accuracy*/
#define Threshold_Error
50
/*distance error*/
#define Threshold_Flag
100
/*start flag range*/
#define Delay_Time
get from experiments*/
#define Vectors_Num
vectors */
2
/*pick vectors interval
10
/*numbersofthetypical
#define BaseX
axis*/
#define BaseY
axis*/
2100
/*the basic value of X
1400
/*the basic value of Y
/*******Four Patterns To Be Matched With*******************
Notes: Only use the left hand
**********************************************************
*/
int LeftShiftX[Vectors_Num] =
{1950,1810,1850,1950,2160,2430,2530,2230,2110,2150};
int LeftShiftY[Vectors_Num] =
{1400,1400,1400,1400,1400,1400,1400,1400,1400,1400};
int RightShiftX[Vectors_Num]=
{2230,2330,2430,2500,2530,2530,2510,2400,2330,2300};
int RightShiftY[Vectors_Num]=
{1400,1400,1400,1400,1400,1400,1400,1400,1400,1400};
int UpShiftX[Vectors_Num] =
{2100,2100,2100,2100,2100,2100,2100,2100,2100,2100};
int UpShiftY[Vectors_Num] =
{1230,1180,1010,1110,1230,1350,1430,1500,1630,1530};
int DownShiftX[Vectors_Num] =
{2100,2100,2100,2100,2100,2100,2100,2100,2100,2100};
int DownShiftY[Vectors_Num] =
{1530,1600,1700,1730,1800,1750,1700,1600,1500,1430};
/*****************Function
Prototype****************************/
float Similarity(int Sample[Vectors_Num],int Pattern[Vectors_Num]);
/****************The Main
Function****************************/
void main(void)
{
int i,j;
unsigned int Flag=0;
/*indicate the start of
matching*/
int current_data[2]={0};
/*initialization and wait
for extraction*/
/*************Sample extract from data
flow********************
*if Flag =1,start extract data and put current data flow
in the arrays,
data extraction's interval depends on
delay(Delay_Time)*/
int Sample_X[Vectors_Num]={0};
int Sample_Y[Vectors_Num]={0};
/*
two similarity container
*/
float sim_X;
float sim_Y;
FILE *Axis_X,*Axis_Y;
/*two files contain the data
from the acclerator*/
/* open the file for read */
if((Axis_X=fopen("c:\\11.txt","r"))==NULL)
{
printf("Can not Open File--11.TXT !\n");
exit(1);
}
else
{
printf("Open File====11.TXT Successfully!\n");
}
if((Axis_Y=fopen("c:\\22.txt","r"))==NULL)
{
printf("Can not Open File--22.TXT !\n");
exit(1);
}
else
{
printf("Open File====22.TXT Successfully!\n");
}
////
while(1)
{
/*extract current data into current_data[]*/
/*if not end of file ,process (all files are
sychronous)*/
while(!feof(Axis_X))
{
Flag=0;
fscanf(Axis_X,"%d",¤t_data[0]);
fscanf(Axis_Y,"%d",¤t_data[1]);
/*judge if it is ready to start matching*/
if((abs(BaseX-current_data[0])>Threshold_Flag)||(abs(Ba
seY-current_data[1])>Threshold_Flag))
{
}
Flag=1;
/*find the start indicator*/
if(Flag)
{
/*start pick vectors and put into the sample*/
for(i=0;i=Threshold_Match) &&
(sim_Y>=Threshold_Match) )
{
//
printf("%.2f\t%.2f\n",sim_X,sim_Y);
printf("Pattern One ==Left Shift
Success!!\n");
continue;
}
****/
/*****
the second Pattern Matching
sim_X= Similarity(Sample_X,RightShiftX);
sim_Y= Similarity(Sample_Y,RightShiftY);
if( (sim_X>=Threshold_Match) &&
(sim_Y>=Threshold_Match) )
{
//
printf("%.2f\t%.2f\n",sim_X,sim_Y);
printf("Pattern Two ==Right Shift
Success!!\n");
continue;
}
/*** the third pattern Matching ***/
sim_X= Similarity(Sample_X,UpShiftX);
sim_Y= Similarity(Sample_Y,UpShiftY);
if( (sim_X>=Threshold_Match) &&
(sim_Y>=Threshold_Match) )
{
//
printf("%.2f\t%.2f\n",sim_X,sim_Y);
printf("Pattern Three ==Up Shift
Success!!\n");
continue;
}
/*** the fourth pattern Matching
***/
sim_X= Similarity(Sample_X,DownShiftX);
sim_Y= Similarity(Sample_Y,DownShiftY);
if( (sim_X>=Threshold_Match) &&
(sim_Y>=Threshold_Match) )
{
printf("%.2f\t%.2f\n",sim_X,sim_Y);
printf("Pattern Four ==Down Shift Success!!\n");