CardiacPhase/Code/RespiratoryPhase.m

76 lines
3.1 KiB
Mathematica
Raw Permalink Normal View History

2019-05-06 16:34:28 +02:00
classdef RespiratoryPhase < Phase
properties
FullPhase = Phase;
2019-05-13 10:15:01 +02:00
IMF = uint32(0);
2019-05-06 16:34:28 +02:00
InspirationPositions = [];
ExpirationPositions = [];
end
properties % (GetAccess = private) should become private
InspirationTreshold = double(0);
ExpirationTreshold = double(0);
MaxRespPhase = double(0);
MinRespPhase = double(0);
end
2019-05-06 16:34:28 +02:00
methods %constructor
function obj=RespiratoryPhase(Phase)
if nargin==0;return;end
% gets properties of superclass
obj.FullPhase = Phase.ModePhases;
2019-05-13 10:15:01 +02:00
% obj.WorkLoad = Phase.WorkLoad;
2019-05-06 16:34:28 +02:00
obj.Video = Phase.Video;
end
% Choose the correct IMF depending on the work load
function SelectPhase(obj)
2019-05-13 10:15:01 +02:00
prompt = {'Choose the IMF representing respiratory phase:'};
dlgtitle = 'Respiratory Phase';
dims = [1 60];
definput = {'5'};
opts.Interpreter = 'tex';
answer = inputdlg(prompt,dlgtitle,dims,definput,opts);
obj.IMF = str2num(answer{1})
% SHOULD TRY TO USE GETPHASE FUNCTION
% obj.IMF = imf_number;
% GetPhase@Phase(obj.FullPhase,obj.IMF);
2019-05-13 10:15:01 +02:00
obj.Values = obj.FullPhase(obj.IMF,:); %Phase corresponding to respiratory phase
2019-05-06 16:34:28 +02:00
end
2019-05-14 14:54:03 +02:00
function GetFrequency(obj,time)
resp_inst_freq = (abs(diff(obj.Values))./diff(time))/(2*pi());
obj.InstantaneousFreq = medfilt1(resp_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('Respiratory Instantaneous Frequency');
xlabel('Time (sec)')
ylabel('Frequency (Hz)');
end
2019-05-06 16:34:28 +02:00
% Detects the frame's positions of inspiration moments
function Inspiration(obj)
obj.MaxRespPhase = max(obj.Values); % respiratory phase maxima
obj.InspirationTreshold = 0.8*obj.MaxRespPhase; % inspiration treshold
index1 = obj.Values > obj.InspirationTreshold; % frames above inpiration treshold
2019-05-06 16:34:28 +02:00
indexNumeric1 = find(index1);
values1 = obj.Values(indexNumeric1);
2019-05-06 16:34:28 +02:00
[ordered_values1 oredered_index1] = sort(values1);
obj.InspirationPositions = indexNumeric1(oredered_index1); % sorts the frames in ascending respiratory phase
end
% Detects the frame's positions of expiration moments
function Expiration(obj)
obj.MinRespPhase = min(obj.Values); % respiratory phase minima
obj.ExpirationTreshold = 0.8*obj.MinRespPhase; % systole treshold
index2 = obj.Values < obj.ExpirationTreshold; % frames below the systole treshold
2019-05-06 16:34:28 +02:00
indexNumeric2 = find(index2);
values2 = obj.Values(indexNumeric2);
2019-05-06 16:34:28 +02:00
[ordered_values2 oredered_index2] = sort(values2);
obj.ExpirationPositions = indexNumeric2(oredered_index2); % sorts the frames in ascending respiratory phase
end
2019-05-06 16:34:28 +02:00
end
end