function [command_gui,classed,v,w,x,y,z] = practiceLDA_2Cat(offset, v,w,x,y,z,tdata,classed,data)

co = tdata.co;
thresMAT = tdata.thresMAT;
xmark = tdata.xmark;

set_t = 500;     % analysis window size
seg = 250;   % moving average window
ch = 5;     % number of channels
command_gui = zeros(1,5);   % command matrix

for i = 1:5
    evalc(['thres' num2str(i) '=thresMAT('  num2str(i)  ',2);']);
    evalc(['tCH' num2str(i) '=thresMAT('  num2str(i)  ',1);']);
end

%% read data
for i = 1:ch
    emg_win(:,i) = data(:,i)-offset(i);     % detrend incoming data
end

%% moving average
ave_win = emg_win(1:seg,1:ch);
ave_win = ave_win.^2;
mov_ave = mean(ave_win,1);  % compute moving average

% if classed == 6     % check current class
%     v = mov_ave(tCH1)>rat*thres1;
%     w = mov_ave(tCH2)>rat*thres2;
%     x = mov_ave(tCH3)>rat*thres3;
%     y = mov_ave(tCH4)>rat*thres4;
%     z = mov_ave(tCH5)>rat*thres5;
%     if v || w || x || y || z    % check if above moving threshold
        %% mean absolute value
        emg_abs = abs(emg_win);     % rectify EMG
        MAV = mean(emg_abs,1);
        
        clear gi abs_win
        
        %% zero crossings
        zc = zeros(1,ch);
        for ai = 1:ch
            for ci = 1:set_t-1
                if emg_win(ci,ai)<0 && emg_win(ci+1,ai)>0 && abs(emg_win(ci,ai)-emg_win(ci+1,ai))>=0.01
                    zc(ai) = zc(ai) + 1;
                elseif emg_win(ci,ai)>0 && emg_win(ci+1,ai)<0 && abs(emg_win(ci,ai)-emg_win(ci+1,ai))>=0.01
                    zc(ai) = zc(ai) + 1;
                end
            end
        end
        
        clear ai ci
        
        %% slope sign change
        m_sign = zeros(1,ch);
        for ai = 1:ch
            for ci = 1:set_t-2
                if emg_win(ci+1,ai)>emg_win(ci+2,ai) && emg_win(ci+1,ai)>emg_win(ci,ai) && abs(emg_win(ci+1,ai)-emg_win(ci,ai))>=0.01
                    m_sign(ai) = m_sign(ai) + 1;
                elseif emg_win(ci+1,ai)<emg_win(ci+2,ai) && emg_win(ci+1,ai)<emg_win(ci,ai) && abs(emg_win(ci+1,ai)-emg_win(ci,ai))>=0.01
                    m_sign(ai) = m_sign(ai) + 1;
                end
            end
        end
        
        clear ai ci
        
        %% waveform length
        l = zeros(1,ch);
        for di = 1:ch
            for k = 1:set_t-1
                l(di) = l(di) + abs(emg_win(k+1,di) - emg_win(k,di));
            end
        end
        
        clear di j
        
        
        datamat = [MAV zc m_sign l];
        
        
        for k = 1:6
            f(k) = (datamat*co(k).linear)+co(k).const;
        end
        
        for k = 1:6
            classI(k) = f(k)>xmark(k);
        end
        if sum(classI) > 1
            classed = 6;
        elseif sum(classI) == 0
            classed = 6;
        elseif sum(classI) == 1
            classed = find(classI);
        end
        
%     end
% elseif v && mov_ave(tCH1)<rat*thres1    % check if below moving threshold
%     classed = 6;
% elseif w && mov_ave(tCH2)<rat*thres2    % check if below moving threshold
%     classed = 6;
% elseif x && mov_ave(tCH3)<rat*thres3    % check if below moving threshold
%     classed = 6;
% elseif y && mov_ave(tCH4)<rat*thres4    % check if below moving threshold
%     classed = 6;
% elseif z && mov_ave(tCH5)<rat*thres5    % check if below moving threshold
%     classed = 6;
% end

if classed ~= 6     % create command matrix
    command_gui(1,classed) = 1;
else
    command_gui = zeros(1,5);
end

end