function [trainingDataEEG,trainingDataEEGlf,trainingDataEMG,kinPerSec] = generateTrainingData(signal,kin,windowEMG,windowEEG,shiftEMG,shiftEEG,params,pburgOrder,minEEGFreq,maxEEGFreq,noLFsamples,EMGChannels)
    bci_sf=params.SamplingRate.NumericValue;
    signalWindowEEG=bci_sf*windowEEG;
    tempEEG=zeros([32,fix(floor(size(signal,1)/signalWindowEEG-1)*windowEEG/shiftEEG+1),201]);
    tempEEGlf=zeros([32,fix(floor(size(signal,1)/signalWindowEEG-1)*windowEEG/shiftEEG+1),noLFsamples]);
    
    %Filter around 50 Hz and 150 Hz
    % filter for the range minEEGFreq to maxEEGFreq
    [A,B]= butter(2,[48 52]/(bci_sf/2),'stop');
    [C,D]= butter(2,minEEGFreq/(bci_sf/2),'high');
    [E,F]= butter(2,[148 152]/(bci_sf/2),'stop');
    [G,H]= butter(2,maxEEGFreq/(bci_sf/2),'low');
    
    % filter for low Frequencies
    [V,W]= butter(2,0.01/(bci_sf/2),'high');
    [X,Y]= butter(2,1/(bci_sf/2),'low');

    parfor i=1:32 %filter single channel, w/o EMG, HEOG, Synchro and 0s
        tempEEG(i,:,:)=shiftingPburg(filtfilt(double(G),double(H),filtfilt(double(E),double(F),filtfilt(double(C),double(D),filtfilt(double(A),double(B),double(signal(:,i)))))),bci_sf,windowEEG,shiftEEG,pburgOrder,0,200);
        tempEEGlf(i,:,:)=shiftingDownsample(filtfilt(double(X),double(Y),filtfilt(double(V),double(W),double(signal(:,i)))),bci_sf,windowEEG,shiftEEG,noLFsamples);
    end
    trainingDataEEG=permute(tempEEG,[2 1 3]);
    trainingDataEEGlf=permute(tempEEGlf,[2 1 3]);
    
    trainingDataEMG=waveformLengthAll(signal(:,ismember(params.ChannelNames.Value,EMGChannels)),bci_sf,windowEMG,shiftEMG);
    
    %shift kin according to synch channel in first minute
    [~,startingPoint]=max(abs(diff(signal(1:60*bci_sf,size(signal,2)-1))));
    % add time offset in ms to kin-time
    offset=startingPoint/bci_sf*1000;
    kin(:,1)=kin(:,1)+offset;
    %add dummy timestamp at the end to fill kinematics
    kin=[kin;kin(end,:)];
    kin(end,1)=size(trainingDataEMG,1)*1000*shiftEMG+windowEMG*1000;
    kinPerSec=shiftingKin(kin,windowEMG,shiftEMG);
end
