The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum
 Origin Forum
 Double-Exponential + IRF convolution fit

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
HAYAO Posted - 04/05/2017 : 6:44:04 PM
OriginPro 2017 Ver.9.4 (Academic):
Operating System: Windows 10 (64-bit)

Dear all, I saw tutorial on how to fit with convolution here:
http://www.originlab.com/doc/Tutorials/Fitting-Convolution

However, it seems like the code used here is for Single-Exponential fitting with IRF. I need double-exponential fitting with IRF, so I modified the code provided in the tutorial. I want you guys to check to see if the following code looks right.

Thank you,
HAYAO


  • Function Name: FitConv

  • Function Type: User-Defined

  • Independent Variables: x

  • Dependent Variables: y

  • Parameter Names: y0, A1, A2, t1, t2

  • Function Form: Origin C

  • Function:


#pragma warning(error : 15618)
#include <origin.h>
// Header files need to be included
#include <ONLSF.H>
#include <fft_utils.h>
//
// 
void _nlsfTestConv(
// Fit Parameter(s):
double y0, double A1, double A2, double t1, double t2,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
	// Beginning 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();
 
			vector vResponse, vSample;
 
			vResponse = dsResponse;
			vSample = dsSampling;
 
			vSignal.SetSize(iSize);
			vResponse.SetSize(iSize);
			vSample.SetSize(iSize);
 
			// Compute the exponential decay curve
			vSignal = A1 * exp( -t1*vSample ) + A2 * exp( -t2*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;
	}
	// End of editable part
}
2   L A T E S T    R E P L I E S    (Newest First)
HAYAO Posted - 04/20/2017 : 06:04:43 AM
Hi Yuki,

Thanks, I'll try that. I'll come back if it doesn't go well.
yuki_wu Posted - 04/06/2017 : 01:23:38 AM
Hi HAYAO,

I think you’d better try to compile the fitting function after you define the function in Code Builder. Compiling the code can help you to find out the error in your code firstly. Then, you should try to evaluate the fitting function as the following page, so that you can do a quick check to see whether the function is appropriate.
http://www.originlab.com/doc/Origin-Help/UserDef-FitFunc

Regards,
Yuki
OriginLab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000