Finished objectifying #8
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -1 +1,3 @@ | ||||
| *.asv | ||||
| *.pdf | ||||
| *.xml | ||||
|  | ||||
							
								
								
									
										217
									
								
								EPR_script.m
									
									
									
									
									
								
							
							
						
						
									
										217
									
								
								EPR_script.m
									
									
									
									
									
								
							| @ -1,217 +0,0 @@ | ||||
| % high-spin S=1 simulation | ||||
| % Inputs requested in command line at certain points | ||||
| 
 | ||||
| clear variables | ||||
| close all | ||||
| 
 | ||||
|  % window positions (currently optimised for dual WQHD with main on right) | ||||
|  % also uncomment all figure(gcf) when working with single monitor | ||||
| % Give desired position of figure window as number of pixels [pos_x pos_y size_x size_y]: | ||||
| position = [-1250,50,1200,800]; | ||||
| % Give desired position of figure(2) window (will have two stacked subplots) | ||||
| % as number of pixels [pos_x pos_y size_x size_y]:  | ||||
| position2 = [-2000,50,700,800]; | ||||
| % Give desired position of figure(3) window (will contain EPR spectrum and  | ||||
| % simulation) as number of pixels [pos_x pos_y size_x size_y]:  | ||||
| position3 = [-1250,50,1200,600]; | ||||
| 
 | ||||
| % specify dir for printing figures | ||||
| figdir = './'; | ||||
| % specifiy excel-file for saving parameters | ||||
| table_path = 'example_results.xlsx'; | ||||
| 
 | ||||
| %% loading Data | ||||
| path = input('Path to dataset: ','s'); | ||||
| load(path) | ||||
| 
 | ||||
| whos % what variables have been loaded | ||||
| params % what information is contained in the structure called 'params' | ||||
| 
 | ||||
| % get name of dataset | ||||
| dataname = string(extractBefore(extractAfter(path,asManyOfPattern(wildcardPattern + "/")),'.')); | ||||
| % using Parallel Computing toolbox to speed up (check with "gpuDevice" if you can use this) | ||||
| gpuData = gpuArray(Data); | ||||
| 
 | ||||
| %% Baseline Correcting | ||||
| % plot the raw data & check the number of points before the signal (pre-trigger) | ||||
| plot(gpuData) | ||||
| title('raw data') | ||||
| set(gcf,'Position',position) | ||||
| 
 | ||||
| % substract the pre-trigger | ||||
| pre_trigger = input('Number of pre-trigger points: '); | ||||
| signal_baseline_time = bsxfun(@minus, gpuData, mean(gpuData(1:pre_trigger,:))); | ||||
| plot(signal_baseline_time) % plot the corrected data set | ||||
| title('time corrected data') | ||||
| set(gcf,'Position',position) | ||||
| % figure(gcf) % bring figure to foreground | ||||
| 
 | ||||
| ready = input('Proceed?'); | ||||
| 
 | ||||
|  % plot the transpose and check the number of points to the lower and higher fields of the signal | ||||
| plot(signal_baseline_time.') | ||||
| title('transposed time corrected data') | ||||
| set(gcf,'Position',position) | ||||
| % figure(gcf) % bring figure to foreground | ||||
| 
 | ||||
| 
 | ||||
|  % BASELINE correction | ||||
| baseline_points = input('Number of baseline points (use smaller value from left and right): '); | ||||
| l1 = mean(signal_baseline_time(:,1:baseline_points),2); % calculate the mean on the left along the time axis | ||||
| l2 = mean(signal_baseline_time(:,end-baseline_points:end),2); %calculate the mean on the right along the time axis | ||||
| baseline_time = (l1 +l2)/2; %take the average | ||||
| 
 | ||||
| signal_baseline_time_field = bsxfun(@minus, signal_baseline_time, baseline_time); % subtract the background in the time-domain  | ||||
| 
 | ||||
|  % plot the corrected data set | ||||
| plot(signal_baseline_time_field.') | ||||
| title('transposed fully corrected data') | ||||
| set(gcf,'Position',position) | ||||
| % figure(gcf) % bring figure to foreground | ||||
| 
 | ||||
| clear ready | ||||
| ready = input('Proceed?'); | ||||
| 
 | ||||
|  % plot the transpose to find the region of maximum signal. Use this below | ||||
| plot(signal_baseline_time_field) | ||||
| title('fully corrected data') | ||||
| set(gcf,'Position',position) | ||||
| % figure(gcf) % bring figure to foreground | ||||
| 
 | ||||
|  % contour plot: The index gives the number of contours | ||||
| % contourf(signal_baseline_field_time,6) | ||||
| 
 | ||||
|  % NORMALISING | ||||
| max_region = input('Region of the maximum signal as [x1:x2]: '); | ||||
| % take the mean over the maxium region. You can decide how wide it is | ||||
| signal_baseline_time_field_mean = (mean(signal_baseline_time_field(max_region,:))); | ||||
| % normalise the amplitude to 1 | ||||
| signal_baseline_time_field_mean_norm = signal_baseline_time_field_mean/max(signal_baseline_time_field_mean); | ||||
| 
 | ||||
| %% Creating figure with two subplots | ||||
| figure(2) | ||||
| set(gcf,'PaperUnits','centimeters') | ||||
| set(gcf,'Position',position2) | ||||
| set(gcf,'InvertHardcopy','off','Color',[1 1 1]) | ||||
| set(0,'DefaultAxesFontSize', 12,'DefaultAxesLineWidth',2) | ||||
| 
 | ||||
| cont_or_surf = input('Should lower subplot be contour(1) or surface(2) plot? (1/2): '); | ||||
| subplot(2,1,2) | ||||
| if cont_or_surf == 1 | ||||
|     % contour plot: add the time and field axes | ||||
|     contourf(0.1*params.Field_Vector, TimeBase*1e6 ,signal_baseline_time_field,'LineColor','none') | ||||
| elseif cont_or_surf == 2 | ||||
|     % surface plot: add the time and field axes | ||||
|     surf(0.1*params.Field_Vector, TimeBase*1e6 ,signal_baseline_time_field) | ||||
|     colormap default | ||||
|     shading interp | ||||
| end | ||||
| 
 | ||||
| xlabel('Magnetic Field / mT') | ||||
| ylabel('Time / \mus') | ||||
| 
 | ||||
| subplot(2,1,1) | ||||
|  % plot the spectrum | ||||
| plot(0.1*params.Field_Vector,signal_baseline_time_field_mean_norm,'LineWidth',2) | ||||
| 
 | ||||
| xlabel('Magnetic Field / mT') | ||||
| axis('tight') | ||||
| box off | ||||
| 
 | ||||
| %% Simulation section | ||||
| 
 | ||||
| Exp.mwFreq = params.mwFreq; % GHz | ||||
| Exp.nPoints = length(params.Field_Vector); | ||||
| Exp.CenterSweep = 0.1*[params.Field_Center params.Field_Sweep]; % mT (converted from Gauss) | ||||
| Exp.Harmonic = 0; % zeroth harmonic | ||||
| 
 | ||||
| init_proceed = 'n'; | ||||
| while init_proceed == 'n' | ||||
|     % populations of the triplet sub-levels | ||||
|     % these need to be varied manually to get the right shape | ||||
|     Exp.Temperature = input('Input population of triplett sublevels as [T_x T_y T_z]: '); | ||||
|     % initial simulation settings | ||||
|     Sys.S = 1; % Total Spin | ||||
|     Sys.g = input('g value: '); % needs to be optimised | ||||
|     Sys.D = input('D and E value as [D E]: '); % mT, The D and E values need to be optimised | ||||
|     Sys.lw = input('Isotropic line broadening at FWHM as [Gaussian Lorentzian]: '); % mT, linewidth needs to be optimised | ||||
|      | ||||
|     [bfield,spec] = pepper(Sys,Exp); % perform a simulation with the parameters above | ||||
|     spec_norm = spec/max(spec); % normalize the simulation | ||||
|      | ||||
|     figure(3) | ||||
|     set (gcf,'PaperUnits','centimeters') | ||||
|     set (gcf,'Position',position3) % set the position, size and shape of the plot | ||||
|     set (gcf,'InvertHardcopy','off','Color',[1 1 1]) | ||||
|     set(0,'DefaultAxesFontSize', 16,'DefaultAxesLineWidth',1.5) | ||||
|     plot(0.1*params.Field_Vector,signal_baseline_time_field_mean_norm,'r', bfield,spec_norm,'b','LineWidth',1); | ||||
|     axis('tight') | ||||
|     legend('experimental','simulation') | ||||
|     legend boxoff | ||||
|     xlabel('Magnetic Field / mT') | ||||
|     ylabel('EPR signal / A. U.') | ||||
|     set(gca,'Box','Off', 'XMinorTick','On', 'YMinorTick','On', 'TickDir','Out', 'YColor','k') | ||||
|     pause(2); | ||||
|     init_proceed = input('Spectrum shape manually fitted? [y/n]: ','s'); | ||||
| end | ||||
| 
 | ||||
|  % variation settings for simulation | ||||
| Vary.g = 0.01;  | ||||
| Vary.D = [10 10]; | ||||
| Vary.lw = [1 0]; | ||||
|  % further setup | ||||
| FitOpt.Method = 'simplex fcn'; | ||||
| FitOpt.Scaling = 'lsq'; | ||||
| 
 | ||||
|  % When you have got a good fit by eye, use esfit to optimise | ||||
| simu_proceed = 'n'; | ||||
| while simu_proceed == 'n' | ||||
|     % fitting routine | ||||
|     [BestSys,BestSpc] = esfit('pepper',signal_baseline_time_field_mean_norm,Sys,Vary,Exp,[],FitOpt); | ||||
|     % plot best fit | ||||
|     figure(3) | ||||
|     plot(0.1*params.Field_Vector,signal_baseline_time_field_mean_norm,'r',... | ||||
|          0.1*params.Field_Vector,BestSpc,'b','LineWidth',1); | ||||
|     axis('tight') | ||||
|     legend('experimental','simulation') | ||||
|     legend boxoff | ||||
|     xlabel('Magnetic Field / mT') | ||||
|     ylabel('EPR signal / A. U.') | ||||
|     set(gca,'Box','Off', 'XMinorTick','On', 'YMinorTick','On', 'TickDir','Out', 'YColor','k') | ||||
|      | ||||
|     simu_proceed = input('Did the simulation converge? [y/n]: ','s'); | ||||
|     if simu_proceed == 'n' | ||||
|         simu_val = input('Do you want to repeat the simulation with new best values? [y/n]: ','s'); | ||||
|         if simu_val == 'y' | ||||
|             Sys.g = BestSys.g; | ||||
|             Sys.D = BestSys.D; | ||||
|             Sys.lw = BestSys.lw; | ||||
|         end | ||||
|     end | ||||
| end | ||||
| 
 | ||||
| %% printing figures | ||||
| printing = input('Do you want to print figure(3)? [y/n]: ','s'); | ||||
| if printing == 'y' | ||||
|     figure(3) | ||||
|     set(gcf,'Units','Inches'); | ||||
|     pos = get(gcf,'Position'); | ||||
|     set(gcf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)]); | ||||
|     print(gcf,strcat(figdir,dataname),'-dpdf','-r0'); | ||||
| end | ||||
| 
 | ||||
