Skip to content
Snippets Groups Projects
Commit c6bd6abf authored by pierre.rousselot_ird.fr's avatar pierre.rousselot_ird.fr
Browse files

Cleaned version

parent 81776aa2
No related branches found
No related tags found
No related merge requests found
function [zbins,zadcp1,offset,x_null]=adcp_surface_fit(zadcp,ea,surface_bins,blen,blnk,nbin);
function [zbins,zadcp1,offset,x_null]=adcp_surface_fit(zadcp,ea,surface_bins,blen,blnk,nbin)
% Bin depth matrix
dpt1 = repmat(zadcp,nbin,1);
dpt1 = repmat(zadcp,nbin,1);
binmat = repmat((1:nbin)',1,length(dpt1));
z = dpt1-(binmat-0.5)*blen-blnk;
z = dpt1-(binmat-0.5)*blen-blnk;
% Loop over time, determine bin of maximum ea in surface bin range and
% do quadratic fit over 2 neighbouring and center bins
easurf=ea(surface_bins,:);
easurf = ea(surface_bins,:);
for ii=1:length(ea)
[eamax,maxind]=max(easurf(:,ii));
[eamax,maxind] = max(easurf(:,ii));
if length(eamax)>1; maxind=maxind(1); end
if length(eamax)>1
maxind = maxind(1);
end
if maxind>1 & eamax>80
if surface_bins(maxind)==nbin;
if maxind>1 && eamax>80
if surface_bins(maxind)==nbin
xtofit(1:2) = easurf(maxind-1:maxind,ii);
xtofit(3) = 0;
xtofit(3) = 0;
else
xtofit = easurf(maxind-1:maxind+1,ii);
xtofit = easurf(maxind-1:maxind+1,ii);
end
for jj=1:3
A(jj,:)=[(surface_bins(maxind)+jj-2)^2, surface_bins(maxind)+jj-2, 1];
A(jj,:) = [(surface_bins(maxind)+jj-2)^2, surface_bins(maxind)+jj-2, 1];
end
coef(:,ii)= A\xtofit;
coef(:,ii) = A\xtofit;
else
coef(:,ii)=NaN;
coef(:,ii) = NaN;
end
end
% Find maximum of quadratic fit ax^2+bx+c: 2ax+b=0
x_null = -coef(2,:)./2./coef(1,:);
%offset=-round(nmedian((x_null-0.5)*blen+blnk)-nmedian(zadcp));
offset=-round(((x_null)*blen+blnk)-(zadcp)); %% P. Rousselot - offset over time
%% Calculate offset
offset = round(((x_null-0.5)*blen+blnk)-(zadcp));
disp('-------------------------------');
disp(['Depth offset is ' num2str(nanmean(offset)) ' m']);
disp(['Depth offset is ' num2str(round(nanmean(offset))) ' m']);
disp('-------------------------------');
% offset over time cleaned (median filter)
[offset_clean,~] = clean_median(offset,20,2.8,[0.5 5],2,NaN);
lin_offset = linspace(1,length(offset),length(offset));
offset = interp1(lin_offset(~isnan(offset_clean)),...
offset_clean(~isnan(offset_clean)),lin_offset,'linear','extrap');
% offset median
%offset = nanmedian(offset);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot histogram of differences
dz=((x_null)*blen+blnk)-zadcp;
count=[-100:1:100];
ncount=hist(-dz,count);
%% Plot histogram of differences
dz = ((x_null-0.5)*blen+blnk)-zadcp;
count = [-100:1:100];
ncount = hist(-dz,count);
figure(1);
bar(count,ncount);
grid on
......@@ -53,38 +64,33 @@ function [zbins,zadcp1,offset,x_null]=adcp_surface_fit(zadcp,ea,surface_bins,ble
plot(-zadcp,'b');
grid on
hold on;
plot(-(x_null)*blen+blnk,'r');
plot(-((x_null-0.5)*blen+blnk),'r');
legend('Original','Reconstructed from surface reflection');
% if abs(offset)>15
% reply = input('Do you want to overwrite offset? 1/0 [0]:');
% if isempty(reply)
% reply = 0;
% end
%
% if reply==1
% offset=input('Enter new offset:');
% end
% end
if abs(offset)>15
reply = input('Do you want to overwrite offset? 1/0 [0]:');
if isempty(reply)
reply = 0;
end
if reply==1
offset=input('Enter new offset:');
end
end
disp(['Offset of ' num2str(offset) ' m is applied']);
offset = 19;
% Apply offset to get correct bin depth and instrument depth:
zbins=z-offset;
zadcp1=zadcp-offset;
%% Apply offset to get correct bin depth and instrument depth:
zbins = z+offset;
zadcp1 = zadcp+offset;
figure(2);
plot(-zadcp1,'y');
text(300, max(zadcp),['Offset applied: ' num2str(offset) ' m']);
%,'fonts',12,'fontw','bold','backgroundc','w');
legend('Original','Reconstructed from surface reflection','Offset applied');
legend('Original','Reconstructed from surface reflection','Offset applied');
%print -dpng surface_fit;
figure(3);
pcolor([1:length(x_null)],-zbins,ea); shading flat;
title('Amplitude'); colorbar; ylabel('Depth [m]');xlabel('Time index');
%print -dpng surface_ea;
end
\ No newline at end of file
......@@ -56,7 +56,7 @@
% Copyright 1988-2011 The MathWorks, Inc.
% $Revision: 1.7.4.10 $ $Date: 2012/12/25 21:34:47 $
error(nargchk(3,3,nargin,'struct'))
narginchk(3,3)
% Only double precision is supported
if ~isa(b,'double') || ~isa(a,'double') || ~isa(x,'double')
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment