#include <ONLSF.H>
#include <fft_utils.h>2. 之后在第40行,即灰色的Beginning和End of editable part之间插入
NLFitContext *pCtxt = Project.GetNLFitContext();
Worksheet wks;
DataRange dr;
int c1,c2;
dr = pCtxt->GetSourceDataRange(); //Get the source data range
dr.GetRange(wks, c1, c2); //Get the source data worksheet
if ( pCtxt )
{
// Vector for the output signal in each iteration.
static vector vSignal;
// If parameters were updated, we will recalculate the convolution result.
BOOL bIsNewParamValues = pCtxt->IsNewParamValues();
if ( bIsNewParamValues )
{
// Read sampling and response data from worksheet.
Dataset dsSampling(wks, 0);
Dataset dsResponse(wks, 2);
int iSize = dsSampling.GetSize();
// Compute the exponential decay curve
vSignal = A * exp( -t*vSample );
// Perform convolution
int iRet = fft_fft_convolution(iSize, vSignal, vResponse);
//Correct the convolution by multiplying the sampling interval
vSignal = (vSample[1]-vSample[0])*vSignal;
}
NLSFCURRINFO stCurrInfo;
pCtxt->GetFitCurrInfo(&stCurrInfo);
// Get the data index for the iteration
int nCurrentIndex = stCurrInfo.nCurrDataIndex;
// Get the evaluated y value
y = vSignal[nCurrentIndex] + y0;
// For compile the function, since we haven't use x here.
x;
}3. 点一下左上角的编译按钮(Compile),4. 看看编译是否通过(Done)。5. 编译完成后点击左上角的返回对话框(Return to Dialog),再点击下一步、结束即可完成拟合函数的新建。此时我们先关闭拟合对话框。
第三步,开始拟合。此时我们的数据本上A、B、C三列应该分别是x轴数据、待拟合荧光数据和处理后的IRF数据。1. 选中B列,按快捷键Ctrl+Y开始拟合。2. 选择刚才新建的FitConv函数,3. 在设置(Settings)-拟合曲线(Fitted Curves)-X数据类型(X Data Type)中选择 4.“与输入数据相同(Same as Input Data)”。在拟合参数选项卡中,先将弛豫时间 t 手动初始化为一个接近的值,通过点击 5. “计算卡方(Calculate Chi-Square)”观察拟合函数与原始数据的吻合情况,点击“一次迭代(1 Iteration)”观察拟合函数是否收敛。判断拟合参数大致收敛后,点击“拟合至收敛(Fit Until Converged)”。需要注意由于卷积计算时间较长,如果没有手动调整参数的过程,迭代拟合将非常缓慢。