| %% saving parameters | ||||
|  % concatenate data to existing table | ||||
| table_old = readtable(table_path); | ||||
| table_old.Properties.VariableNames = {'filename', 'date', 'pre-trigger', ... | ||||
|     'baseline_points', 'max_area_left', 'max_area_right', 'T_x', 'T_y', 'T_z', ... | ||||
|     'sim. g-value', 'sim_D', 'sim_E', 'sim_lw_gauss', 'sim_lw_lorentz'}; | ||||
| % new data as table | ||||
| table_new = table(dataname, string(datestr(clock)), pre_trigger, baseline_points, ... | ||||
|     max_region(1), max_region(end), Exp.Temperature(1), Exp.Temperature(2), Exp.Temperature(3), ... | ||||
|     BestSys.g, BestSys.D(1), BestSys.D(2), BestSys.lw(1), BestSys.lw(2), ... | ||||
|     'VariableNames', {'filename', 'date', 'pre-trigger', 'baseline_points', ... | ||||
|     'max_area_left', 'max_area_right', 'T_x', 'T_y', 'T_z', 'sim. g-value', ... | ||||
|     'sim_D', 'sim_E', 'sim_lw_gauss', 'sim_lw_lorentz'}); | ||||
| table_conc = [table_old;table_new]; | ||||
| writetable(table_conc,table_path) | ||||
							
								
								
									
										24
									
								
								TR_EPR_script.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								TR_EPR_script.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| clear variables | ||||
| close all | ||||
| 
 | ||||
| %Script for calling the functions of TR-EPR toolbox | ||||
| 
 | ||||
| %path to dataset | ||||
| datapath = 'C:\Users\lukas\Nextcloud\Uni\Bachelorarbeit\tr-epr-simulation\example_data.mat'; | ||||
| 
 | ||||
| [raw_data,params] = load_matlab(datapath); | ||||
| 
 | ||||
| [time_corr_data,params] = correct_time_baseline(raw_data,params); | ||||
| 
 | ||||
| [full_corr_data,params] = correct_magnetic_baseline(time_corr_data,params); | ||||
| 
 | ||||
| [norm_data,params] = normalize_data(full_corr_data,params); | ||||
| 
 | ||||
| [params] = pre_simulation_TREPR(params); | ||||
| 
 | ||||
| [params] = simulation_TREPR(params); | ||||
| 
 | ||||
| writestruct(params,strcat(params.Path,"/",params.Name,".xml")); | ||||
| 
 | ||||
| print_figure_pdf(full_corr_data,params,1) %print simuation figure | ||||
| % print_figure_pdf(full_corr_data,params,1) %print 3D figure | ||||
							
								
								
									
										127
									
								
								correct_magnetic_baseline.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								correct_magnetic_baseline.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,127 @@ | ||||
| function [dataOUT,params] = correct_magnetic_baseline(dataIN,params) | ||||
| %CORRECT_MAGNETIC_BASELINE UI for basline correction along field axis | ||||
| % | ||||
| %   Usage: [dataOUT,params] = CORRECT_MAGNETIC_BASELINE(dataIN,params), where | ||||
| %   dataIN is a dataset loaded via the LOAD_MATLAB or LOAD_BRUKER function. | ||||
| % | ||||
| %   The function will show the input data and offer an input field, where | ||||
| %   the number of field basline points should be set. It is also possible to | ||||
| %   cut the field axis on both sides by the number in the second input field. | ||||
| %   By pressing "Apply" the correction will be executed and the graph changes | ||||
| %   to the corrected data. The number of field baseline points and points, | ||||
| %   which were cut off, will also be appended to the params struct. | ||||
| %   By pressing "Reset" the graph will return to show the original data. | ||||
| %   Exit the function by pressing "Done". | ||||
| 
 | ||||
| %% creating UI | ||||
| fig = figure; | ||||
| fig.Name = 'Correct Magnetic Baseline'; | ||||
| fig.Units = 'Normalized'; | ||||
| fig.Position = [.2 .2 .6 .6]; | ||||
| fig.Tag = 'CorrMagBase'; | ||||
| 
 | ||||
| %panel for plot | ||||
| plotpanel = uipanel(fig); | ||||
| plotpanel.Units = 'Normalized'; | ||||
| plotpanel.Position = [.01 .06 .98 .92]; | ||||
| %axes for plot | ||||
| ax = axes(plotpanel); | ||||
| ax.XLabel.String = 'Magnetic field'; | ||||
| ax.YLabel.String = 'Intensity'; | ||||
| %plot current data in figure with field as x axis | ||||
| dataIN_transp = dataIN.'; | ||||
| plot(ax,dataIN_transp) | ||||
| axis tight | ||||
| 
 | ||||
| %create push buttons | ||||
| a = uicontrol(fig,'Style','pushbutton'); | ||||
| a.String = 'Apply'; | ||||
| a.Units = 'Normalized'; | ||||
| a.Position = [.52 .01 .15 .05]; | ||||
| a.FontUnits = 'Normalized'; | ||||
| a.FontSize = 0.6; | ||||
| a.Tag = 'Apply'; | ||||
| a.Callback = @FieldApplyButtonPushed; | ||||
| 
 | ||||
| r = uicontrol(fig,'Style','pushbutton'); | ||||
| r.String = 'Reset'; | ||||
| r.Units = 'Normalized'; | ||||
| r.Position = [.68 .01 .15 .05]; | ||||
| r.FontUnits = 'Normalized'; | ||||
| r.FontSize = 0.6; | ||||
| r.Tag = 'Reset'; | ||||
| r.Callback = @FieldResetButtonPushed; | ||||
| 
 | ||||
| d = uicontrol(fig,'Style','pushbutton'); | ||||
| d.String = 'Done'; | ||||
| d.Units = 'Normalized'; | ||||
| d.Position = [.84 .01 .15 .05]; | ||||
| d.FontUnits = 'Normalized'; | ||||
| d.FontSize = 0.6; | ||||
| d.Tag = 'Done'; | ||||
| d.Callback = @FieldDoneButtonPushed; | ||||
| 
 | ||||
| %create input fields | ||||
| p1 = uicontrol(fig,'Style','edit'); | ||||
| p1.String = 'No. points baseline'; | ||||
| p1.Units = 'Normalized'; | ||||
| p1.Position = [.01 .01 .24 .05]; | ||||
| p1.HorizontalAlignment = 'left'; | ||||
| p1.FontUnits = 'Normalized'; | ||||
| p1.FontSize = 0.6; | ||||
| p1.Tag = 'FieldPoints'; | ||||
| 
 | ||||
| p2 = uicontrol(fig,'Style','edit'); | ||||
| p2.String = 'No. points to cut'; | ||||
| p2.Units = 'Normalized'; | ||||
| p2.Position = [.26 .01 .24 .05]; | ||||
| p2.HorizontalAlignment = 'left'; | ||||
| p2.FontUnits = 'Normalized'; | ||||
| p2.FontSize = 0.6; | ||||
| p2.Tag = 'FieldPoints'; | ||||
| 
 | ||||
| uicontrol(p1); %passes focus to input | ||||
| uiwait(fig) | ||||
| 
 | ||||
| %% Callback functions | ||||
|     function FieldApplyButtonPushed(~,event) | ||||
|         field_baseline = str2double(get(p1,'String')); | ||||
|         field_cut = str2double(get(p2,'String')); | ||||
|         %field baseline CUTTING | ||||
|         dataIN(:,1:field_cut) = []; | ||||
|         dataIN(:,end-field_cut:end) = []; | ||||
|         %field baseline CORRECTING | ||||
|         data_size = size(dataIN); | ||||
|         dataOUT = zeros(data_size); | ||||
|         baseline_mean_right = mean(dataIN(:,1:field_baseline),2); | ||||
|         baseline_mean_left = mean(dataIN(:,end-field_baseline:end),2); | ||||
|         baseline_mean = (baseline_mean_right + baseline_mean_left) / 2; | ||||
|         for n = 1:data_size(1) | ||||
|             dataOUT(n,:) = dataIN(n,:) - baseline_mean(n); | ||||
|         end | ||||
|         %plotting result with field as x axis | ||||
|         dataOUT_transp = dataOUT.'; | ||||
|         plot(ax,dataOUT_transp) | ||||
|         axis tight | ||||
|         %adjusting parameter | ||||
|         params.Field_Sweep = params.Field_Sweep - params.Field_Step*2*field_cut; | ||||
|         params.Field_Start = params.Field_Start + params.Field_Step*field_cut; | ||||
|         params.Field_End = params.Field_End - params.Field_Step*field_cut; | ||||
|         params.Field_Vector(:,1:field_cut) = []; | ||||
|         params.Field_Vector(:,end-field_cut:end) = []; | ||||
|         %writing parameter | ||||
|         params.No_field_cut_pts = field_cut; | ||||
|         params.No_field_basline_pts = field_baseline; | ||||
|     end | ||||
| 
 | ||||
|     function FieldResetButtonPushed(~,~) | ||||
|         plot(ax,dataIN_transp) | ||||
|         axis tight | ||||
|     end | ||||
| 
 | ||||
|     function FieldDoneButtonPushed(~,~) | ||||
|         close 'Correct Magnetic Baseline' | ||||
|     end | ||||
| 
 | ||||
| end | ||||
| 
 | ||||
							
								
								
									
										101
									
								
								correct_time_baseline.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								correct_time_baseline.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,101 @@ | ||||
| function [dataOUT,params] = correct_time_baseline(dataIN,params) | ||||
| %CORRECT_TIME_BASELINE UI for basline correction along time axis | ||||
| % | ||||
| %   Usage: [dataOUT,params] = CORRECT_TIME_BASELINE(dataIN,params), where | ||||
| %   dataIN is a dataset loaded via the LOAD_MATLAB or LOAD_BRUKER function. | ||||
| % | ||||
| %   The function will show the input data and offer an input field, where | ||||
| %   the number of pretrigger points should be set. By pressing "Apply" the | ||||
| %   correction will be executed and the graph changes to the corrected data. | ||||
| %   The number of pretigger points will also be appended to the params struct. | ||||
| %   By pressing "Reset" the graph will return to show the original data. | ||||
| %   Exit the function by pressing "Done". | ||||
| 
 | ||||
| %% creating UI | ||||
| fig = figure; | ||||
| fig.Name = 'Correct Time Baseline'; | ||||
| fig.Units = 'Normalized'; | ||||
| fig.Position = [.2 .2 .6 .6]; | ||||
| fig.Tag = 'CorrTimeBase'; | ||||
| 
 | ||||
| %panel for plot | ||||
| plotpanel = uipanel(fig); | ||||
| plotpanel.Units = 'Normalized'; | ||||
| plotpanel.Position = [.01 .06 .98 .92]; | ||||
| %axes for plot | ||||
| ax = axes(plotpanel); | ||||
| ax.XLabel.String = 'Time'; | ||||
| ax.YLabel.String = 'Intensity'; | ||||
| %plot current data in figure | ||||
| plot(ax,dataIN) | ||||
| axis tight | ||||
| 
 | ||||
