function E = energy(y, wind, winover, padd)

% E = energy(y, wind, winover, padd)
% 
% This function calculates the short-time energy of input signal.
% 
% y         - input column vector
% wind      - length of window in samples or window samples
% winover   - window overlapp in samples
% padd      - if set to 1, the last segment will be padded by zeros 
%             if necessary (default: 0)
% E         - short-time energy

%% Paths and variables
if ((nargin < 2) || (isempty(wind)))
    wind = hamming(0.02*fs); 
end
if ((nargin < 3) || (isempty(winover)))
    winover =  length(wind)/2;
end
if ((nargin < 4) || (isempty(padd)))
    padd = 0;
end

%% Segment the signal
[rows, cols] = size(y);
if ((rows == 1) || (cols == 1))
    if (rows < cols)
        y = y.';
    end
    Y = segmentation(y, wind, winover, padd);
else
    Y = y;
end

%% Calculate the energy
E = sum(abs(Y).^2);