function [trimmed,index] = trim(orig_signal, signal,rate)
    %signal2 = ssubmmse(signal,rate);
    [c,lags] = xcorr(signal,orig_signal);
    [~,index] = max(c);
    index = index + lags(1);
    len = length(orig_signal)/rate;
    trimmed = signal(abs(index):abs(index) + rate*len -1);
%     noise = length(signal(1:index))/rate;
end