| %create push buttons | ||||
| a = uicontrol(fig,'Style','pushbutton'); | ||||
| a.String = 'Apply'; | ||||
| a.Units = 'Normalized'; | ||||
| a.Position = [.52 .01 .15 .05]; | ||||
| a.FontUnits = 'Normalized'; | ||||
| a.FontSize = 0.6; | ||||
| a.Tag = 'Apply'; | ||||
| a.Callback = @TimeApplyButtonPushed; | ||||
| 
 | ||||
| r = uicontrol(fig,'Style','pushbutton'); | ||||
| r.String = 'Reset'; | ||||
| r.Units = 'Normalized'; | ||||
| r.Position = [.68 .01 .15 .05]; | ||||
| r.FontUnits = 'Normalized'; | ||||
| r.FontSize = 0.6; | ||||
| r.Tag = 'Reset'; | ||||
| r.Callback = @TimeResetButtonPushed; | ||||
| 
 | ||||
| d = uicontrol(fig,'Style','pushbutton'); | ||||
| d.String = 'Done'; | ||||
| d.Units = 'Normalized'; | ||||
| d.Position = [.84 .01 .15 .05]; | ||||
| d.FontUnits = 'Normalized'; | ||||
| d.FontSize = 0.6; | ||||
| d.Tag = 'Done'; | ||||
| d.Callback = @TimeDoneButtonPushed; | ||||
| 
 | ||||
| %create input field | ||||
| inp = uicontrol(fig,'Style','edit'); | ||||
| inp.String = 'No. points baseline'; | ||||
| inp.Units = 'Normalized'; | ||||
| inp.Position = [.01 .01 .5 .05]; | ||||
| inp.HorizontalAlignment = 'left'; | ||||
| inp.FontUnits = 'Normalized'; | ||||
| inp.FontSize = 0.6; | ||||
| inp.Tag = 'TimePoints'; | ||||
| 
 | ||||
| uicontrol(inp); %passes focus to input | ||||
| uiwait(fig) | ||||
| 
 | ||||
| %% Callback functions | ||||
|     function TimeApplyButtonPushed(~,~) | ||||
|         pretrigger = str2double(get(inp,'String')); | ||||
|         %timeline CORRECTING | ||||
|         data_size = size(dataIN); | ||||
|         dataOUT = zeros(data_size); | ||||
|         for n = 1:data_size(2) | ||||
|             column_mean = mean(dataIN(1:pretrigger,n)); | ||||
|             dataOUT(:,n) = dataIN(:,n) - column_mean; | ||||
|         end | ||||
|         %plotting result | ||||
|         plot(ax,dataOUT) | ||||
|         axis tight | ||||
|         %writing parameter | ||||
|         params.pretrigger = pretrigger; | ||||
|     end | ||||
| 
 | ||||
|     function TimeResetButtonPushed(~,~) | ||||
|         plot(ax,dataIN) | ||||
|         axis tight | ||||
|     end | ||||
| 
 | ||||
|     function TimeDoneButtonPushed(~,~) | ||||
|         close 'Correct Time Baseline' | ||||
|     end | ||||
| 
 | ||||
| end | ||||
| 
 | ||||
							
								
								
									
										11766
									
								
								example_data.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11766
									
								
								example_data.xml
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										65
									
								
								figure_testing.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								figure_testing.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,65 @@ | ||||
| %% function for testing of uifigures and buttons | ||||
| function [] = figure_testing() | ||||
| %% figure with "Apply", "Reset" and "Done" button | ||||
| %create figure | ||||
| fig = figure; | ||||
| fig.Name = 'Test Window'; | ||||
| fig.Units = 'Normalized'; | ||||
| fig.Position = [.2 .2 .6 .6]; | ||||
| fig.Tag = 'Test Window'; | ||||
| 
 | ||||
| %create push buttons | ||||
| a = uicontrol(fig,'Style','pushbutton'); | ||||
| a.String = 'Apply'; | ||||
| a.Units = 'Normalized'; | ||||
| a.Position = [.52 .01 .15 .05]; | ||||
| a.FontUnits = 'Normalized'; | ||||
| a.FontSize = 0.6; | ||||
| a.Tag = 'Apply'; | ||||
| a.Callback = @ApplyButtonPushed; | ||||
| 
 | ||||
| r = uicontrol(fig,'Style','pushbutton'); | ||||
| r.String = 'Reset'; | ||||
| r.Units = 'Normalized'; | ||||
| r.Position = [.68 .01 .15 .05]; | ||||
| r.FontUnits = 'Normalized'; | ||||
| r.FontSize = 0.6; | ||||
| r.Tag = 'Reset'; | ||||
| r.Callback = @ResetButtonPushed; | ||||
| 
 | ||||
| d = uicontrol(fig,'Style','pushbutton'); | ||||
| d.String = 'Done'; | ||||
| d.Units = 'Normalized'; | ||||
| d.Position = [.84 .01 .15 .05]; | ||||
| d.FontUnits = 'Normalized'; | ||||
| d.FontSize = 0.6; | ||||
| d.Tag = 'Done'; | ||||
| d.Callback = @DoneButtonPushed; | ||||
| 
 | ||||
| %create input field | ||||
| inp = uicontrol(fig,'Style','edit'); | ||||
| inp.Units = 'Normalized'; | ||||
| inp.Position = [.01 .01 .5 .05]; | ||||
| inp.HorizontalAlignment = 'left'; | ||||
| inp.FontUnits = 'Normalized'; | ||||
| inp.FontSize = 0.6; | ||||
| % inp.Tag = 'input'; | ||||
| 
 | ||||
| uicontrol(inp); %passes focus to input | ||||
| 
 | ||||
| %% Callback functions | ||||
|     function ApplyButtonPushed(src,event) | ||||
|         out = get(inp,'String'); | ||||
|         txt = strcat("Applied correction by ",out," points!"); | ||||
|         disp(txt) | ||||
|     end | ||||
| 
 | ||||
|     function ResetButtonPushed(src,event) | ||||
|         disp('Resetted data!') | ||||
|     end | ||||
| 
 | ||||
|     function DoneButtonPushed(src,event) | ||||
|         close 'Test Window' | ||||
|     end | ||||
| 
 | ||||
| end | ||||
							
								
								
									
										66
									
								
								load_bruker.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								load_bruker.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,66 @@ | ||||
| function [Data,params] = load_bruker(path) | ||||
| %LOAD_MATLAB imports TR-EPR data recorded with Bruker's xEPR | ||||
| %   Usage: ['data_as_double','struct_with_parameters'] = load_bruker('C:/full/path/to/file.mat') | ||||
| % | ||||
| %   Imports data recorded by xEPR, where x axis is time and y axis is | ||||
| %   magnetic field. | ||||
| %   PATH can be either pointing to .DSC or .DTA, but both need to be there | ||||
| %   and in the same folder. PATH must also contain forwardslashes only. | ||||
| %   The params struct contains metadata of the measurement and is displayed | ||||
| %   in the command window when calling the function. | ||||
| % | ||||
| %   Note that this funtion is dependent on easyspin. | ||||
| % | ||||
| %   Example for params output: | ||||
| %   params =  | ||||
| %  | ||||
| %   struct with fields:                         Units | ||||
| %  | ||||
| %             Field_Center: 3500                G | ||||
| %              Field_Sweep: 2700                G | ||||
| %               Field_Step: 5                   G | ||||
| %            Accumulations: 100                 - | ||||
| %        laser_shotreprate: 20                  - | ||||
| %              Field_Start: 2150                G | ||||
| %                Field_End: 4850                G | ||||
| %             Field_Vector: [1×540 double]      G | ||||
| %                   mwFreq: 9.6845              GHz | ||||
| %                  mwPower: 0.2000              W | ||||
| %                   QValue: 22800               - | ||||
| %                  mwAtten: 30                  dB | ||||
| %                  mwFreqs: [681×1 double]      GHz | ||||
| %                 TimeBase: [1×10001 double]    s | ||||
| %                     Path: '/some/path/'       - | ||||
| %                     Name: 'example_data'      - | ||||
| 
 | ||||
