function y = ocean_spec_background_removal (wl,x_l,x_s,N) figure; % plot(wl,x_l); % xlabel ('wavelength [nm]'); % ylabel ('Equivalent counts'); % title ('Long length transmission'); % hold on; % % legend('click the start of the first band'); % [start_1, temp] = ginput(1); % legend('click the end of the first band'); % [end_1, temp] = ginput(1); % hold off % legend('click the start of the second band'); % [start_2, temp] = ginput(1); % legend('click the end of the second band'); % [end_2, temp] = ginput(1); % close; start_1 = 185; end_1 = 210; start_2 = 240; end_2 = 260; index_1 = max(find(round(wl-start_1)==0)); index_2 = min(find(round(wl-end_1)==0)); index_3 = max(find(round(wl-start_2)==0)); index_4 = min(find(round(wl-end_2)==0)); wl_for_fitting = [wl(index_1:index_2);wl(index_3:index_4)]; x_l_for_fitting = [x_l(index_1:index_2);x_l(index_3:index_4)]; x_s_for_fitting = [x_s(index_1:index_2);x_s(index_3:index_4)]; p_l = polyfit(wl_for_fitting,x_l_for_fitting,N); p_s = polyfit(wl_for_fitting,x_s_for_fitting,N); figure; wl_new = wl(index_1:index_4); x_l_new = x_l(index_1:index_4); x_s_new = x_s(index_1:index_4); plot(wl_new,x_l_new,':', wl_new,x_s_new,':'); xlabel ('wavelength [nm]'); ylabel ('Equivalent counts'); hold on; background_l = polyval(p_l,wl_new); background_s = polyval(p_s,wl_new); x_l_new = x_l_new - background_l; x_s_new = x_s_new - background_s; plot(wl_new,x_l_new, wl_new,x_s_new); y = [wl_new,x_l_new,x_s_new]; end