CardiacPhase/Code/CardiacPhase.m

82 lines
3.5 KiB
Matlab

classdef CardiacPhase < Phase
properties
FullPhase = Phase;
IMF = uint32(0);
SystolePositions = [];
DiastolePositions = [];
end
properties % (GetAccess = private) should become private
SystoleTreshold = double(0);
DiastoleTreshold = double(0);
end
methods %constructor
function obj=CardiacPhase(Phase)
if nargin==0;return;end
% gets properties of superclass
obj.FullPhase = Phase.ModePhases;
obj.Video = Phase.Video;
obj.InstantaneousFreq = Phase.InstantaneousFreq;
end
% Choose the correct IMF depending on the work load
function SelectPhase(obj)
prompt = {'Choose the IMF representing cardiac phase:','Combine with additional IMF:'};
dlgtitle = 'Cardiac Phase';
dims = [1 60];
definput = {'3',''};
opts.Interpreter = 'tex';
answer = inputdlg(prompt,dlgtitle,dims,definput,opts);
obj.IMF = str2num(answer{1});
if length(answer{2}) > 0.
new_imf = obj.FullPhase(obj.IMF,:) + obj.FullPhase(str2num(answer{2}),:); % if the IMFs are unorthogonal combine them into one IMF
obj.FullPhase(obj.IMF,:) = new_imf;
obj.FullPhase(str2num(answer{2}),:) = [];
Complot(obj.FullPhase);
end
% SHOULD TRY TO USE GETPHASE FUNCTION
% obj.IMF = imf_number;
% GetPhase@Phase(obj.FullPhase,obj.IMF);
obj.Values = obj.FullPhase(obj.IMF,:); %Phase corresponding to respiratory phase
end
function GetFrequency(obj,time)
heart_inst_freq = (abs(diff(obj.Values))./diff(time))/(2*pi());
obj.InstantaneousFreq = medfilt1(heart_inst_freq,3);
figure
scatter(time,[obj.InstantaneousFreq,0],8);
mean_freq1 = mean(obj.InstantaneousFreq);
hline = refline([0 mean_freq1]); % Reference line for maximum phase
hline.Color = 'm';
title('Cardiac Instantaneous Frequency');
xlabel('Time (sec)')
ylabel('Frequency (Hz)');
end
% Detects the frame's positions of diastolic events
function Diastole(obj)
max_heart_phase = max(obj.Values); % cardiac phase maxima
obj.DiastoleTreshold = 0.8*max_heart_phase; % diastole treshold
index1 = obj.Values > obj.DiastoleTreshold; % frames with phase above the diastolic treshold
indexNumeric1 = find(index1);
values1 = obj.Values(indexNumeric1);
[ordered_values1 oredered_index1] = sort(values1);
obj.DiastolePositions = indexNumeric1(oredered_index1); % sorts the frames in ascending cardiac phase
end
% Detects the frame's positions of systolic events
function Systole(obj)
min_heart_phase = min(obj.Values); % cardiac phase minima
obj.SystoleTreshold = 0.8*min_heart_phase; % systole treshold
index2 = obj.Values < obj.SystoleTreshold; % frames with phase below the systolic treshold
indexNumeric2 = find(index2);
values2 = obj.Values(indexNumeric2);
[ordered_values2 oredered_index2] = sort(values2);
obj.SystolePositions = indexNumeric2(oredered_index2); % sorts the frames in ascending cardiac phase
end
end
end