Hi,
Can you try the following code instead?
#pragma numlittype(push, TRUE)
#pragma numlittype(push, TRUE)
#pragma numlittype(push, TRUE)
#pragma numlittype(push, TRUE)
#pragma numlittype(push, TRUE)
#pragma numlittype(push, TRUE)
#pragma warning(error : 15618)
#include <origin.h>
#include <ONLSF.H>
#include <fft_utils.h>
//
void _nlsfFitConv(
// Fit Parameter(s):
double y0, double A, double t,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
// Beginning of editable part
Worksheet wks = Project.ActiveLayer();
NLFitContext *pCtxt = Project.GetNLFitContext();
if ( pCtxt )
{
// Vector for the output signal in each iteration.
static vector vSignal;
static double dx;
// 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();
vector vResponse, vSample;
vResponse = dsResponse;
vSample = dsSampling;
dx = vSample[1] - vSample[0];
vSignal.SetSize(iSize);
vResponse.SetSize(iSize);
vSample.SetSize(iSize);
// Compute the exponential decay curve
vSignal = A * exp( -t*(vSample-vSample[0]) );
// Perform convolution
int iRet = fft_fft_convolution(iSize, vSignal, vResponse);
}
NLSFCURRINFO stCurrInfo;
pCtxt->GetFitCurrInfo(&stCurrInfo);
// Get the data index for the iteration
int nCurrentIndex = stCurrInfo.nCurrDataIndex;
// Get the evaluated y value
y = dx*vSignal[nCurrentIndex] + y0;
// For compile the function, since we haven't use x here.
x;
}
// End of editable part
}
When you use it to fit convolution in NLFit dialog, you need to notice:
1. In NLFit dialog, make sure the worksheet for source data active.
2. In NLFit dialog, X data for fitted curve should be Same as Input Data.
Regards!
Sean
OriginLab Technical Service