Update EPR_script.m
Finished requests on correcting and plotting section. Also moved normalising into "Baseline correcting" section.
This commit is contained in:
		
							parent
							
								
									16a0b198f6
								
							
						
					
					
						commit
						eb4f59fe15
					
				
							
								
								
									
										109
									
								
								EPR_script.m
									
									
									
									
									
								
							
							
						
						
									
										109
									
								
								EPR_script.m
									
									
									
									
									
								
							| @ -4,88 +4,107 @@ | |||||||
| clear variables | clear variables | ||||||
| close all | close all | ||||||
| 
 | 
 | ||||||
| %% Baseline Correcting |  % window positions (currently optimised for dual WQHD with main on right) | ||||||
| % loading Data | % 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]; | ||||||
|  | 
 | ||||||
|  | %% loading Data | ||||||
| path = input('Path to dataset: ','s'); | path = input('Path to dataset: ','s'); | ||||||
| load(path) | load(path) | ||||||
| 
 | 
 | ||||||
| whos % what variables have been loaded | whos % what variables have been loaded | ||||||
| params % what information is contained in the structure called 'params' | params % what information is contained in the structure called 'params' | ||||||
| 
 | 
 | ||||||
|  | %% Baseline Correcting | ||||||
| % plot the raw data & check the number of points before the signal (pre-trigger) | % plot the raw data & check the number of points before the signal (pre-trigger) | ||||||
| plot(Data) | plot(Data) | ||||||
| title('raw data') | title('raw data') | ||||||
|  | set(gcf,'Position',position) | ||||||
| 
 | 
 | ||||||
| % substract the pre-trigger | % substract the pre-trigger | ||||||
| pre_trigger = input('Number of pre-trigger points: '); | pre_trigger = input('Number of pre-trigger points: '); | ||||||
| signal_baseline_field = bsxfun(@minus, Data, mean(Data(1:pre_trigger,:))); | signal_baseline_time = bsxfun(@minus, Data, mean(Data(1:pre_trigger,:))); | ||||||
| plot(signal_baseline_field) % plot the corrected data set | plot(signal_baseline_time) % plot the corrected data set | ||||||
| title('corrected data') | title('time corrected data') | ||||||
| return | 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 the transpose and check the number of points to the lower and higher fields of the signal | ||||||
| % plot(signal_baseline_field') | plot(signal_baseline_time') | ||||||
| % use the smaller value below | title('transposed time corrected data') | ||||||
| % return | set(gcf,'Position',position) | ||||||
|  | % figure(gcf) % bring figure to foreground | ||||||
| 
 | 
 | ||||||
|  % BASLINE correction | 
 | ||||||
| time_points = 140; % number of points from the plot above |  % BASELINE correction | ||||||
| l1 = mean(signal_baseline_field(:,1:time_points),2); % calculate the mean on the left along the time axis | baseline_points = input('Number of baseline points (use smaller value from left and right): '); | ||||||
| l2 = mean(signal_baseline_field(:,end-time_points:end),2); %calculate the mean on the right along the time axis | 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 | baseline_time = (l1 +l2)/2; %take the average | ||||||
| 
 | 
 | ||||||
| signal_baseline_field_time = bsxfun(@minus, signal_baseline_field, baseline_time); % subtract the background in the time-domain  | signal_baseline_time_field = bsxfun(@minus, signal_baseline_time, baseline_time); % subtract the background in the time-domain  | ||||||
| 
 | 
 | ||||||
|  % plot the corrected data set |  % plot the corrected data set | ||||||
| % plot(signal_baseline_field_time') | plot(signal_baseline_time_field') | ||||||
| % return | 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 the transpose to find the region of maximum signal. Use this below | ||||||
| % plot(signal_baseline_field_time) | plot(signal_baseline_time_field) | ||||||
| % return | title('fully corrected data') | ||||||
|  | set(gcf,'Position',position) | ||||||
|  | % figure(gcf) % bring figure to foreground | ||||||
| 
 | 
 | ||||||
|  % contour plot: The index gives the number of contours |  % contour plot: The index gives the number of contours | ||||||
| % contourf(signal_baseline_field_time,6) | % contourf(signal_baseline_field_time,6) | ||||||
| % return |  | ||||||
| 
 | 
 | ||||||
| %% |  % NORMALISING | ||||||
| figure(1) | 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,'PaperUnits','centimeters') | ||||||
| set(gcf,'Position',[0,0,750, 750]) | set(gcf,'Position',position2) | ||||||
| set(gcf,'InvertHardcopy','off','Color',[1 1 1]) | set(gcf,'InvertHardcopy','off','Color',[1 1 1]) | ||||||
| set(0,'DefaultAxesFontSize', 14,'DefaultAxesLineWidth',2) | set(0,'DefaultAxesFontSize', 12,'DefaultAxesLineWidth',2) | ||||||
| 
 | 
 | ||||||