| %correct \ for / | ||||
| corrpath = replace(path,"\","/"); | ||||
| 
 | ||||
| %load Bruker data with help of easyspin | ||||
| [bruker_axes,Data,bruker_params] = eprload(corrpath); | ||||
| 
 | ||||
| %assign metadata to custom params struct | ||||
| params.Field_Center = bruker_params.YMIN + 0.5*bruker_params.YWID; | ||||
| params.Field_Sweep = bruker_params.YWID; | ||||
| params.Field_Step = bruker_params.YWID / (bruker_params.YPTS-1); | ||||
| params.Accumulations = bruker_params.AVGS; | ||||
| params.laser_shotreprate = "NOT RECORDED"; | ||||
| params.Field_Start = bruker_params.YMIN; | ||||
| params.Field_End = bruker_params.YMIN + bruker_params.YWID; | ||||
| params.Field_Vector = cell2mat(bruker_axes(1,2)); | ||||
| params.mwFreq = bruker_params.MWFQ / 1e9; | ||||
| params.mwPower = bruker_params.MWPW * 1e3; | ||||
| params.QValue = "NOT RECORDED"; | ||||
| params.mwAtten = str2double(extractBefore(string(bruker_params.PowerAtten),' ')); | ||||
| params.mwFreqs = "NOT RECORDED"; | ||||
| params.TimeBase = (bruker_params.XMIN:(bruker_params.XWID/bruker_params.XPTS):(bruker_params.XMIN+bruker_params.XWID)) .* 1e-9; | ||||
| 
 | ||||
| %get filename for further documentation and exporting figures | ||||
| [datapath,dataname,~] = fileparts(corrpath); | ||||
| params.Path = datapath; | ||||
| params.Name = dataname; | ||||
| 
 | ||||
| %echo what information is contained in the structure called 'params' | ||||
| params | ||||
| end | ||||
| 
 | ||||
							
								
								
									
										47
									
								
								load_matlab.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								load_matlab.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,47 @@ | ||||
| function [Data,params] = load_matlab(path) | ||||
| %LOAD_MATLAB imports EPR data recorded with MATLAB script | ||||
| %   Usage: ['data_as_double','struct_with_parameters'] = load_matlab('C:/full/path/to/file.mat') | ||||
| % | ||||
| %   Imports data exported from MATLAB workspace and extracts the filename. | ||||
| %   Input has to be the full path to file with forwardslashes as char or | ||||
| %   string. The extracted name is appended to the 'params' struct, whos | ||||
| %   contents are displayed in the command window afterwards. | ||||
| % | ||||
| %   Example for params output: | ||||
| %   params =  | ||||
| %  | ||||
| %   struct with fields:                         Units | ||||
| %  | ||||
| %             Field_Center: 3500                G | ||||
| %              Field_Sweep: 2700                G | ||||
| %               Field_Step: 5                   G | ||||
| %            Accumulations: 100                 - | ||||
| %        laser_shotreprate: 20                  - | ||||
| %              Field_Start: 2150                G | ||||
| %                Field_End: 4850                G | ||||
| %             Field_Vector: [1×540 double]      G | ||||
| %                   mwFreq: 9.6845              GHz | ||||
| %                  mwPower: 0.2000              W | ||||
| %                   QValue: 22800               - | ||||
| %                  mwAtten: 30                  dB | ||||
| %                  mwFreqs: [681×1 double]      GHz | ||||
| %                 TimeBase: [1×10001 double]    s | ||||
| %                     Path: '/some/path/'       - | ||||
| %                     Name: 'example_data'      - | ||||
| 
 | ||||
| %correct \ for / | ||||
| corrpath = replace(path,"\","/"); | ||||
| 
 | ||||
| %load data and write TimeBase in params | ||||
| load(corrpath,'Data','params','TimeBase') | ||||
| params.TimeBase = TimeBase; | ||||
| 
 | ||||
| %get filename for further documentation and exporting figures | ||||
| [datapath,dataname,~] = fileparts(corrpath); | ||||
| params.Path = datapath; | ||||
| params.Name = dataname; | ||||
| 
 | ||||
| %echo what information is contained in the structure called 'params' | ||||
| params | ||||
| end | ||||
| 
 | ||||
							
								
								
									
										109
									
								
								normalize_data.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								normalize_data.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,109 @@ | ||||
| function [dataOUT,params] = normalize_data(dataIN,params) | ||||
| %NORMALISE_DATA normalizes data by max of region | ||||
| % | ||||
| %   Usage: [dataOUT,params] = NORMALISE_DATA(dataIN,params), where dataIN | ||||
| %   is a dataset loaded via the LOAD_MATLAB or LOAD_BRUKER function. | ||||
| % | ||||
| %   The function will show the input data and offer two input fields, where | ||||
| %   the left and right borders of the maximum's region should be set. | ||||
| %   By pressing "Apply" the normalization will be executed and the graph | ||||
| %   changes to the normalized data. The borders of the maximum region and | ||||
| %   the mean of maximums will also be appended to the params struct. | ||||
| %   By pressing "Reset" the graph will return to show the original data. | ||||
| %   Exit the function by pressing "Done". | ||||
| 
 | ||||
| %% creating UI | ||||
| fig = figure; | ||||
| fig.Name = 'Normalize Data'; | ||||
| fig.Units = 'Normalized'; | ||||
| fig.Position = [.2 .2 .6 .6]; | ||||
| fig.Tag = 'Normalize'; | ||||
| 
 | ||||
| %panel for plot | ||||
| plotpanel = uipanel(fig); | ||||
| plotpanel.Units = 'Normalized'; | ||||
| plotpanel.Position = [.01 .06 .98 .92]; | ||||
| %axes for plot | ||||
| ax = axes(plotpanel); | ||||
| ax.XLabel.String = 'Time'; | ||||
| ax.YLabel.String = 'Intensity'; | ||||
| %plot current data in figure with time as x axis | ||||
| plot(ax,dataIN) | ||||
| axis tight | ||||
| 
 | ||||
| %create push buttons | ||||
| a = uicontrol(fig,'Style','pushbutton'); | ||||
| a.String = 'Apply'; | ||||
| a.Units = 'Normalized'; | ||||
| a.Position = [.52 .01 .15 .05]; | ||||
| a.FontUnits = 'Normalized'; | ||||
| a.FontSize = 0.6; | ||||
| a.Tag = 'Apply'; | ||||
| a.Callback = @NormApplyButtonPushed; | ||||
| 
 | ||||
| r = uicontrol(fig,'Style','pushbutton'); | ||||
| r.String = 'Reset'; | ||||
| r.Units = 'Normalized'; | ||||
| r.Position = [.68 .01 .15 .05]; | ||||
| r.FontUnits = 'Normalized'; | ||||
| r.FontSize = 0.6; | ||||
| r.Tag = 'Reset'; | ||||
| r.Callback = @NormResetButtonPushed; | ||||
| 
 | ||||
| d = uicontrol(fig,'Style','pushbutton'); | ||||
| d.String = 'Done'; | ||||
| d.Units = 'Normalized'; | ||||
| d.Position = [.84 .01 .15 .05]; | ||||
| d.FontUnits = 'Normalized'; | ||||
| d.FontSize = 0.6; | ||||
| d.Tag = 'Done'; | ||||
| d.Callback = @NormDoneButtonPushed; | ||||
| 
 | ||||
| %create input fields | ||||
| p1 = uicontrol(fig,'Style','edit'); | ||||
| p1.String = 'Left point of max region'; | ||||
| p1.Units = 'Normalized'; | ||||
| p1.Position = [.01 .01 .24 .05]; | ||||
| p1.HorizontalAlignment = 'left'; | ||||
| p1.FontUnits = 'Normalized'; | ||||
| p1.FontSize = 0.6; | ||||
| p1.Tag = 'MaxRegionLeft'; | ||||
| 
 | ||||
| p2 = uicontrol(fig,'Style','edit'); | ||||
| p2.String = 'Right point of max region'; | ||||
| p2.Units = 'Normalized'; | ||||
| p2.Position = [.25 .01 .24 .05]; | ||||
| p2.HorizontalAlignment = 'left'; | ||||
| p2.FontUnits = 'Normalized'; | ||||
| p2.FontSize = 0.6; | ||||
| p2.Tag = 'MaxRegionRight'; | ||||
| 
 | ||||
| uicontrol(p1); %passes focus to first input | ||||
| uiwait(fig) | ||||
| 
 | ||||
| %% Callback functions | ||||
|     function NormApplyButtonPushed(~,~) | ||||
|         left_point = str2double(get(p1,'String')); | ||||
|         right_point = str2double(get(p2,'String')); | ||||
|         %take mean of each field line between specified min and max time | ||||
|         maxima_mean = mean(dataIN([left_point right_point],:)); | ||||
|         %normalize amplitude to 1 by dividing by max of means | ||||
|         dataOUT = dataIN / max(maxima_mean); | ||||
|         %plotting result with time as x axis | ||||
|         plot(ax,dataOUT) | ||||
|         axis tight | ||||
|         %writing parameter | ||||
|         params.region_of_max = [left_point right_point]; | ||||
|         params.max_mean = maxima_mean / max(maxima_mean); | ||||
|     end | ||||
| 
 | ||||
|     function NormResetButtonPushed(~,~) | ||||
|         plot(ax,dataIN) | ||||
|         axis tight | ||||
|     end | ||||
| 
 | ||||
|     function NormDoneButtonPushed(~,~) | ||||
|         close 'Normalize Data' | ||||
|     end | ||||
| 
 | ||||
| end | ||||
							
								
								
									
										118
									
								
								pentacene_355nm_481pt.DSC
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								pentacene_355nm_481pt.DSC
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,118 @@ | ||||
| #DESC	1.2 * DESCRIPTOR INFORMATION *********************** | ||||
| * | ||||
| *	Dataset Type and Format: | ||||
| * | ||||
| DSRC	EXP | ||||
| BSEQ	BIG | ||||
| IKKF	REAL | ||||
| XTYP	IDX | ||||
| YTYP	IGD | ||||
| ZTYP	NODATA | ||||
| * | ||||
| *	Item Formats: | ||||
| * | ||||
| IRFMT	D | ||||
| YFMT	D | ||||
| * | ||||
| *	Data Ranges and Resolutions: | ||||
| * | ||||
| XPTS	1024 | ||||
| XMIN	0.000000 | ||||
| XWID	10230.000000 | ||||
| YPTS	481 | ||||
| YMIN	2799.991821 | ||||
| YWID	1199.999976 | ||||
| * | ||||
| *	Documentational Text: | ||||
| * | ||||
| TITL	'pentacene_355nm_481pt' | ||||
| IRNAM	'Intensity' | ||||
| XNAM	'Time' | ||||
| YNAM	'Field' | ||||
| IRUNI	'' | ||||
| XUNI	'ns' | ||||
| YUNI	'G' | ||||
| * | ||||
| ************************************************************ | ||||
| * | ||||
| #SPL	1.2 * STANDARD PARAMETER LAYER | ||||
| * | ||||
| OPER    xuser | ||||
| DATE    04/14/21 | ||||
| TIME    15:27:19 | ||||
| CMNT     | ||||
| SAMP     | ||||
| SFOR     | ||||
| STAG    C | ||||
| EXPT    CW | ||||
| OXS1    TADC | ||||
| AXS1    ETIM | ||||
| AXS2    B0VL | ||||
| AXS3     | ||||
| A2RS    481 | ||||
| A2CT    0.34 | ||||
| A2SW    0.12 | ||||
| MWFQ    9.625755e+09 | ||||
| MWPW    0.0006331 | ||||
| AVGS    30 | ||||
| * | ||||
| ************************************************************ | ||||
| * | ||||
| #DSL	1.0 * DEVICE SPECIFIC LAYER | ||||
| * | ||||
| 
 | ||||
| .DVC     acqStart, 1.0 | ||||
| 
 | ||||
| 
 | ||||
| .DVC     fieldCtrl, 1.0 | ||||
| 
 | ||||
| AllegroMode        False | ||||
| Delay              0.0 s | ||||
| FieldFlyback       On | ||||
| FieldWait          Wait LED off | ||||
| GFactor            2.000000 | ||||
| MeasuringHall      False | ||||
| NbPoints           481 | ||||
| RampCenter         3400.00 G | ||||
| RampData            G | ||||
| RampWidth          1200.0 G | ||||
| SetToSampleG       False | ||||
| StaticField        2800.000 G | ||||
| StaticFieldMon     3480.000 G | ||||
| SweepDirection     Up | ||||
| WidthTM            200.0 G | ||||
| 
 | ||||
| .DVC     freqCounter, 1.0 | ||||
| 
 | ||||
| FrequencyMon       9.625755 GHz | ||||
| QMonitBridge       On | ||||
| 
 | ||||
| .DVC     mwBridge, 1.0 | ||||
| 
 | ||||
| AcqFineTuning      Never | ||||
| AcqScanFTuning     Off | ||||
| AcqSliceFTuning    Off | ||||
| BridgeCalib        100.0 | ||||
| Power              0.6331 mW | ||||
| PowerAtten         25 dB | ||||
| 
 | ||||
| .DVC     recorder, 1.0 | ||||
| 
 | ||||
| BaselineCorr       Off | ||||
| NbScansAcc         30 | ||||
| NbScansDone        1 | ||||
| NbScansToDo        1 | ||||
| ReplaceMode        Off | ||||
| SmoothMode         Auto | ||||
| SmoothPoints       1 | ||||
| 
 | ||||
| .DVC     transRec, 1.0 | ||||
| 
 | ||||
| AcqMode            Start Single Trace | ||||
| NbCompScansToDo    1 | ||||
| ReplaceMode        Off | ||||
| TrRecTrgTimeOut    10 s | ||||
| TransPerScan       30 | ||||
| 
 | ||||
| * | ||||
| ************************************************************ | ||||
							
								
								
									
										
											BIN
										
									
								
								pentacene_355nm_481pt.DTA
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								pentacene_355nm_481pt.DTA
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								pentacene_355nm_481pt.YGF
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								pentacene_355nm_481pt.YGF
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										300
									
								
								pre_simulation_TREPR.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										300
									
								
								pre_simulation_TREPR.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,300 @@ | ||||
| function [params] = pre_simulation_TREPR(params) | ||||
| %PRE_SIMULATION_TREPR allows manual fitting of parameters in GUI | ||||
| % | ||||
| %   Usage: [params] = PRE_SIMULATION_TREPR(params), where params is | ||||
| %   a struct, created by the load_bruker/matlab function and preprocessed | ||||
| %   by NORMALIZE_DATA, at least. | ||||
| % | ||||
| %   The function will show a window with a plot of the normalized mean of | ||||
| %   maxima (calculated by NORMALIZE_DATA) and serveral input fields for | ||||
| %   different relevant paramters of TREPR simulation. | ||||
| %   By pressing "Apply" the simulation will be calculated and displayed. | ||||
| %   The simulation parameters will be saved to the params struct. | ||||
| 
 | ||||
| %% creating UI | ||||
| fig = figure; | ||||
| fig.Name = 'Manual Simulation'; | ||||
| fig.Units = 'Normalized'; | ||||
| fig.Position = [.15 .2 .7 .6]; | ||||
| fig.Tag = 'Normalize'; | ||||
| 
 | ||||
| %panel for plot | ||||
| plotpanel = uipanel(fig); | ||||
| plotpanel.Units = 'Normalized'; | ||||
| plotpanel.Position = [.01 .01 .7 .98]; | ||||
| %axes for plot | ||||
| ax = axes(plotpanel); | ||||
| ax.XLabel.String = 'magnetic field'; | ||||
| ax.YLabel.String = 'Intensity'; | ||||
| %plot current data in figure with field as x axis | ||||
| plot(ax,0.1*params.Field_Vector,params.max_mean,'r') | ||||
| axis tight | ||||
| 
 | ||||
| %% create push buttons | ||||
| a = uicontrol(fig,'Style','pushbutton'); | ||||
| a.String = 'Apply'; | ||||
| a.Units = 'Normalized'; | ||||
| a.Position = [.71 .06 .28 .05]; | ||||
| a.FontUnits = 'Normalized'; | ||||
| a.FontSize = 0.6; | ||||
| a.Tag = 'Apply'; | ||||
| a.Callback = @PreSimApplyButtonPushed; | ||||
| 
 | ||||
| d = uicontrol(fig,'Style','pushbutton'); | ||||
| d.String = 'Done'; | ||||
| d.Units = 'Normalized'; | ||||
| d.Position = [.71 .01 .28 .05]; | ||||
| d.FontUnits = 'Normalized'; | ||||
| d.FontSize = 0.6; | ||||
| d.Tag = 'Done'; | ||||
| d.Callback = @PreSimDoneButtonPushed; | ||||
| 
 | ||||
| %% create input and text fields (Triplet) | ||||
| textTrip = uicontrol(fig,'Style','text'); | ||||
| textTrip.String = 'Triplett populations'; | ||||
| textTrip.Units = 'Normalized'; | ||||
| textTrip.Position = [.71 .94 .28 .05]; | ||||
| textTrip.HorizontalAlignment = 'center'; | ||||
| textTrip.FontUnits = 'Normalized'; | ||||
| textTrip.FontSize = 0.6; | ||||
| textTrip.FontWeight = 'bold'; | ||||
| textTrip.Tag = 'textTrip'; | ||||
| 
 | ||||
| textTx = uicontrol(fig,'Style','text'); | ||||
| textTx.String = 'T_1 = '; | ||||
| textTx.Units = 'Normalized'; | ||||
| textTx.Position = [.71 .89 .04333 .05]; | ||||
| textTx.HorizontalAlignment = 'right'; | ||||
| textTx.FontUnits = 'Normalized'; | ||||
| textTx.FontSize = 0.6; | ||||
| textTx.Tag = 'textTx'; | ||||
| 
 | ||||
| InpTx = uicontrol(fig,'Style','edit'); | ||||
| InpTx.String = '1'; | ||||
| InpTx.Units = 'Normalized'; | ||||
| InpTx.Position = [.75334 .89 .04333 .05]; | ||||
| InpTx.HorizontalAlignment = 'left'; | ||||
| InpTx.FontUnits = 'Normalized'; | ||||
| InpTx.FontSize = 0.6; | ||||
| InpTx.Tag = 'InpTx'; | ||||
| 
 | ||||
| textTy = uicontrol(fig,'Style','text'); | ||||
| textTy.String = 'T_2 = '; | ||||
| textTy.Units = 'Normalized'; | ||||
| textTy.Position = [.80668 .89 .04333 .05]; | ||||
| textTy.HorizontalAlignment = 'right'; | ||||
| textTy.FontUnits = 'Normalized'; | ||||
| textTy.FontSize = 0.6; | ||||
| textTy.Tag = 'textTy'; | ||||
| 
 | ||||
| InpTy = uicontrol(fig,'Style','edit'); | ||||
| InpTy.String = '1'; | ||||
| InpTy.Units = 'Normalized'; | ||||
| InpTy.Position = [.85001 .89 .04333 .05]; | ||||
| InpTy.HorizontalAlignment = 'left'; | ||||
| InpTy.FontUnits = 'Normalized'; | ||||
| InpTy.FontSize = 0.6; | ||||
| InpTy.Tag = 'InpTy'; | ||||
| 
 | ||||
| textTz = uicontrol(fig,'Style','text'); | ||||
| textTz.String = 'T_3 = '; | ||||
| textTz.Units = 'Normalized'; | ||||
| textTz.Position = [.90334 .89 .04333 .05]; | ||||
| textTz.HorizontalAlignment = 'right'; | ||||
| textTz.FontUnits = 'Normalized'; | ||||
| textTz.FontSize = 0.6; | ||||
| textTz.Tag = 'textTz'; | ||||
| 
 | ||||
| InpTz = uicontrol(fig,'Style','edit'); | ||||
| InpTz.String = '1'; | ||||
| InpTz.Units = 'Normalized'; | ||||
| InpTz.Position = [.94667 .89 .04333 .05]; | ||||
| InpTz.HorizontalAlignment = 'left'; | ||||
| InpTz.FontUnits = 'Normalized'; | ||||
| InpTz.FontSize = 0.6; | ||||
| InpTz.Tag = 'InpTz'; | ||||
| 
 | ||||
| %% create input and text fields (D & E) | ||||
| textDE = uicontrol(fig,'Style','text'); | ||||
| textDE.String = 'D tensor'; | ||||
| textDE.Units = 'Normalized'; | ||||
| textDE.Position = [.71 .77 .28 .05]; | ||||
| textDE.HorizontalAlignment = 'center'; | ||||
| textDE.FontUnits = 'Normalized'; | ||||
| textDE.FontSize = 0.6; | ||||
| textDE.FontWeight = 'bold'; | ||||
| textDE.Tag = 'textDE'; | ||||
| 
 | ||||
| textD = uicontrol(fig,'Style','text'); | ||||
| textD.String = 'D = '; | ||||
| textD.Units = 'Normalized'; | ||||
| textD.Position = [.71 .72 .0675 .05]; | ||||
| textD.HorizontalAlignment = 'right'; | ||||
| textD.FontUnits = 'Normalized'; | ||||
| textD.FontSize = 0.6; | ||||
| textD.Tag = 'textD'; | ||||
| 
 | ||||
| InpD = uicontrol(fig,'Style','edit'); | ||||
| InpD.String = '1/2 width'; | ||||
| InpD.Units = 'Normalized'; | ||||
| InpD.Position = [.7775 .72 .0675 .05]; | ||||
| InpD.HorizontalAlignment = 'left'; | ||||
| InpD.FontUnits = 'Normalized'; | ||||
| InpD.FontSize = 0.6; | ||||
| InpD.Tag = 'InpD'; | ||||
| 
 | ||||
| textE = uicontrol(fig,'Style','text'); | ||||
| textE.String = 'E = '; | ||||
| textE.Units = 'Normalized'; | ||||
| textE.Position = [.855 .72 .0675 .05]; | ||||
| textE.HorizontalAlignment = 'right'; | ||||
| textE.FontUnits = 'Normalized'; | ||||
| textE.FontSize = 0.6; | ||||
| textE.Tag = 'textE'; | ||||
| 
 | ||||
| InpE = uicontrol(fig,'Style','edit'); | ||||
| InpE.String = '1/3 D'; | ||||
| InpE.Units = 'Normalized'; | ||||
| InpE.Position = [.9225 .72 .0675 .05]; | ||||
| InpE.HorizontalAlignment = 'left'; | ||||
| InpE.FontUnits = 'Normalized'; | ||||
| InpE.FontSize = 0.6; | ||||
| InpE.Tag = 'InpE'; | ||||
| 
 | ||||
| %% create input and text fields (Spin & g) | ||||
| textSG = uicontrol(fig,'Style','text'); | ||||
| textSG.String = 'Spin and g-value'; | ||||
| textSG.Units = 'Normalized'; | ||||
| textSG.Position = [.71 .60 .28 .05]; | ||||
| textSG.HorizontalAlignment = 'center'; | ||||
| textSG.FontUnits = 'Normalized'; | ||||
| textSG.FontSize = 0.6; | ||||
| textSG.FontWeight = 'bold'; | ||||
| textSG.Tag = 'textSG'; | ||||
| 
 | ||||
| textS = uicontrol(fig,'Style','text'); | ||||
| textS.String = 'Spin = '; | ||||
| textS.Units = 'Normalized'; | ||||
| textS.Position = [.71 .55 .0675 .05]; | ||||
| textS.HorizontalAlignment = 'right'; | ||||
| textS.FontUnits = 'Normalized'; | ||||
| textS.FontSize = 0.6; | ||||
| textS.Tag = 'textS'; | ||||
| 
 | ||||
| InpS = uicontrol(fig,'Style','edit'); | ||||
| InpS.String = '1'; | ||||
| InpS.Units = 'Normalized'; | ||||
| InpS.Position = [.7775 .55 .0675 .05]; | ||||
| InpS.HorizontalAlignment = 'left'; | ||||
| InpS.FontUnits = 'Normalized'; | ||||
| InpS.FontSize = 0.6; | ||||
| InpS.Tag = 'InpS'; | ||||
| 
 | ||||
| textG = uicontrol(fig,'Style','text'); | ||||
| textG.String = 'g-value = '; | ||||
| textG.Units = 'Normalized'; | ||||
| textG.Position = [.855 .55 .0675 .05]; | ||||
| textG.HorizontalAlignment = 'right'; | ||||
| textG.FontUnits = 'Normalized'; | ||||
| textG.FontSize = 0.6; | ||||
| textG.Tag = 'textG'; | ||||
| 
 | ||||
| InpG = uicontrol(fig,'Style','edit'); | ||||
| InpG.String = '2'; | ||||
| InpG.Units = 'Normalized'; | ||||
| InpG.Position = [.9225 .55 .0675 .05]; | ||||
| InpG.HorizontalAlignment = 'left'; | ||||
| InpG.FontUnits = 'Normalized'; | ||||
| InpG.FontSize = 0.6; | ||||
| InpG.Tag = 'InpG'; | ||||
| 
 | ||||
| %% create input and text fields (linewidth) | ||||
| textLW = uicontrol(fig,'Style','text'); | ||||
| textLW.String = 'Linewidth'; | ||||
| textLW.Units = 'Normalized'; | ||||
| textLW.Position = [.71 .43 .28 .05]; | ||||
| textLW.HorizontalAlignment = 'center'; | ||||
| textLW.FontUnits = 'Normalized'; | ||||
| textLW.FontSize = 0.6; | ||||
| textLW.FontWeight = 'bold'; | ||||
| textLW.Tag = 'textLW'; | ||||
| 
 | ||||
| textGauss = uicontrol(fig,'Style','text'); | ||||
| textGauss.String = 'lw(Gau) = '; | ||||
| textGauss.Units = 'Normalized'; | ||||
| textGauss.Position = [.71 .38 .0675 .05]; | ||||
| textGauss.HorizontalAlignment = 'right'; | ||||
| textGauss.FontUnits = 'Normalized'; | ||||
| textGauss.FontSize = 0.6; | ||||
| textGauss.Tag = 'textGauss'; | ||||
| 
 | ||||
| InpGauss = uicontrol(fig,'Style','edit'); | ||||
| InpGauss.String = '1'; | ||||
| InpGauss.Units = 'Normalized'; | ||||
| InpGauss.Position = [.7775 .38 .0675 .05]; | ||||
| InpGauss.HorizontalAlignment = 'left'; | ||||
| InpGauss.FontUnits = 'Normalized'; | ||||
| InpGauss.FontSize = 0.6; | ||||
| InpGauss.Tag = 'InpGauss'; | ||||
| 
 | ||||
| textLor = uicontrol(fig,'Style','text'); | ||||
| textLor.String = 'lw(Lor) = '; | ||||
| textLor.Units = 'Normalized'; | ||||
| textLor.Position = [.855 .38 .0675 .05]; | ||||
| textLor.HorizontalAlignment = 'right'; | ||||
| textLor.FontUnits = 'Normalized'; | ||||
| textLor.FontSize = 0.6; | ||||
| textLor.Tag = 'textLor'; | ||||
| 
 | ||||
| InpLor = uicontrol(fig,'Style','edit'); | ||||
| InpLor.String = '0'; | ||||
| InpLor.Units = 'Normalized'; | ||||
| InpLor.Position = [.9225 .38 .0675 .05]; | ||||
| InpLor.HorizontalAlignment = 'left'; | ||||
| InpLor.FontUnits = 'Normalized'; | ||||
| InpLor.FontSize = 0.6; | ||||
| InpLor.Tag = 'InpLor'; | ||||
| 
 | ||||
| uicontrol(InpTx); %passes focus to first input | ||||
| uiwait(fig) | ||||
| 
 | ||||
| %% Callback functions | ||||
|     function PreSimApplyButtonPushed(~,~) | ||||
|         %get values from params | ||||
|         Exp.mwFreq = params.mwFreq; % GHz | ||||
|         Exp.nPoints = length(params.Field_Vector); | ||||
|         Exp.CenterSweep = 0.1*[params.Field_Center params.Field_Sweep]; % mT (converted from Gauss) | ||||
|         Exp.Harmonic = 0; % zeroth harmonic | ||||
|         %get values from UI | ||||
|         T1 = str2double(get(InpTx,'String')); | ||||
|         T2 = str2double(get(InpTy,'String')); | ||||
|         T3 = str2double(get(InpTz,'String')); | ||||
|         Tsum = T1 + T2 + T3; | ||||
|         T1n = T1/Tsum; T2n = T2/Tsum; T3n = T3/Tsum; %normalize population | ||||
|         Exp.Temperature = [T1n T2n T3n]; %Triplet population | ||||
|         Sys.S = str2double(get(InpS,'String')); % Total Spin | ||||
|         Sys.g = str2double(get(InpG,'String')); % g-value | ||||
|         D = str2double(get(InpD,'String')); | ||||
|         E = str2double(get(InpE,'String')); | ||||
|         Sys.D = [D E]; % MHz, D and E values | ||||
|         lwGau = str2double(get(InpGauss,'String')); | ||||
|         lwLor = str2double(get(InpLor,'String')); | ||||
|         Sys.lw = [lwGau lwLor]; % mT, linewidth needs to be optimised | ||||
|         %perform a simulation with the parameters above | ||||
|         [bfield,spec] = pepper(Sys,Exp); | ||||
|         spec_norm = spec/max(spec); % normalize the simulation | ||||
|         %plot result | ||||
|         plot(ax,0.1*params.Field_Vector,params.max_mean,'r',... | ||||
|              bfield,spec_norm,'b','LineWidth',1.2) | ||||
|         legend('experimental','simulation') | ||||
|         axis tight | ||||
|         %write manual fit to params | ||||
|         params.Manual_Sys = Sys; | ||||
|         params.Triplett_pop = Exp.Temperature; | ||||
|     end | ||||
| 
 | ||||
|     function PreSimDoneButtonPushed(~,~) | ||||
|         close 'Manual Simulation' | ||||
|     end | ||||
| 
 | ||||
| end | ||||
							
								
								
									
										60
									
								
								print_figure_pdf.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								print_figure_pdf.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,60 @@ | ||||
| function [] = print_figure_pdf(data,params,type) | ||||
| %PRINT_FIGURE_PDF creates pdf figures of TREPR data | ||||
| % | ||||
| %   Usage: PRINT_FIGURE_PDF(data,params,type), where data are TREPR data | ||||
| %   loaded by LOAD_MATLAB or LOAD_BRUKER, params is a struct created by | ||||
| %   SIMULATION_TREPR and type a number. | ||||
| %    | ||||
| %   type = 1: 2D plot of data and simulation with magnetic field as x-axis | ||||
| %   type = 2: 3D plot of data without simulation | ||||
| 
 | ||||
| if type == 1 | ||||
|     %getting simulation values | ||||
|     Exp.mwFreq = params.mwFreq; % GHz | ||||
|     Exp.nPoints = length(params.Field_Vector); | ||||
|     Exp.CenterSweep = 0.1*[params.Field_Center params.Field_Sweep]; % mT (converted from Gauss) | ||||
|     Exp.Harmonic = 0; % zeroth harmonic | ||||
|     Exp.Temperature = params.Triplett_pop; | ||||
|     Sys = params.Fitted_Simulation; | ||||
|     %calculate simulation | ||||
|     [~,spec] = pepper(Sys,Exp); | ||||
|     spec_norm = spec/max(spec); % normalize the simulation | ||||
|     %plot invisible and print | ||||
|     figure('Visible','off') | ||||
|     plot(0.1*params.Field_Vector,params.max_mean,'r',... | ||||
|          0.1*params.Field_Vector,spec_norm,'b','LineWidth',1.2) | ||||
|     xlabel 'Magnetic Field / mT' | ||||
|     ylabel 'EPR signal / A. U.' | ||||
|     legend('experimental','simulation') | ||||
|     title(params.Name, 'Interpreter','none') | ||||
|     axis tight | ||||
|     set(gcf,'Units','Inches'); | ||||
|     pos = get(gcf,'Position'); | ||||
|     set(gcf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)]); | ||||
|     figurepath = strcat(params.Path,"/",params.Name,"_Sim.pdf"); %create full filename | ||||
|     print(gcf,figurepath,'-dpdf','-r0'); | ||||
|      | ||||
| elseif type == 2 | ||||
|     %plot invisible and print | ||||
|     figure('Visible','off') | ||||
|     surf(0.1*params.Field_Vector, params.TimeBase*1e6, data) | ||||
|     colormap default | ||||
|     shading interp | ||||
|     view(305,10) | ||||
|     axis tight | ||||
|     xlabel 'Magnetic Field / mT' | ||||
|     ylabel 'Time / \mus' | ||||
|     zlabel 'EPR Signal / A.U.' | ||||
|     title(params.Name, 'Interpreter','none') | ||||
|     set(gcf,'Units','Inches'); | ||||
|     pos = get(gcf,'Position'); | ||||
|     set(gcf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)]); | ||||
|     figurepath = strcat(params.Path,"/",params.Name,"_3D.pdf"); %create full filename | ||||
|     print(gcf,figurepath,'-dpdf','-r0'); | ||||
|      | ||||
| else | ||||
|     error('Unknown plot type.'); | ||||
| end | ||||
| 
 | ||||
