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
 Convolution of two functions
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

jackychenp

3 Posts

Posted - 05/06/2015 :  5:23:38 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin 9.1
Operating System: windows vista

Hello,

I wrote a code to fit some data points. The fitting function is the convolution of function F = A + B * theta(C-x)*(C-x)^0.5 and a Gaussian function, where theta is a step function. The code and some test data points are list below.

Basically, the code can be run. But the parameter D which is the Gaussian width doesn't change. No matter what initial value I used for D, it will stay the same during the fitting and the output result is not good.

The output of the fitting has very large interval which is the same as that of the data points. How can I make it smaller and more smooth? Thanks in advance.





#pragma numlittype(push, TRUE)
#pragma warning(error : 15618)
#include <origin.h>
#include <ONLSF.H>
#include <fft_utils.h>
 

//----------------------------------------------------------
// 
void _nlsfmeanfield_squareroot(
// Fit Parameter(s):
double A, double B, double C, double D,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
	// Beginning of editable part
	//	if(x<C) {
	//		y = A+B*(C-x)^0.5
	//	} else {
	//		y = A;
	//	}
	Worksheet wks = Project.ActiveLayer();
	NLFitContext *pCtxt = Project.GetNLFitContext();
	
	if(pCtxt)
	{	
	    int i;
		  
		// Vector for the output signal in each iteration.
		static vector  vF;
		// If parameters were updated, we will recalculate the convolution result.
		BOOL bIsNewParamValues = pCtxt->IsNewParamValues();
		if ( bIsNewParamValues )
		{			 			
			// Read sampling  data from worksheet.
			Dataset dsSampling(wks, 0);
			 vector vSample,vG;
			 vSample = dsSampling;
			 
	 		int nSize = dsSampling.GetSize();
			vSample.SetSize(nSize);
			vF.SetSize(nSize);
			vG.SetSize(nSize); 
			 
			for(i=0;i<=nSize;i++)
			{
				if(vSample[i] < C)
				{
					vF[i]= B * (C-vSample[i])^0.5;
				}else{
					vF[i]=0;
				}
				vG[i]=exp(-(vSample[i]-C)^2/(2*D^2))/(0.39894*D); 
				 
	 		}
		 
			 	//vG=exp(-(vSample-C)^2/(2*D^2))/(0.39894*D); 
			
			int iRet = fft_fft_convolution(nSize, vF, vG);
 	 			
		}
		 	
		NLSFCURRINFO    stCurrInfo;
		pCtxt->GetFitCurrInfo(&stCurrInfo);
		// Get the data index for the iteration
	int nCurrentIndex = stCurrInfo.nCurrDataIndex;
		// Get the evaluated y value
		y = vF[nCurrentIndex]+A;
		// For compile the function, since we haven't use x here.
	 	x;
	//	 }}
	}
	// End of editable part
}


Test data:
15 177
50 172.3094
100 163.41035
150 151.29372
180 140.50654
200 126.92814
210 120
220 120
230 120
240 120
250 120
260 120
270 120
280 120
300 120

Best regards,
Peng

jasonzhao

China
262 Posts

Posted - 05/06/2015 :  11:07:26 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello,

You can send the fdf file and the OPJ file to tech@originlab.com for us to make a further check.

Best regards!
Jason
OriginLab Technical Service
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