function ms_sig = mean_sub(signal,Fs)

    win = floor(Fs/2);
    len = length(signal);
    for i=0:win:len-win
        m(i+1:i+win) = mean(signal(1,i+1:i+win));
        j=i+win;
    end

    if(length(m) < length(signal))
        m(j+1:length(signal)) = mean(signal(j+1:end));
    end

    m_sm = smooth(m,win)';
    ms_sig = signal - m_sm;

end