| end | ||||
| 
 | ||||
							
								
								
									
										358
									
								
								simulation_TREPR.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										358
									
								
								simulation_TREPR.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,358 @@ | ||||
| function [params] = simulation_TREPR(params) | ||||
| %SIMULATION_TREPR uses esfit to perform fitting of TREPR simulation | ||||
| % | ||||
| %   Usage: [params] = SIMULATION_TREPR(params), where params is a struct | ||||
| %   created by the PRE_SIMULATION_TREPR function. | ||||
| %    | ||||
| %   This function will show the mean of maxima, specified in the | ||||
| %   NORMALIZE_DATA function and allow inputs for Variation limits of | ||||
| %   relevant parameters for the simulations and for fitting options. | ||||
| %   "Start Fit" will call esfit and perform the specified fitting. For | ||||
| %   possible values, please refer to the easyspin docs. | ||||
| %   "Save Parameters" will write the current best fitting simulation | ||||
| %   parameters as starting values for a possible next iteration of fitting | ||||
| %   and also write them to the params struct. The button may only be | ||||
| %   pressed after performing at least one iteration of fitting. | ||||
| %   "Done" will close the window. | ||||
| 
 | ||||
| %% setup | ||||
| %create struct for passing data between callbacks | ||||
| eventdata.manSys = params.Manual_Sys; | ||||
| eventdata.manExp.mwFreq = params.mwFreq; %GHz | ||||
| eventdata.manExp.nPoints= length(params.Field_Vector); | ||||
| eventdata.manExp.CenterSweep = 0.1*[params.Field_Center params.Field_Sweep]; % mT (converted from Gauss) | ||||
| eventdata.manExp.Harmonic = 0; % zeroth harmonic | ||||
| eventdata.manExp.Temperature = params.Triplett_pop; | ||||
| eventdata.simSys = params.Manual_Sys; %initialize simulation parameters | ||||
| eventdata.simExp = eventdata.manExp; | ||||
| 
 | ||||
