classdef RespiratoryPhase < Phase properties FullPhase = Phase; IMF = uint32(0); InspirationPositions = []; ExpirationPositions = []; end properties % (GetAccess = private) should become private InspirationTreshold = double(0); ExpirationTreshold = double(0); MaxRespPhase = double(0); MinRespPhase = double(0); end methods %constructor function obj=RespiratoryPhase(Phase) if nargin==0;return;end % gets properties of superclass obj.FullPhase = Phase.ModePhases; % obj.WorkLoad = Phase.WorkLoad; obj.Video = Phase.Video; end % Choose the correct IMF depending on the work load function SelectPhase(obj) 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); obj.Values = obj.FullPhase(obj.IMF,:); %Phase corresponding to respiratory phase end 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 % 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 indexNumeric1 = find(index1); values1 = obj.Values(indexNumeric1); [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 indexNumeric2 = find(index2); values2 = obj.Values(indexNumeric2); [ordered_values2 oredered_index2] = sort(values2); obj.ExpirationPositions = indexNumeric2(oredered_index2); % sorts the frames in ascending respiratory phase end end end