Logistic Regression-HSMM-based Heart Sound Segmentation 1.0

File: <base>/run_Example_Springer_Script.m (2,210 bytes)
%% Example Springer script
% A script to demonstrate the use of the Springer segmentation algorithm

%% Copyright (C) 2016  David Springer
% dave.springer@gmail.com
% any later version.
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% GNU General Public License for more details.

close all;
clear all;

%% Load the default options:
% These options control options such as the original sampling frequency of
% the data, the sampling frequency for the derived features and whether the
% mex code should be used for the Viterbi decoding:
springer_options = default_Springer_HSMM_options;

%% Load the audio data and the annotations:
% These are 6 example PCG recordings, downsampled to 1000 Hz, with
% annotations of the R-peak and end-T-wave positions.

%% Split the data into train and test sets:
% Select the 5 recordings for training and a sixth for testing:
training_indices = [1, 47, 361, 402, 572];
train_recordings = example_data.example_audio_data(training_indices);
train_annotations = example_data.example_annotations(training_indices,:);

test_index = 664;
test_recordings = example_data.example_audio_data(test_index);
test_annotations = example_data.example_annotations(test_index,:);

%% Train the HMM:
[B_matrix, pi_vector, total_obs_distribution] = trainSpringerSegmentationAlgorithm(train_recordings,train_annotations,springer_options.audio_Fs, false);

%% Run the HMM on an unseen test recording:
% And display the resulting segmentation
numPCGs = length(test_recordings);

for PCGi = 1:numPCGs
    [assigned_states] = runSpringerSegmentationAlgorithm(test_recordings{PCGi}, springer_options.audio_Fs, B_matrix, pi_vector, total_obs_distribution, true);