Skip to content
Snippets Groups Projects
Commit 99cc006e authored by Joakim's avatar Joakim :speech_balloon:
Browse files

Added normalization to FID

parent 279e64e8
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,7 @@ function [rX, rY, f2] = fid(X, Y, cutoff, plotToggle) ...@@ -36,6 +36,7 @@ function [rX, rY, f2] = fid(X, Y, cutoff, plotToggle)
Y1(2:end) = (Y(2:end,1)-y1)./(X(2:end,1)-x1); Y1(2:end) = (Y(2:end,1)-y1)./(X(2:end,1)-x1);
Y1(1) = Y1(2); Y1(1) = Y1(2);
Y1 = Y1/max(abs(Y1));
if plotT if plotT
figure, plot(X,Y1,'LineWidth',2); figure, plot(X,Y1,'LineWidth',2);
......
...@@ -43,27 +43,25 @@ def fid(X,Y,cutoff = 0.01): ...@@ -43,27 +43,25 @@ def fid(X,Y,cutoff = 0.01):
Boolean indexing array, the feature selection result. Boolean indexing array, the feature selection result.
""" """
try: def f(x,a,b,c,d):
def f(x,a,b,c,d): return -a/(b*x+c)+d
return -a/(b*x+c)+d
x0 = X[0]; y0 = Y[0]
x0 = X[0]; y0 = Y[0] Y1 = np.zeros(len(Y))
Y1 = np.zeros(len(Y)) for i in range(1,len(X)):
for i in range(1,len(X)): Y1[i] = (Y[i]-y0)/(X[i]-x0)
Y1[i] = (Y[i]-y0)/(X[i]-x0) Y1[0] = Y1[1]
Y1[0] = Y1[1] Y1 = Y1/np.max(np.abs(Y1))
popt, pcov = sp.optimize.curve_fit(f,X,Y1,p0=[1,10,10,0], popt, pcov = sp.optimize.curve_fit(f,X,Y1,p0=[1,10,10,0],
bounds=([0,-np.inf,-np.inf,-np.inf],[np.inf,np.inf,np.inf,np.inf])) bounds=([0,-np.inf,-np.inf,-np.inf],[np.inf,np.inf,np.inf,np.inf]))
Y2 = f(X,*popt) Y2 = f(X,*popt)
dY2 = Y2[-1]-Y2[0] dY2 = Y2[-1]-Y2[0]
f2 = Y2 < Y2[-1] - dY2*cutoff f2 = Y2 < Y2[-1] - dY2*cutoff
rX = X[f2] rX = X[f2]
rY = Y[f2] rY = Y[f2]
return rX, rY, f2 return rX, rY, f2
except RuntimeError as e:
raise e
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment