Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.04 KB | None | 0 0
  1. %% Convolution
  2. % % Convolve interpolated spectrum with a gaussian
  3. % params = load(gauss_params); % Load gaussian window
  4. % wl_step = mean(diff(wl_crop)); % wavelength step interval
  5. % std_dev = params.k / wl_step;
  6. % wsize = round(3 * std_dev);
  7. % win = -wsize:wsize;
  8. % gauss_win = params.amp * exp(-(win).^2./(2 * std_dev.^2));
  9. % spec_crop_convolve = conv(spec_crop,gauss_win,'same');
  10. %% Interpolation
  11. % Interpolate spectrum to 100x sampling rate
  12. wl_interp100x = linspace(min(wl_crop),max(wl_crop),numel(wl_crop) * 100);
  13. spec_crop_interp100x = interp1(wl_crop,spec_crop,wl_interp100x);
  14. %% Integration
  15. % Integrate interpolated spectrum over cropped wavelengths
  16. spec_crop_sum = cumsum(spec_crop_interp100x);
  17. %% Find threshold wavelengths
  18. % Find max integrated power for normalization scaling
  19. spec_max = max(spec_crop_sum);
  20. % Normalize spectrum sum to max integrated power
  21. spec_crop_sum_norm = spec_crop_sum / spec_max;
  22. % Initialize wl_thresh
  23. wl_thresh = zeros(size(thresh));
  24. % Iterate through all power thresholds
  25. for ii = 1:length(thresh)
  26.     thresh_ii = thresh(ii); % extract ii-th power threshold
  27.     % The next line extracts the index of the power value closest to the
  28.     % power threshold
  29.     i_p = find(spec_crop_sum_norm > thresh_ii, 1, 'first');
  30.     % This index is used to determine the next wl_thresh
  31.     wl_thresh(ii) = wl_interp100x(i_p);
  32. end
  33. %% Plot results
  34. figure(11)
  35. plot(wl_interp100x,spec_crop_sum_norm)
  36. title('Auto-cropped and noise corrected cumulative sum')
  37. hold on
  38. xlim([min(wl_interp100x),max(wl_interp100x)])
  39. ylim([-max(spec_crop_sum_norm)*0.05,max(spec_crop_sum_norm)*1.05])
  40. str = {};
  41. for jj = 1:length(thresh)
  42.     thresh_jj = thresh(jj);
  43.     wl_thresh_jj = wl_thresh(jj);
  44.     plot([min(wl_interp100x),wl_thresh_jj],[thresh_jj, thresh_jj],'--g')
  45.     plot([wl_thresh_jj,wl_thresh_jj],[-1000, thresh_jj],'--r')
  46.     str{end + 1} = sprintf('%0.0f%% power = %0.2fnm',thresh(jj)*100,wl_thresh_jj);
  47. end
  48. hold off
  49. dim = [0.7 0.5 0.3 0.3];
  50. annotation('textbox',dim,'String',str,'FitBoxToText','on','BackgroundColor','white');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement