int Smoothing(double* array, int pts_num,int axis,int iter)
{
int j,count=0;
double dt=0.25, K=5;
double DataL,DataR, CL, CR;
double ImdValDif, ImdValDifN;
double sumdot, sumnoise, sumdiff;
// corr[0]: last corr; corr[1]; current corr;
double difference,corr[2]={1,1};
double * Orig=new double[pts_num];
if (Orig== NULL)
{
AfxMessageBox("Orig_z's memeory error in the smoothing_ANID funciton!");
exit(1);
}
for (j=0; j<pts_num; j++)
{
Orig[j]=array[j];
}
K=100;
do
{
corr[0]=corr[1];
count +=1;
// process the left boundary
DataL=array[1]-array[0];
//DataR=array[1]-array[0];
CL=exp(-(fabs(DataL)/K)*(fabs(DataL)/K));
//CR=exp(-(fabs(DataR)/K)*(fabs(DataR)/K));
// compute the diffusion result
ImdValDif=array[0]+dt*(CL*DataL);//+CR*DataR);
ImdValDifN=ImdValDif;
for (j=1;j<pts_num-1;j++)
{
DataL=array[j-1]-array[j];
DataR=array[j+1]-array[j];
CL=exp(-(fabs(DataL)/K)*(fabs(DataL)/K));
CR=exp(-(fabs(DataR)/K)*(fabs(DataR)/K));
ImdValDif=array[j]+dt*(CL*DataL+CR*DataR);
array[j-1]=ImdValDifN;
ImdValDifN=ImdValDif;
}
//process the right boundary
DataL=array[pts_num-2]-array[pts_num-1];
//DataR=array[pts_num-2]-array[pts_num-1];
CL=exp(-(fabs(DataL)/K)*(fabs(DataL)/K));
//CR=exp(-(fabs(DataR)/K)*(fabs(DataR)/K));
array[pts_num-1]=array[pts_num-1]+dt*(CL*DataL);//+//CR*DataR);
// computer the stop time
sumdot=0, sumnoise=0, sumdiff=0;
for (j=0;j<pts_num;j++)
{
difference=Orig[j]-array[j];
sumdot +=fabs(difference*array[j]);
sumnoise +=pow(difference,2);
sumdiff +=pow(array[j],2);
}
corr[1]=sumdot/(sqrt(sumnoise)*sqrt(sumdiff));
if (count>iter)
{
delete [] Orig;
return count;
}
}while (corr[1]-corr[0]<0.01);
delete [] Orig;
return count;
}
{
int j,count=0;
double dt=0.25, K=5;
double DataL,DataR, CL, CR;
double ImdValDif, ImdValDifN;
double sumdot, sumnoise, sumdiff;
// corr[0]: last corr; corr[1]; current corr;
double difference,corr[2]={1,1};
double * Orig=new double[pts_num];
if (Orig== NULL)
{
AfxMessageBox("Orig_z's memeory error in the smoothing_ANID funciton!");
exit(1);
}
for (j=0; j<pts_num; j++)
{
Orig[j]=array[j];
}
K=100;
do
{
corr[0]=corr[1];
count +=1;
// process the left boundary
DataL=array[1]-array[0];
//DataR=array[1]-array[0];
CL=exp(-(fabs(DataL)/K)*(fabs(DataL)/K));
//CR=exp(-(fabs(DataR)/K)*(fabs(DataR)/K));
// compute the diffusion result
ImdValDif=array[0]+dt*(CL*DataL);//+CR*DataR);
ImdValDifN=ImdValDif;
for (j=1;j<pts_num-1;j++)
{
DataL=array[j-1]-array[j];
DataR=array[j+1]-array[j];
CL=exp(-(fabs(DataL)/K)*(fabs(DataL)/K));
CR=exp(-(fabs(DataR)/K)*(fabs(DataR)/K));
ImdValDif=array[j]+dt*(CL*DataL+CR*DataR);
array[j-1]=ImdValDifN;
ImdValDifN=ImdValDif;
}
//process the right boundary
DataL=array[pts_num-2]-array[pts_num-1];
//DataR=array[pts_num-2]-array[pts_num-1];
CL=exp(-(fabs(DataL)/K)*(fabs(DataL)/K));
//CR=exp(-(fabs(DataR)/K)*(fabs(DataR)/K));
array[pts_num-1]=array[pts_num-1]+dt*(CL*DataL);//+//CR*DataR);
// computer the stop time
sumdot=0, sumnoise=0, sumdiff=0;
for (j=0;j<pts_num;j++)
{
difference=Orig[j]-array[j];
sumdot +=fabs(difference*array[j]);
sumnoise +=pow(difference,2);
sumdiff +=pow(array[j],2);
}
corr[1]=sumdot/(sqrt(sumnoise)*sqrt(sumdiff));
if (count>iter)
{
delete [] Orig;
return count;
}
}while (corr[1]-corr[0]<0.01);
delete [] Orig;
return count;
}