function y = VAD_trim(x, LWIN, SHIFT, NFFT, FI, NE, THR)

% y = VAD_trim(x)
% 
% This function trim the pauses from the speech signal. If there is no
% output, the signal along with VAD will be figured.
% 
% x         - input signal
% LWIN      - length of win in samples (default: 256)
% SHIFT     - shift in the number of samples (default: 80)
% NFFT      - number of samples used during the FFT calculation 
%             (default: 256)
% FI        - number of frames for noise averaging initizalization
%             (default: 2)
% NE        - noise estimation (default: 0)
% THR       - threshold (default: 1)
% y         - trimmed signal

%% Variables
if (nargin < 2 || (isempty(LWIN)))
    LWIN = 256;
end
if (nargin < 3 || (isempty(SHIFT)))
    SHIFT = 80;
end
if (nargin < 4 || (isempty(NFFT)))
    NFFT = 256;
end
if (nargin < 5 || (isempty(FI)))
    FI = 2;
end
if (nargin < 6 || (isempty(NE)))
    NE = 0;
end
if (nargin < 7 || (isempty(THR)))
    THR = 1;
end

%% Get VAD function and trim signal or plot VAD
if (nargout > 0)
    pos = VAD_find(x, LWIN, SHIFT, NFFT, FI, NE, THR);
    pos = (floor(pos) == 1);
    y   = x(pos);
else
    VAD_find(x, LWIN, SHIFT, NFFT, FI, NE, THR);
end