Skip to content

Instantly share code, notes, and snippets.

@Steboss
Created February 25, 2021 09:59
Show Gist options
  • Save Steboss/4c856ca5848d4bae64d330932d27389e to your computer and use it in GitHub Desktop.
Save Steboss/4c856ca5848d4bae64d330932d27389e to your computer and use it in GitHub Desktop.
Compute the rms element-wise for each chunk
for(int t=0; t<curr_scale;t++){
for(int u=(fitting_order); u>-1;u--){
if(u==0){
//this is the last step
fitting_result+= tmpCoeff[u]; //here no tmpX[t] because we have 0 for x order so x^0=1
}
else{
//tmpCoeff * x^fitting_order - u
//e.g. tmpCoeff[0]*x --> fitting-Order = 1 and u = 0
fitting_result+=tmpCoeff[u]*(pow(scale_ax[t],u));
}
}
//now here we can compute how good is the fit between element t and element
//t of the tmpX at the moment we are computing the difference of elements
float curr_diff = tmpX[t]-fitting_result;
float squared_diff = pow( curr_diff,2);
// printf("tmpX[%d]: %.4f, fitting_result:%.4f, diff:%.4f, pow:%.4f\n",
// t, tmpX[t], fitting_result, curr_diff, squared_diff);
tmpDiff[t] =squared_diff;
// printf("pow(tmpX[t] - fitting_result, 2):%.8f\n", tmpDiff[t]);
fitting_result = 0.0;
// at the end we need to compute average of ((xcut-xfit)**2))
}
// here we are closing shape1 cycle, namely cycle through all the strided elements of X
// at this stage we need to compute the sqrt of the average of tmpShape1 elements
float tmpDiffavg = vector_avg(tmpDiff, curr_scale);
// this is the shape1-th element of the final
tmpShape1[j] = sqrt(tmpDiffavg);
// printf("elment %d rms %.8f\n", j, tmpShape1[j]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment