Finished objectifying #8
| @ -1,8 +1,19 @@ | |||||||
| function [params] = simulation_TREPR(Exp,Sys0,params) | function [params] = simulation_TREPR(params) | ||||||
| %SIMULATION_TREPR Summary of this function goes here | %SIMULATION_TREPR Summary of this function goes here | ||||||
| % | % | ||||||
| %   Detailed explanation goes here | %   Detailed explanation goes here | ||||||
| 
 | 
 | ||||||
|  | %% 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 | %% creating UI | ||||||
| fig = figure; | fig = figure; | ||||||
| fig.Name = 'Simulation'; | fig.Name = 'Simulation'; | ||||||
| @ -19,7 +30,7 @@ ax = axes(plotpanel); | |||||||
| ax.XLabel.String = 'magnetic field'; | ax.XLabel.String = 'magnetic field'; | ||||||
| ax.YLabel.String = 'Intensity'; | ax.YLabel.String = 'Intensity'; | ||||||
| %plot manual simulation | %plot manual simulation | ||||||
| [bfield,spec] = pepper(Sys0,Exp); | [bfield,spec] = pepper(eventdata.manSys,eventdata.manExp); | ||||||
| spec_norm = spec/max(spec); % normalize the simulation | spec_norm = spec/max(spec); % normalize the simulation | ||||||
| plot(ax,0.1*params.Field_Vector,params.max_mean,'r',... | plot(ax,0.1*params.Field_Vector,params.max_mean,'r',... | ||||||
|      bfield,spec_norm,'b','LineWidth',1.2) |      bfield,spec_norm,'b','LineWidth',1.2) | ||||||
| @ -286,7 +297,7 @@ uicontrol(InpTx); %passes focus to first input | |||||||
| uiwait(fig) | uiwait(fig) | ||||||
| 
 | 
 | ||||||
| %% Callback functions | %% Callback functions | ||||||
|     function BestSys = SimStartButtonPushed(src,event) |     function SimStartButtonPushed(src,event) | ||||||
|         %get Vary and Opt from Input |         %get Vary and Opt from Input | ||||||
|         varT1 = str2double(get(InpTx,'String')); |         varT1 = str2double(get(InpTx,'String')); | ||||||
|         varT2 = str2double(get(InpTy,'String')); |         varT2 = str2double(get(InpTy,'String')); | ||||||
| @ -301,19 +312,31 @@ uiwait(fig) | |||||||
|         Vary.g = str2double(get(InpG,'String')); |         Vary.g = str2double(get(InpG,'String')); | ||||||
|         FitOpt.Method = get(InpMeth,'String'); |         FitOpt.Method = get(InpMeth,'String'); | ||||||
|         FitOpt.Scaling = get(InpScal,'String'); |         FitOpt.Scaling = get(InpScal,'String'); | ||||||
|  |         %get previous simulation parameters (manual or saved) | ||||||
|  |         Sys0 = eventdata.simSys; | ||||||
|  |         Exp0 = eventdata.simExp; | ||||||
|         %perform fit |         %perform fit | ||||||
|         Sys0.Temperature = [0 0 0]; |         Sys0.Temperature = [0 0 0]; | ||||||
|         [BestSys,BestSpc] = esfit('thyme',params.max_mean,Sys0,Vary,Exp,[],FitOpt); |         [BestSys,BestSpc] = esfit('thyme',params.max_mean,Sys0,Vary,Exp0,[],FitOpt); | ||||||
|         plot(ax,0.1*params.Field_Vector,params.max_mean,'r',... |         plot(ax,0.1*params.Field_Vector,params.max_mean,'r',... | ||||||
|                 0.1*params.Field_Vector,BestSpc,'b','LineWidth',1.2) |                 0.1*params.Field_Vector,BestSpc,'b','LineWidth',1.2) | ||||||
|         xlabel 'Magnetic Field / mT' |         xlabel 'Magnetic Field / mT' | ||||||
|         ylabel 'EPR signal / A. U.' |         ylabel 'EPR signal / A. U.' | ||||||
|         legend('experimental','simulation') |         legend('experimental','simulation') | ||||||
|         axis tight |         axis tight | ||||||
|  |         %normalize Triplett population | ||||||
|  |         Tsum = sum(BestSys.Temperature); | ||||||
|  |         BestSys.Temperature = BestSys.Temperature ./ Tsum; | ||||||
|  |         %write best simulation parameters to eventdata | ||||||
|  |         eventdata.BestSys = BestSys; | ||||||
|     end |     end | ||||||
|      |      | ||||||
|     function SimSaveButtonPushed(src,event) |     function SimSaveButtonPushed(src,event) | ||||||
| %         Sys = BestSys; |         %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 |     end | ||||||
|      |      | ||||||
|     function SimDoneButtonPushed(src,event) |     function SimDoneButtonPushed(src,event) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user