Skip to content
Newer
Older
100755 117 lines (100 sloc) 3.83 KB
0b57975 @timothyv upload 2011/7/18
timothyv authored
1 function [signal time] = siemens_PPOload(fname,varargin);
2
3 %
4 % A loader for the PulseOx data coming off of the Siemens Trio system.
5 %
6 % INPUT:
7 % fname = name of text file with respiration information
8 % opts = options on extracting the ECG signal
9 %
10 % a) 'Hz': Sampling Rate of the signal (50Hz default)
11 %
12 % b) 'TR': Sampling rate of scans (2000ms default)
13 %
14 % c) 'iPatOn': whether or not parallel imaging is on (default true)
15 %
16 % d) 'EndClip': Lag time to stop the physio recording (2040ms default)
17 %
18 % OUTPUT
19 % ppo = vector of the pulse-ox waveform
20 % time = vector of timestamps (in seconds)
21 %
22 %
23 % Written by T. Verstynen (November 2007);
24 % Hacked a bit by J Schlerf (August 2008)
25 %
26 % Rewritten to optimize loading time taking heavily from code written by V.
27 % Deshpande and J. Grinstead, Siemens Medical Solutions (March 2009)
28 %
29 % Liscensed under the GPL public license (version 3.0)
30
31
32 % If no input given, then get the file
33 if nargin < 1 | isempty(fname);
34 [filename filepath] = uigetfile('*.puls','Get PPO File');
35 fname = fullfile(filepath,filename);
36 end
37
38 TR = 2000; % Acquisition time (for working around dummy scans)
39 iPatOn = 1; % If iPat is on, skip an extra TR
40 EndClip = 1000; % Always seems to take a second and change to finish
41 StartClip = 0; % Some systems have to have a pause between record onset and gradient onset
42 Hz = 50; % Sampling Frequency
43 DOSAVE = 0; % Saving Flag
44 StartJump = 0; % Number of shift samples to adjust at the beginning of
45 % the series
46
47 if nargin > 1 & ~isempty(varargin)
48 for i = 1:2:length(varargin)
49 optlabel = varargin{i};
50 optvalue = varargin{i+1};
51
52 if isnumeric(optvalue); optvalue = num2str(optvalue); end;
53 eval(sprintf('%s = %s;',optlabel, optvalue));
54
55 end;
56 end;
57
58 fclose('all');fid=fopen(fname);
59 ignore=textscan(fid,'%s',4); %Ignore first 4 values.
60
61 data = textscan(fid,'%u16'); %Read data until end of u16 data.
62 footer = textscan(fid,'%s'); %Read in remaining data (time stamps and statistics).
63
64 %Get time stamps from footer:
65 for n=1:size(footer{1},1)
66 if strcmp(footer{1}(n),'LogStartMDHTime:') %log start time
67 LogStartTime=str2num(footer{1}{n+1});
68 end
69 if strcmp(footer{1}(n),'LogStopMDHTime:') %log stop time
70 LogStopTime=str2num(footer{1}{n+1});
71 end
72 if strcmp(footer{1}(n),'LogStartMPCUTime:') %scan start time
73 ScanStartTime=str2num(footer{1}{n+1});
74 end
75 if strcmp(footer{1}(n),'LogStopMPCUTime:') %scan stop time
76 ScanStopTime=str2num(footer{1}{n+1});
77 end
78 end
79
80 % Remove the systems own evaluation of triggers.
81 t_on = find(data{1} == 5000); % System uses identifier 5000 as trigger ON
82 t_off = find(data{1} == 5003); % System uses identifier 5003 as trigger OFF
83
84 % Filter the trigger markers from the data
85 data_t=transpose(1:length(data{1}));
86 indx = setdiff(data_t(:),union(t_on,t_off)); %Note: depending on when the scan ends, the last size(t_off)~=size(t_on).
87 signal = data{1}(indx);
88 time = (1:length(signal))./Hz;
89
90 % Now work around the Dummy Scans
91 if iPatOn
92 SkipTR = [1+floor(3000/TR)]+1; % extra reference scan included
93 else
94 SkipTR = [1+floor(3000/TR)];
95 end
96
97 % Clip the time series to begin and end with the scan.
98 if TR < 1000
99 start = StartClip*(Hz/1000)+(TR*SkipTR)*(Hz/1000);
100 stop = length(signal) - Hz*floor([length(signal) - EndClip*(Hz/1000)]/Hz);
101 else
102 start = StartClip*(Hz/1000)+Hz/2+(TR*SkipTR)*(Hz/1000);
103 stop = EndClip*(Hz/1000)+mod(length(signal(1:end)),Hz)+ Hz/2;
104 %stop = length(signal) - Hz*floor([length(signal) - EndClip*(Hz/1000)]/Hz) + Hz/2;
105 end;
106
107 % Reset vectors;
108 signal = double(signal(start+1-StartJump:end-stop-StartJump)');
109 time = time(start+1-StartJump:end-stop-StartJump);
110 time = time(:)-time(1);
111
112 % saving, then save
113 if DOSAVE
114 [fpath fname fext] = fileparts(fname);
115 save(fullfile(fpath,[fname '.mat']),'signal','time');
116 end;
Something went wrong with that request. Please try again.