0001 function frame_timing_correct_gui()
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 method='fft';
0030
0031 [filenames,path.data, file_type]=uigetfile({...
0032
0033 '*.get','Gotenberg and Visis files, *.get'; ...
0034
0035
0036 },'Select filename(s):', ...
0037 'MultiSelect', 'on');
0038 if filenames == 0
0039 errordlg('no data selected')
0040 return
0041 end
0042 if ischar(filenames)
0043 filenames=cellstr(filenames);
0044 end
0045
0046
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);
0054
0055 infile=fopen(filename,'r');
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;
0062 fseek(infile,0,'bof');
0063 raw(:,1:eframe,1)=fread(infile,[208,inf],'208*float32',48*4);
0064
0065 fseek(infile,208*4,'bof');
0066 data2=fread(infile,[48,inf],'48*float32',208*4);
0067 fclose(infile);
0068 end
0069
0070 [c_data,stats]= frame_timing_correct(raw, method);
0071
0072
0073 c_data(209:208+48,:)=data2;
0074 outfile=fopen([a b '_corrected' ext],'w');
0075 fseek(outfile,0,'bof');
0076 fwrite(outfile,c_data,'float32');
0077 fclose(outfile);
0078
0079 infile=fopen([a b '.prl'],'r');
0080 if infile==-1;
0081 warndlg(['Cannot find the file: ',b,'.prl']);
0082 fr=13;
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));
0091 fr=str2num(s{line}(13:strfind(s{line},'per')-1));
0092 end
0093
0094 temp= stats.change*100;
0095
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
0101
0102
0103
0104 threshold_p=5;
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;
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;
0112 if max(reci_percent)>threshold_p
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
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),'.')
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
0132 end
0133 end
0134 end