|  % contour plot: add the time and field axes | cont_or_surf = input('Should lower subplot be contour(1) or surface(2) plot? (1/2): '); | ||||||
| subplot(2,1,2) | subplot(2,1,2) | ||||||
| contourf(0.1*params.Field_Vector, TimeBase*1e6 ,signal_baseline_field_time,'LineColor','none') | if cont_or_surf == 1 | ||||||
| 
 |     % contour plot: add the time and field axes | ||||||
|  % contour plot: add the time and field axes |     contourf(0.1*params.Field_Vector, TimeBase*1e6 ,signal_baseline_time_field,'LineColor','none') | ||||||
| % surf(0.1*params.Field_Vector, TimeBase*1e6 ,signal_baseline_field_time) | elseif cont_or_surf == 2 | ||||||
| % colormap default |     % surface plot: add the time and field axes | ||||||
| % shading interp |     surf(0.1*params.Field_Vector, TimeBase*1e6 ,signal_baseline_time_field) | ||||||
|  |     colormap default | ||||||
|  |     shading interp | ||||||
|  | end | ||||||
| 
 | 
 | ||||||
| xlabel('Magnetic Field / mT') | xlabel('Magnetic Field / mT') | ||||||
| ylabel('Time / \mus') | ylabel('Time / \mus') | ||||||
| % colorbar |  | ||||||
| % print('TR_EPR_Chichibabin_80K_frozen_solution_532_01_3D' , '-dpng', '-r300') |  | ||||||
| % return |  | ||||||
| 
 | 
 | ||||||
| subplot(2,1,1) | subplot(2,1,1) | ||||||
| 
 |  | ||||||
|  % take the mean over the maxium region. You can decide how wide it is |  | ||||||
| signal_baseline_field_time_mean = (mean(signal_baseline_field_time(1300:1390,:))); |  | ||||||
|  % normalise the amplitude to 1 |  | ||||||
| signal_baseline_field_time_mean_norm = signal_baseline_field_time_mean/max(signal_baseline_field_time_mean); |  | ||||||
|  % plot the spectrum |  % plot the spectrum | ||||||
| plot(0.1*params.Field_Vector,signal_baseline_field_time_mean_norm,'LineWidth',2) | plot(0.1*params.Field_Vector,signal_baseline_time_field_mean_norm,'LineWidth',2) | ||||||
| 
 | 
 | ||||||
| xlabel('Magnetic Field / mT') | xlabel('Magnetic Field / mT') | ||||||
| 
 |  | ||||||
| axis('tight') | axis('tight') | ||||||
| box off | box off | ||||||
| return |  | ||||||
| 
 | 
 | ||||||
| % print('TR_EPR_Chichibabin_80K_frozen_solution_570_01' , '-dpng', '-r300') |  | ||||||
| return | return | ||||||
| %% Simulation section. Use the "Run Section" button to avoid running the previous section every time | %% Simulation section. Use the "Run Section" button to avoid running the previous section every time | ||||||
| 
 | 
 | ||||||
| @ -115,13 +134,13 @@ FitOpt.Scaling = 'lsq'; | |||||||
| [bfield,spec] = pepper(Sys,Exp); % perform a simulation with the parameters above | [bfield,spec] = pepper(Sys,Exp); % perform a simulation with the parameters above | ||||||
| spec_norm = spec/max(spec); % normalize the simulation | spec_norm = spec/max(spec); % normalize the simulation | ||||||
| 
 | 
 | ||||||
| figure(2) | figure(3) | ||||||
| set (gcf,'PaperUnits','centimeters') | set (gcf,'PaperUnits','centimeters') | ||||||
| set (gcf,'Position',[-900,100,800,400]) % set the position, size and shape of the plot | set (gcf,'Position',position) % set the position, size and shape of the plot | ||||||
| set (gcf,'InvertHardcopy','off','Color',[1 1 1]) | set (gcf,'InvertHardcopy','off','Color',[1 1 1]) | ||||||
| set(0,'DefaultAxesFontSize', 16,'DefaultAxesLineWidth',1.5) | set(0,'DefaultAxesFontSize', 16,'DefaultAxesLineWidth',1.5) | ||||||
| 
 | 
 | ||||||
| plot(0.1*params.Field_Vector,signal_baseline_field_time_mean_norm,'r', bfield,spec_norm,'b','LineWidth',1); | plot(0.1*params.Field_Vector,signal_baseline_time_field_mean_norm,'r', bfield,spec_norm,'b','LineWidth',1); | ||||||
| axis('tight') | axis('tight') | ||||||
| 
 | 
 | ||||||
| legend('experimental','simulation') | legend('experimental','simulation') | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user