| %% creating UI | ||||
| fig = figure; | ||||
| fig.Name = 'Simulation'; | ||||
| fig.Units = 'Normalized'; | ||||
| fig.Position = [.15 .2 .7 .6]; | ||||
| fig.Tag = 'Normalize'; | ||||
| 
 | ||||
| %panel for plot | ||||
| plotpanel = uipanel(fig); | ||||
| plotpanel.Units = 'Normalized'; | ||||
| plotpanel.Position = [.01 .01 .7 .98]; | ||||
| %axes for plot | ||||
| ax = axes(plotpanel); | ||||
| ax.XLabel.String = 'magnetic field'; | ||||
| ax.YLabel.String = 'Intensity'; | ||||
| %plot manual simulation | ||||
| [bfield,spec] = pepper(eventdata.manSys,eventdata.manExp); | ||||
| spec_norm = spec/max(spec); % normalize the simulation | ||||
| plot(ax,0.1*params.Field_Vector,params.max_mean,'r',... | ||||
|      bfield,spec_norm,'b','LineWidth',1.2) | ||||
| xlabel 'Magnetic Field / mT' | ||||
| ylabel 'EPR signal / A. U.' | ||||
| legend('experimental','simulation') | ||||
| axis tight | ||||
| 
 | ||||
| %% create push buttons | ||||
| s = uicontrol(fig,'Style','pushbutton'); | ||||
| s.String = 'Start Fit'; | ||||
| s.Units = 'Normalized'; | ||||
| s.Position = [.72 .13 .27 .05]; | ||||
| s.FontUnits = 'Normalized'; | ||||
| s.FontSize = 0.6; | ||||
| s.Tag = 'Start'; | ||||
| s.Callback = @SimStartButtonPushed; | ||||
| 
 | ||||
| p = uicontrol(fig,'Style','pushbutton'); | ||||
| p.String = 'Save Parameters'; | ||||
| p.Units = 'Normalized'; | ||||
| p.Position = [.72 .07 .27 .05]; | ||||
| p.FontUnits = 'Normalized'; | ||||
| p.FontSize = 0.6; | ||||
| p.Tag = 'Save'; | ||||
| p.Callback = @SimSaveButtonPushed; | ||||
| 
 | ||||
| d = uicontrol(fig,'Style','pushbutton'); | ||||
| d.String = 'Done'; | ||||
| d.Units = 'Normalized'; | ||||
| d.Position = [.72 .01 .27 .05]; | ||||
| d.FontUnits = 'Normalized'; | ||||
| d.FontSize = 0.6; | ||||
| d.Tag = 'Done'; | ||||
| d.Callback = @SimDoneButtonPushed; | ||||
| 
 | ||||
| %% create input and text fields (Triplet) | ||||
| textTrip = uicontrol(fig,'Style','text'); | ||||
| textTrip.String = 'Triplett population variations'; | ||||
| textTrip.Units = 'Normalized'; | ||||
| textTrip.Position = [.71 .94 .28 .05]; | ||||
| textTrip.HorizontalAlignment = 'center'; | ||||
| textTrip.FontUnits = 'Normalized'; | ||||
| textTrip.FontSize = 0.6; | ||||
| textTrip.FontWeight = 'bold'; | ||||
| textTrip.Tag = 'textTrip'; | ||||
| 
 | ||||
| textTx = uicontrol(fig,'Style','text'); | ||||
| textTx.String = 'T_1 = '; | ||||
| textTx.Units = 'Normalized'; | ||||
| textTx.Position = [.71 .89 .04333 .05]; | ||||
| textTx.HorizontalAlignment = 'right'; | ||||
| textTx.FontUnits = 'Normalized'; | ||||
| textTx.FontSize = 0.6; | ||||
| textTx.Tag = 'textTx'; | ||||
| 
 | ||||
| InpTx = uicontrol(fig,'Style','edit'); | ||||
| InpTx.String = '0'; | ||||
| InpTx.Units = 'Normalized'; | ||||
| InpTx.Position = [.75334 .89 .04333 .05]; | ||||
| InpTx.HorizontalAlignment = 'left'; | ||||
| InpTx.FontUnits = 'Normalized'; | ||||
| InpTx.FontSize = 0.6; | ||||
| InpTx.Tag = 'InpTx'; | ||||
| 
 | ||||
| textTy = uicontrol(fig,'Style','text'); | ||||
| textTy.String = 'T_2 = '; | ||||
| textTy.Units = 'Normalized'; | ||||
| textTy.Position = [.80668 .89 .04333 .05]; | ||||
| textTy.HorizontalAlignment = 'right'; | ||||
| textTy.FontUnits = 'Normalized'; | ||||
| textTy.FontSize = 0.6; | ||||
| textTy.Tag = 'textTy'; | ||||
| 
 | ||||
| InpTy = uicontrol(fig,'Style','edit'); | ||||
| InpTy.String = '0'; | ||||
| InpTy.Units = 'Normalized'; | ||||
| InpTy.Position = [.85001 .89 .04333 .05]; | ||||
| InpTy.HorizontalAlignment = 'left'; | ||||
| InpTy.FontUnits = 'Normalized'; | ||||
| InpTy.FontSize = 0.6; | ||||
| InpTy.Tag = 'InpTy'; | ||||
| 
 | ||||
| textTz = uicontrol(fig,'Style','text'); | ||||
| textTz.String = 'T_3 = '; | ||||
| textTz.Units = 'Normalized'; | ||||
| textTz.Position = [.90334 .89 .04333 .05]; | ||||
| textTz.HorizontalAlignment = 'right'; | ||||
| textTz.FontUnits = 'Normalized'; | ||||
| textTz.FontSize = 0.6; | ||||
| textTz.Tag = 'textTz'; | ||||
| 
 | ||||
| InpTz = uicontrol(fig,'Style','edit'); | ||||
| InpTz.String = '0'; | ||||
| InpTz.Units = 'Normalized'; | ||||
| InpTz.Position = [.94667 .89 .04333 .05]; | ||||
| InpTz.HorizontalAlignment = 'left'; | ||||
| InpTz.FontUnits = 'Normalized'; | ||||
| InpTz.FontSize = 0.6; | ||||
| InpTz.Tag = 'InpTz'; | ||||
| 
 | ||||
| %% create input and text fields (D & E) | ||||
| textDE = uicontrol(fig,'Style','text'); | ||||
| textDE.String = 'D tensor variation'; | ||||
| textDE.Units = 'Normalized'; | ||||
| textDE.Position = [.71 .78 .28 .05]; | ||||
| textDE.HorizontalAlignment = 'center'; | ||||
| textDE.FontUnits = 'Normalized'; | ||||
| textDE.FontSize = 0.6; | ||||
| textDE.FontWeight = 'bold'; | ||||
| textDE.Tag = 'textDE'; | ||||
| 
 | ||||
| textD = uicontrol(fig,'Style','text'); | ||||
| textD.String = 'D = '; | ||||
| textD.Units = 'Normalized'; | ||||
| textD.Position = [.71 .73 .0675 .05]; | ||||
| textD.HorizontalAlignment = 'right'; | ||||
| textD.FontUnits = 'Normalized'; | ||||
| textD.FontSize = 0.6; | ||||
| textD.Tag = 'textD'; | ||||
| 
 | ||||
| InpD = uicontrol(fig,'Style','edit'); | ||||
| InpD.String = '100'; | ||||
| InpD.Units = 'Normalized'; | ||||
| InpD.Position = [.7775 .73 .0675 .05]; | ||||
| InpD.HorizontalAlignment = 'left'; | ||||
| InpD.FontUnits = 'Normalized'; | ||||
| InpD.FontSize = 0.6; | ||||
| InpD.Tag = 'InpD'; | ||||
| 
 | ||||
| textE = uicontrol(fig,'Style','text'); | ||||
| textE.String = 'E = '; | ||||
| textE.Units = 'Normalized'; | ||||
| textE.Position = [.855 .73 .0675 .05]; | ||||
| textE.HorizontalAlignment = 'right'; | ||||
| textE.FontUnits = 'Normalized'; | ||||
| textE.FontSize = 0.6; | ||||
| textE.Tag = 'textE'; | ||||
| 
 | ||||
| InpE = uicontrol(fig,'Style','edit'); | ||||
| InpE.String = '20'; | ||||
| InpE.Units = 'Normalized'; | ||||
| InpE.Position = [.9225 .73 .0675 .05]; | ||||
| InpE.HorizontalAlignment = 'left'; | ||||
| InpE.FontUnits = 'Normalized'; | ||||
| InpE.FontSize = 0.6; | ||||
| InpE.Tag = 'InpE'; | ||||
| 
 | ||||
| %% create input and text fields (linewidth) | ||||
| textLW = uicontrol(fig,'Style','text'); | ||||
| textLW.String = 'Linewidth variations'; | ||||
| textLW.Units = 'Normalized'; | ||||
| textLW.Position = [.71 .62 .28 .05]; | ||||
| textLW.HorizontalAlignment = 'center'; | ||||
| textLW.FontUnits = 'Normalized'; | ||||
| textLW.FontSize = 0.6; | ||||
| textLW.FontWeight = 'bold'; | ||||
| textLW.Tag = 'textLW'; | ||||
| 
 | ||||
| textGauss = uicontrol(fig,'Style','text'); | ||||
| textGauss.String = 'lw(Gau) = '; | ||||
| textGauss.Units = 'Normalized'; | ||||
| textGauss.Position = [.71 .57 .0675 .05]; | ||||
| textGauss.HorizontalAlignment = 'right'; | ||||
| textGauss.FontUnits = 'Normalized'; | ||||
| textGauss.FontSize = 0.6; | ||||
| textGauss.Tag = 'textGauss'; | ||||
| 
 | ||||
| InpGauss = uicontrol(fig,'Style','edit'); | ||||
| InpGauss.String = '1'; | ||||
| InpGauss.Units = 'Normalized'; | ||||
| InpGauss.Position = [.7775 .57 .0675 .05]; | ||||
| InpGauss.HorizontalAlignment = 'left'; | ||||
| InpGauss.FontUnits = 'Normalized'; | ||||
| InpGauss.FontSize = 0.6; | ||||
| InpGauss.Tag = 'InpGauss'; | ||||
| 
 | ||||
| textLor = uicontrol(fig,'Style','text'); | ||||
| textLor.String = 'lw(Lor) = '; | ||||
| textLor.Units = 'Normalized'; | ||||
| textLor.Position = [.855 .57 .0675 .05]; | ||||
| textLor.HorizontalAlignment = 'right'; | ||||
| textLor.FontUnits = 'Normalized'; | ||||
| textLor.FontSize = 0.6; | ||||
| textLor.Tag = 'textLor'; | ||||
| 
 | ||||
| InpLor = uicontrol(fig,'Style','edit'); | ||||
| InpLor.String = '0'; | ||||
| InpLor.Units = 'Normalized'; | ||||
| InpLor.Position = [.9225 .57 .0675 .05]; | ||||
| InpLor.HorizontalAlignment = 'left'; | ||||
| InpLor.FontUnits = 'Normalized'; | ||||
| InpLor.FontSize = 0.6; | ||||
| InpLor.Tag = 'InpLor'; | ||||
| 
 | ||||
| %% create input and text fields (g) | ||||
| textG = uicontrol(fig,'Style','text'); | ||||
| textG.String = 'g-value variation = '; | ||||
| textG.Units = 'Normalized'; | ||||
| textG.Position = [.71 .46 .2 .05]; | ||||
| textG.HorizontalAlignment = 'right'; | ||||
| textG.FontUnits = 'Normalized'; | ||||
| textG.FontSize = 0.6; | ||||
| textG.Tag = 'textG'; | ||||
| 
 | ||||
| InpG = uicontrol(fig,'Style','edit'); | ||||
| InpG.String = '0.01'; | ||||
| InpG.Units = 'Normalized'; | ||||
| InpG.Position = [.9225 .46 .0675 .05]; | ||||
| InpG.HorizontalAlignment = 'left'; | ||||
| InpG.FontUnits = 'Normalized'; | ||||
| InpG.FontSize = 0.6; | ||||
| InpG.Tag = 'InpG'; | ||||
| 
 | ||||
