%=======================================================================
% BW filttering Low Pass CFC60 Cutoff 100Hz
% Fortran to Matlab
% Kim Kyungju ,Road Kinematics co.,Ltd
%=======================================================================
function [FData] = ButterF2M(Data,DEL, FCUT);

[RowSizeOfA, ColumeSizeOfA] = size(Data);  % matrix size
%=======================================================================
%-------------------------------------------------------------------
% Main Program : 2nd Order Butterworth digital filter
%-------------------------------------------------------------------
NFP=1;      % Number of First Data
NPT=RowSizeOfA; % Nuber of Data Point
YF=Data; % Raw Data
NUM=NPT+10;
sup=10;     %step up number of point (front/rear)

% Initialized array
YFF = zeros(1, sup);
YFR = zeros(1, sup);
for i=0:sup-1
    YFF(i+1)=-YF(10-i);
    YFR(i+1)=-YF(RowSizeOfA-i);
end
j=1:sup;
YF2(j)=YFF(j);

k=sup+1:RowSizeOfA+sup;
YF2(k)=YF(k-sup);

l=1:sup;
YF2(l+RowSizeOfA+sup)=YFR(l);
YF2=YF2';

%------------------------------------------------------------------
% Call Filter function
% FCUT : (Fn) Cutoff frequency, Hz
% CFC60 : FCUT=100, CFC180 : FCUT=300
%------------------------------------------------------------------
Y=MBfilter(YF2,DEL,NFP,NUM,FCUT*1.25);
% Initialized array
Y2 = zeros(1, sup);

for i=sup+1:RowSizeOfA+sup
    Y2(i-sup)=Y(i);
end
FData=Y2';