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 for Programming
 Forum for Origin C
 Convolution of two functions

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
jackychenp Posted - 05/06/2015 : 5:23:38 PM
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
1   L A T E S T    R E P L I E S    (Newest First)
jasonzhao Posted - 05/06/2015 : 11:07:26 PM
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

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