 
function [feature, pos]=LTLEV(signal,samples_window,samples_shift,num_frames,frame_shift)
%% LTLEV 
% Paper title:
% Robust whisper activity detection using long-term log energy variation of sub-band signal
% Authors:
% G.Nisha Meenakshi, Dr. Prasanta Kumar Ghosh
% Affiliation:
% Indian Institute of Science (IISc), Bangalore-560012

%% This function computes the feature -- Long-Term Logarithmic Energy Variation (LTLEV)
% Inputs:
% 1) Speech signal : Full-band or Sub-band signal
% 2) For Short-time energy calculations: 
%      samples_window -- Window length in samples
%      samples_shift  -- Window shift in samples 
% 3) For calculating variance:
%      num_frames     -- Number of frames over which variance is to be calculated-- (parameter M from the paper), 
%      frame_shift    -- Frame shift

%% CALCULATE SHORT TIME ENERGY %%
samples_start=1;
samples_stop=samples_window;

i=1;
while (samples_stop<=length(signal))
    t(i,1)=samples_start;
    t(i,2)=samples_stop;
    energy_profile(i,1)=mean(signal(samples_start:samples_stop,1).^2);
    samples_start=samples_start+samples_shift;
    samples_stop=samples_stop+samples_shift;
    i=i+1;
end

%% CALCULATE VARIANCE OF LOGARITHM OF SHORT TIME ENERGY %%
frame_start=1;
frame_stop=num_frames; % M=num_frames

i=1;
while (frame_stop<=length(energy_profile))
    pos(i,1)=t(frame_start,1);
    pos(i,2)=t(frame_stop,2);
    feature(i,1)=var(energy_profile(frame_start:frame_stop,1));
    frame_start=frame_start+frame_shift;
    frame_stop=frame_stop+frame_shift;
    i=i+1;
end