
function [States, features] = SegmentBased_Detection_BLACKSWAN_verPost(x, sampleRate, Model_Feature1, Model_Feature2, Model_Feature3)
%%
% INPUT:
% x
% sampleRate
% Model_Feature1
% Model_Feature2
% Model_Feature3
%
% OUTPUT:
% States
% features
%=======================================================================
% Authors' contact:
% Morteza Zabihi (morteza.zabihi@gmail.com) & Ali Bahrami Rad(abahramir@gmail.com)
% Black Swan Team (April 2017)
%=======================================================================
% This code is released under the GNU General Public License.
% You should have received a copy of the GNU General Public License along with this program.
% If not, see <http://www.gnu.org/licenses/>.

% By accessing the code through Physionet webpage and/or by installing, copying, or otherwise
% using this software, you agree to be bounded by the terms of GNU General Public License.
% If you do not agree, do not install copy or use the software.

% We make no representation about the suitability of this licensed deliverable for any purppose.
% It is provided "as is" without express or implied warranty of any kind.
% Any use of the licensed deliverables must include the above disclaimer.
% For more detailed information please refer to "readme" file.
%%  
rng(0)

beat = buffer(x, 5*sampleRate, 4*sampleRate); 
k = 1; data = [];
for jj =5: size(beat,2)
     data(k,:) = WaveBased_BLACKSWAN(beat(:,jj), sampleRate);   k = k+1;
end
% *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
[~, post1] = predict(Model_Feature1, data);
% *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
[~, post2] = predict(Model_Feature2, data);
% *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
[~, post3] = predict(Model_Feature3, data);
% *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
States = [mean(post1,1), mean(post2,1), mean(post3,1), std(post1,1), std(post2,1), std(post3,1)];

features = [mean(data,1), std(data,1)];