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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Error using convolution fit
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

jeplb

Australia
2 Posts

Posted - 10/10/2015 :  05:32:28 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 9.0
Operating System: Mac OS X El Capitan, Parallels Desktop Windows 7

I am having issues regarding the convolution algorithm that can be found in the wiki. It keeps giving me an error "Vector operation dimension check error". My suspicion is that the step size of my x-values is not the same as the example (tutorial: step size of 0.1; mine is 0.07). I was wondering if there is a workaround for this.

SeanMao

China
288 Posts

Posted - 10/12/2015 :  05:27:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

jeplb

Australia
2 Posts

Posted - 10/12/2015 :  8:06:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hey Sean,

Calculating dx first solves the problem!

I was wondering, say, if I want to fit a double exponential I should just change the line:
vSignal = A * exp( -(vSample-vSample[0])/t1 );

to

vSignal = A * exp( -(vSample-vSample[0])/t1 ) + B * exp( -(vSample-vSample[0])/t2 );

Is that correct?
Go to Top of Page

SeanMao

China
288 Posts

Posted - 10/12/2015 :  11:43:34 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

This is correct, but you need to be careful when you choose initial values for fitting parameters.

Regards!

Sean
Go to Top of Page

natashatabassum

USA
1 Posts

Posted - 02/06/2016 :  1:43:03 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,
I am trying to use the above mentioned Convolution fit function in OrininPro2015 in windows 10. I am still getting the "Vector operation dimension check error".
I am using the sample data that it came with. I am not sure what can be the problem.

Thanks
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000