| %% create input and text fields (FitOpt) | ||||
| textOpt = uicontrol(fig,'Style','text'); | ||||
| textOpt.String = 'Fitting Options'; | ||||
| textOpt.Units = 'Normalized'; | ||||
| textOpt.Position = [.71 .35 .28 .05]; | ||||
| textOpt.HorizontalAlignment = 'center'; | ||||
| textOpt.FontUnits = 'Normalized'; | ||||
| textOpt.FontSize = 0.6; | ||||
| textOpt.FontWeight = 'bold'; | ||||
| textOpt.Tag = 'textFitOpt'; | ||||
| 
 | ||||
| textMeth = uicontrol(fig,'Style','text'); | ||||
| textMeth.String = 'Method: '; | ||||
| textMeth.Units = 'Normalized'; | ||||
| textMeth.Position = [.71 .30 .0675 .05]; | ||||
| textMeth.HorizontalAlignment = 'right'; | ||||
| textMeth.FontUnits = 'Normalized'; | ||||
| textMeth.FontSize = 0.6; | ||||
| textMeth.Tag = 'textMeth'; | ||||
| 
 | ||||
| InpMeth = uicontrol(fig,'Style','edit'); | ||||
| InpMeth.String = 'simplex fcn'; | ||||
| InpMeth.Units = 'Normalized'; | ||||
| InpMeth.Position = [.7775 .30 .2125 .05]; | ||||
| InpMeth.HorizontalAlignment = 'left'; | ||||
| InpMeth.FontUnits = 'Normalized'; | ||||
| InpMeth.FontSize = 0.6; | ||||
| InpMeth.Tag = 'InpMeth'; | ||||
| 
 | ||||
| textScal = uicontrol(fig,'Style','text'); | ||||
| textScal.String = 'Scaling: '; | ||||
| textScal.Units = 'Normalized'; | ||||
| textScal.Position = [.71 .24 .0675 .05]; | ||||
| textScal.HorizontalAlignment = 'right'; | ||||
| textScal.FontUnits = 'Normalized'; | ||||
| textScal.FontSize = 0.6; | ||||
| textScal.Tag = 'textScal'; | ||||
| 
 | ||||
| InpScal = uicontrol(fig,'Style','edit'); | ||||
| InpScal.String = 'lsq'; | ||||
| InpScal.Units = 'Normalized'; | ||||
| InpScal.Position = [.7775 .24 .2125 .05]; | ||||
| InpScal.HorizontalAlignment = 'left'; | ||||
| InpScal.FontUnits = 'Normalized'; | ||||
| InpScal.FontSize = 0.6; | ||||
| InpScal.Tag = 'InpScal'; | ||||
| 
 | ||||
| %% UI wait | ||||
| uicontrol(InpTx); %passes focus to first input | ||||
| uiwait(fig) | ||||
| 
 | ||||
| %% Callback functions | ||||
|     function SimStartButtonPushed(~,~) | ||||
|         %get Vary and Opt from Input | ||||
|         varT1 = str2double(get(InpTx,'String')); | ||||
|         varT2 = str2double(get(InpTy,'String')); | ||||
|         varT3 = str2double(get(InpTz,'String')); | ||||
|         Vary.Temperature = [varT1 varT2 varT3]; | ||||
|         varD = str2double(get(InpD,'String')); | ||||
|         varE = str2double(get(InpE,'String')); | ||||
|         Vary.D = [varD varE]; | ||||
|         varGauss = str2double(get(InpGauss,'String')); | ||||
|         varLor = str2double(get(InpLor,'String')); | ||||
|         Vary.lw = [varGauss varLor]; | ||||
|         Vary.g = str2double(get(InpG,'String')); | ||||
|         FitOpt.Method = get(InpMeth,'String'); | ||||
|         FitOpt.Scaling = get(InpScal,'String'); | ||||
|         %get previous simulation parameters (manual or saved) | ||||
|         Sys0 = eventdata.simSys; | ||||
|         Exp0 = eventdata.simExp; | ||||
|         %perform fit | ||||
|         Sys0.Temperature = [0 0 0]; | ||||
|         [BestSys,BestSpc] = esfit('thyme',params.max_mean,Sys0,Vary,Exp0,[],FitOpt); | ||||
|         plot(ax,0.1*params.Field_Vector,params.max_mean,'r',... | ||||
|                 0.1*params.Field_Vector,BestSpc,'b','LineWidth',1.2) | ||||
|         xlabel 'Magnetic Field / mT' | ||||
|         ylabel 'EPR signal / A. U.' | ||||
|         legend('experimental','simulation') | ||||
|         axis tight | ||||
|         %normalize Triplett population | ||||
|         Tsum = sum(BestSys.Temperature); | ||||
|         BestSys.Temperature = BestSys.Temperature ./ Tsum; | ||||
|         %write best simulation parameters to eventdata | ||||
|         eventdata.BestSys = BestSys; | ||||
|     end | ||||
|      | ||||
|     function SimSaveButtonPushed(~,~) | ||||
|         %set current parameters as new start values | ||||
|         eventdata.simSys = eventdata.BestSys; | ||||
|         eventdata.simExp.Temperature = eventdata.BestSys.Temperature; | ||||
|         %save fitted parameters to struct | ||||
|         params.Fitted_Simulation = eventdata.BestSys; | ||||
|     end | ||||
|      | ||||
|     function SimDoneButtonPushed(~,~) | ||||
|         close 'Simulation' | ||||
|     end | ||||
|   | ||||
| end | ||||
							
								
								
									
										9
									
								
								thyme.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								thyme.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| function y = thyme(Sys,Exp,Opt) | ||||
| %THYME custom function for easyspin fitting | ||||
| % | ||||
| %   Takes Triplett populations into account when performing esfit. | ||||
| %   Call as [B,Spec] = esfit('thyme',Sys,Exp,Opt); | ||||
| 
 | ||||
| 	Sys.Temperature = Exp.Temperature; | ||||
|     y = pepper(Sys,Exp,Opt); | ||||
| end | ||||
							
								
								
									
										117
									
								
								write_params_txt.m
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										117
									
								
								write_params_txt.m
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,117 @@ | ||||
| function [] = write_params_txt(params) | ||||
| %WRITE_PARAMS_TXT Summary of this function goes here | ||||
| %   Detailed explanation goes here | ||||
| 
 | ||||
| filename = strcat(params.Path,"/",params.Name,".txt"); | ||||
| struct2File(params,filename); | ||||
| 
 | ||||
|     function struct2File(s,fileName,varargin) | ||||
|     %Write struct to text file. The data in the struct can be both numbers and | ||||
|     %strings. The first line in the file will be a row with the headers/names | ||||
|     %of the columns. | ||||
|     %Ex: struct2File( s, 'c:/test.txt' ); | ||||
|     %Ex: struct2File( s, 'c:/test.txt', 'precision', 3 ); %specify precision | ||||
|     %Ex: struct2File( s, 'c:/test.txt', 'promptOverWrite', false ); | ||||
|     [varargin,align]=getarg(varargin,'align',false); | ||||
|     align=align{:}; | ||||
|     [varargin,delimiter]=getarg(varargin,'delimiter','\t'); | ||||
|     delimiter=delimiter{:}; | ||||
|     [varargin,units]=getarg(varargin,'units',''); | ||||
|     units=units{:}; | ||||
|     [varargin,promptOverWrite]=getarg(varargin,'promptOverWrite',false); | ||||
|     promptOverWrite=promptOverWrite{:}; | ||||
|     [varargin,precision]=getarg(varargin,'precision',6); | ||||
|     precision=precision{:}; | ||||
|     [varargin,Sort]=getarg(varargin,'sort',true); | ||||
|     Sort=Sort{:}; | ||||
|     if ~isempty(varargin) | ||||
|         error('Unknown optional arguments specified'); | ||||
|     end | ||||
|     fields = fieldnames(s)'; | ||||
|     if ~isempty(units) | ||||
|         if numel(units)~=numel(fields) | ||||
|             error('The number of units specified doesn not match the number of fields in the struct'); | ||||
|         end | ||||
|     end | ||||
|     if exist(fileName,'file')==2 && promptOverWrite | ||||
|         res = questdlg('File exists, overwrite?','', ... | ||||
|             'Yes', 'No', 'Yes'); | ||||
|         if strcmpi(res,'No') | ||||
|             disp('Aborted'); | ||||
|             return; | ||||
|         end | ||||
|     end | ||||
|     data=cell(numel(s),numel(fields)); | ||||
|     for k=1:numel(fields) | ||||
|         fn=fields{k}; | ||||
|         data(:,k) = {s.(fn)}; | ||||
|     end | ||||
|     if size(units,2)==1 | ||||
|         units = units'; | ||||
|     end | ||||
|     if ~isempty(units) | ||||
|         data=[units;data]; | ||||
|     end | ||||
|     data=[fields;data]; | ||||
|     if Sort | ||||
|         [fields,ind] = sort(fields); | ||||
|         data = data(:,ind); | ||||
|     end | ||||
|     %ex1 = {'a' 1 12 123; 'ab' 4 5 6; 'abc' 7 8 9}; | ||||
|     ex_func3 = @(input)ex_func(input,precision); | ||||
|     ex2 = cellfun(ex_func3,data,'UniformOutput',0); | ||||
|     if align | ||||
|         size_ex2 = cellfun(@length,ex2,'UniformOutput',0); | ||||
|         str_length = max(max(cell2mat(size_ex2)))+1; | ||||
|         ex2 = cellfun(@(x) ex_func2(x,str_length),ex2,'uniformoutput',0); | ||||
|         ex2 = cell2mat(ex2); | ||||
|     end | ||||
|     fid = fopen(fileName,'wt'); | ||||
|     if fid==-1 | ||||
|         error('Could not open %s'); | ||||
|     end | ||||
|     if iscell(ex2) | ||||
|         [m,n]=size(ex2); | ||||
|         for i=1:m | ||||
|             for j=1:n | ||||
|                 fprintf(fid,'%s',ex2{i,j}); | ||||
|                 if j<n | ||||
|                     fprintf(fid,delimiter); | ||||
|                 end | ||||
|             end | ||||
|             if i<m | ||||
|                 fprintf(fid,'\n'); | ||||
|             end | ||||
|         end | ||||
|     else | ||||
|         m=size(ex2,1); | ||||
|         for i=1:m | ||||
|             fprintf(fid,'%s',strtrim(ex2(i,:))); | ||||
|             if i<m | ||||
|                 fprintf(fid,'\n'); | ||||
|             end | ||||
|         end | ||||
|     end | ||||
|     fclose(fid); | ||||
|     function [ out ] = ex_func( in, prec ) | ||||
|         if iscell(in) | ||||
|             in = in{:}; | ||||
|         end | ||||
|         in_datatype = class(in); | ||||
|         switch in_datatype | ||||
|             case 'char' | ||||
|                 out = in; | ||||
|             case 'double' | ||||
|                 out = num2str(in, prec); | ||||
|             otherwise | ||||
|                 error('Unknown type'); | ||||
|         end | ||||
|     end | ||||
|     function [ out ] = ex_func2( in, str_length ) | ||||
|         a = length(in); | ||||
|         out = [char(32*ones(1,str_length-a)), in]; | ||||
|         {"mode":"full","isActive":false}; | ||||
|     end | ||||
|     end | ||||
| 
 | ||||
| end | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user