%**************************************************************************
%This function filters the field integral measurement data.  It performs local
%fits to smooth the data.
%
%Input:
%gap, measured gap values (m)
%i12xy, measured field integral values (Tm or Tm^2)
%gap_filt, gap values to return the filtered integrals values at (m)
%
%Output:
%i12xy_filt, filtered field integral values (Tm or Tm^2)
%
%Zachary Wolf
%10/10/17

function [i12xy_filt] = pid_fit_i12xy_filt_high_pass(gap, i12xy, gap_filt)

%Find the peak value
[i12xy_peak, index_peak] = max(i12xy);

%Fit the smooth curve at gaps past the peak
gap_hi = gap(index_peak : end);
i12xy_hi = i12xy(index_peak : end);
p = polyfit(gap_hi, i12xy_hi, 4);
i12xy_hi_filt = polyval(p, gap_hi);

%Keep the rapidly changing data before the peak
i12xy_lo_filt = i12xy(1 : index_peak - 1);

%Combine the filtered data
i12xy_filt = [i12xy_lo_filt, i12xy_hi_filt];

%Done
