In[]:=
Clear["Global`*"](*clearallMMvariables*)
In[]:=
SetDirectory[NotebookDirectory[]](*setworkingdirectory*)
Out[]=
/Applications/MCNP6_OSX/mcnpdir1/Cherenkov sims/JBScan model/Scan scenarios
In[]:=
gauge=0.250;(*linepairgaugespacing[lp/cm]*)​​k=2*π*gauge;(*spatialfrequency[cm/cycle]]*)
In[]:=
SqWave[x_,a_,x0_,b_]:=a*Sign[Sin[k*(x-x0)]]+b(*squarewave*)
In[]:=
LPGdata=Import["LPG 07-1.txt","Table"];(*simulatedLPGdata*)
In[]:=
ffit=FindFit[LPGdata,SqWave[x,a,x0,b],{a,x0,b},x]
Out[]=
{a-0.00773079,x01.,b0.0238965}
In[]:=
%[{"ParameterTable"}]
Out[]=
{a-0.00773079,x01.,b0.0238965}[{ParameterTable}]
In[]:=
Show[ListPlot[LPGdata,PlotStyle->Red],​​Plot[SqWave[x,a,x0,b]/.ffit,{x,-8,+8},PlotStyle->Blue]]
Out[]=
-6
-4
-2
2
4
0.01
0.02
0.03
0.04