#include "globdef.h" #include "uidef.h" #include "llsqdef.h" void parabolic_fit(float *amp, float *pos, float yy1, float yy2, float yy3) { float t3,t4; // *********************************** // Fit a parabola to the max point and it's nearest neighbours. // As input we have 3 data points y(x) // Find parameters a,b and c to place these points on the curve: // y(x)=a+b*(x-c)**2=a+b*x**2-2*x*b*c+b*c**2 // The equations to solve are: // y(-1)=a + b + 2*b*c + b*c**2 // y( 0)=a + b*c**2 // y( 1)=a + b - 2*b*c + b*c**2 // b has to be negative (for a positive peak) // abs(c) has to be below 0.5 since y(0)is the largest value. // t4=y(-1)-y(1)=4*b*c // t3=2*(y(-1)+y(1)-2*y(0))=4*b // t4/t3=c=peak offset // *********************************** t4=yy1-yy3; t3=2*(yy1+yy3-2*yy2); if(t3 < 0) { amp[0]=yy2-0.5*t4*t4/t3; t4=t4/t3; if(fabs(t4) > 1)t4/=fabs(t4); pos[0]=t4; } else { if(yy1 > yy3) { amp[0]=yy1; pos[0]=-1; } else { amp[0]=yy3; pos[0]=1; } } } int llsq1(void) { float aux[2*LLSQ_MAXPAR]; int ipiv[2*LLSQ_MAXPAR]; int kpiv; int i,j,k; float t1,sig,piv,beta; if(llsq_npar > LLSQ_MAXPAR) { lirerr(1051); return -1; } kpiv=piv=0; for(k=0; k piv) { piv=t1; kpiv=k; } } if(piv == 0)return -1; sig=sqrt(piv); for(k=0; kk) { t1=aux[k]; aux[k]=aux[kpiv]; aux[kpiv]=t1; for(i=k; i 0) { sig=0; for(i=k; i piv) { piv=t1; kpiv=j; } } } t1=0; for(i=k; i=0; k--) { t1=llsq_errors[k ]; for(i=k+1; i LLSQ_MAXPAR) { lirerr(1051); return -1; } kpiv=piv=0; for(k=0; k piv) { piv=t1; kpiv=k; } } if(piv == 0)return -1; sig=sqrt(piv); for(k=0; kk) { t1=aux[k]; aux[k]=aux[kpiv]; aux[kpiv]=t1; for(i=k; i 0) { sig=0; for(i=k; i piv) { piv=t1; kpiv=j; } } } t1=0; t2=0; for(i=k; i=0; k--) { t1=llsq_errors[2*k ]; t2=llsq_errors[2*k+1]; for(i=k+1; i