frame_timing_correct_gui

PURPOSE ^

Corrects serially collected *.get data so that each frame appears

SYNOPSIS ^

function frame_timing_correct_gui()

DESCRIPTION ^

Corrects serially collected *.get data so that each frame appears 
to come from an instantaneous point in time.
outputs *_corrected.get & associated *_corrected.prl files
intended to be a standalone compilable file.
CITATION_REQUEST:
  AUTHOR: Rebecca Yerworth and Richard Bayford
  TITLE: The effect of serial data collection on the accuracy of
  electrical impedance tomography images
  JOURNAL: Physiological Measurement
  VOL: 34
  NUM: 6
  YEAR: 2013
  PAGE: 659-669
  LINK: http://iopscience.iop.org/0967-3334/34/6/659/pdf/0967-3334_34_6_659.pdf
  DOI: 10.1088/0967-3334/34/6/659
  PUBMED:  23719130
 
 ISSUES WITH CODE:
   - Code works only with *.get files
%
try
   citeme(serial_correction)
end

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function  frame_timing_correct_gui()
0002 %Corrects serially collected *.get data so that each frame appears
0003 %to come from an instantaneous point in time.
0004 %outputs *_corrected.get & associated *_corrected.prl files
0005 %intended to be a standalone compilable file.
0006 %CITATION_REQUEST:
0007 %  AUTHOR: Rebecca Yerworth and Richard Bayford
0008 %  TITLE: The effect of serial data collection on the accuracy of
0009 %  electrical impedance tomography images
0010 %  JOURNAL: Physiological Measurement
0011 %  VOL: 34
0012 %  NUM: 6
0013 %  YEAR: 2013
0014 %  PAGE: 659-669
0015 %  LINK: http://iopscience.iop.org/0967-3334/34/6/659/pdf/0967-3334_34_6_659.pdf
0016 %  DOI: 10.1088/0967-3334/34/6/659
0017 %  PUBMED:  23719130
0018 %
0019 % ISSUES WITH CODE:
0020 %   - Code works only with *.get files
0021 %%
0022 %try
0023  %   citeme(serial_correction)
0024 %end
0025 
0026 % FIXME
0027 %  - try to avoid global variables
0028 
0029 method='fft'; %to do:give choice of fft or liniear
0030 %choose file and load date
0031 [filenames,path.data, file_type]=uigetfile({...
0032     %'*.get;*.txt','all EIT data files'; ...
0033     '*.get','Gotenberg and Visis files, *.get'; ...
0034     %'*.txt','*.txt files';...
0035     %'*.*',  'All Files (*.*)' ...
0036     },'Select filename(s):', ...
0037     'MultiSelect', 'on');
0038 if filenames == 0
0039         errordlg('no data selected')
0040         return
0041 end
0042 if ischar(filenames)    %if only one file seclected puts as string not cell, so need to convert.
0043     filenames=cellstr(filenames);
0044 end
0045 
0046 %for each file selected....
0047 for i=1:max(size(filenames))
0048     filename = [path.data,'/',filenames{i}];
0049     if file_type == 0
0050         errordlg('no data selected')
0051         return
0052     elseif file_type == 1
0053         [a,b,ext]=fileparts(filename);%work out filetype
0054 % Should use eidors_readdata
0055         infile=fopen(filename,'r'); %open file for reading
0056         if infile==-1;
0057            errordlg(['Cannot find the file: ',filename,'.get']);
0058            return
0059         end;
0060         fseek(infile,0,'eof');
0061         eframe=ftell(infile)/256/4;%number of frames in file
0062         fseek(infile,0,'bof');
0063         raw(:,1:eframe,1)=fread(infile,[208,inf],'208*float32',48*4);%[read 208 boundary voltages, skip 48 pieces of other info] per frame
0064                     %%Loading of addition information.
0065         fseek(infile,208*4,'bof');
0066         data2=fread(infile,[48,inf],'48*float32',208*4);
0067         fclose(infile); %close file
0068     end
0069     
0070   [c_data,stats]= frame_timing_correct(raw, method);
0071 
0072 %output corrected file
0073    c_data(209:208+48,:)=data2; %attach V, I & auxillary data to cleaned data.
0074    outfile=fopen([a b '_corrected' ext],'w'); %open file for writing  %check filename & add '_corrected'
0075    fseek(outfile,0,'bof');
0076    fwrite(outfile,c_data,'float32');
0077    fclose(outfile); %close file
0078    %copy associated .prl file
0079    infile=fopen([a b '.prl'],'r'); %open file for reading
0080    if infile==-1;
0081        warndlg(['Cannot find the file: ',b,'.prl']);
0082        fr=13; % default frame rate
0083    else
0084        prl=fread(infile);
0085        fclose(infile);
0086        outfile=fopen([a b '_corrected.prl'],'w');
0087        fwrite(outfile,prl);
0088        fclose(outfile);
0089        s=importdata([a b '.prl'],'\t');
0090        line=find(strncmp('Framerate = ',s,12)); %find line in .prl file which gives frame rate.
0091        fr=str2num(s{line}(13:strfind(s{line},'per')-1)); %framerate
0092    end
0093    %statistic/how much did file change?
0094    temp= stats.change*100;  % change in percent
0095    %[mean(temp(:)) trimmean(temp(:),10) std(temp(:)) prctile(temp(:),[2.5 97.5])]
0096    h1=msgbox([{strcat('File saved as ''', b, '_corrected.get''')};...
0097        {strcat('Percent change: ', num2str(mean(temp(:)),3) ,'(', num2str(std(temp(:)),3), '), mean(+/-std)')}],...
0098        'Sucess');
0099 end
0100 %h=msgbox('Corrected data saved as *_corrected.get','Finished');
0101 %end
0102 
0103 %function quality
0104 threshold_p=5; %acceptable level of recipocity error (guestimate)
0105 
0106 imdl.fwd_model.reci=[39 51 63 75 87 99 111 123 135 147 159 171 183 52 64 76 88 100 112 124 136 148 160 172 184 196 65 77 89 101 113 125 137 149 161 173 185 197 1 78 90 102 114 126 138 150 162 174 186 198 2 14 91 103 115 127 139 151 163 175 187 199 3 15 27 104 116 128 140 152 164 176 188 200 4 16 28 40 117 129 141 153 165 177 189 201 5 17 29 41 53 130   142   154   166   178     190   202     6    18    30    42    54    66   143   155   167   179   191   203     7    19    31    43    55    67    79   156   168   180     192   204     8    20    32    44    56    68    80    92   169   181   193   205     9    21    33    45    57    69    81    93   105   182     194   206    10    22    34    46    58    70    82    94   106   118   195   207    11    23    35    47    59    71    83    95   107   119     131   208    12    24    36    48    60    72    84    96   108   120   132   144    13    25    37    49    61    73    85    97   109   121     133   145   157    26    38    50    62    74    86    98   110   122   134   146   158   170]';
0107 
0108     reci=(c_data(1:208,:)-c_data(imdl.fwd_model.reci,:,:))./(c_data(1:208,:)+c_data(imdl.fwd_model.reci,:,:))*200; %use corrected data
0109 quality.reci_m=median(reci,2);
0110 quality.reci_std=std(reci,0,2);
0111 reci_percent=sum(quality.reci_m>threshold_p)/length(imdl.fwd_model.reci)*200;%percent of electrode combinations with abs reci>threshold_p%
0112 if max(reci_percent)>threshold_p %threshold may need changing
0113      i=find(reci_percent>threshold_p);
0114    for j=1:length(i)
0115        f = questdlg([num2str(round(reci_percent(:,:,i(j)))) '% of electrode combinations have high reciprocity errors. Data may be unreliable.'], ['% electrode combinations with recipocity error >', num2str(threshold_p), '%'],'ignore', 'display', 'display');
0116       if strmatch(f,'display')
0117           figure
0118           set(gcf,'position',[400 250 800 450])
0119           subplot(2,1,1)
0120           %plot(auxiliary.time.data, reci(:,:,i(j)),'.'); xlabel 'time(s)'; ylabel 'recipocity(%)'
0121           plot([1:size(reci,2)]/fr,reci(:,:,i(j))','.'); xlabel 'time(s)'; ylabel 'recipocity(%)';axis tight
0122           a=axis;
0123           axis([a(1) a(2) 0 a(4)])
0124           title(filenames)
0125           subplot(2,1,2)
0126           errorbar(abs(mean(reci(:,:,i(j))')),std(reci(:,:,i(j))'*2),'.')%if I only show the positive errors, I might not see the pattern of where they come from
0127           axis([1 length(imdl.fwd_model.reci) 0 ceil(max(reci(:)))])
0128           set(gca,'XTick',6:13:208)
0129           set(gca,'XTickLabel',[' 1-2 ';' 2-3 ';' 3-4 ';' 4-5 ';' 5-6 ';' 6-7 ';' 7-8 ';' 8-9 ';' 9-10';'10-11';'11-12';'12-13';'13-14';'14-15';'15-16';'16-1 '])
0130           xlabel 'drive electrodes'; ylabel 'recipocity(%)'
0131           %plot(mean(raw')) %should show 16 'u's, if adj 16.
0132       end
0133    end       
0134 end

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005