

h=nanmedian(htt);
h=cldtop(:,2);
ht=nanmedian(cldtop(:,2));
kk=find(ht<h);
topi=max(kk);
j=1;
dbb=-40:0;
jj=find(Ref(topi-2,:)<-20);
for dk=5:25;
    jj=find(Ref(topi-dk,:)>-35);

%[P,S] = polyfit(Ref(topi-dk,jj),DV(topi-dk,jj)-DV(topi-2,jj),2);
[P,S] = polyfit(Ref(topi-dk,jj),DV(topi-dk,jj),2);

yg=polyval(P,dbb);
ygg(j,:)=yg;
Pi(j,:)=P;
j=j+1;
end
figure;plot(dbb,mean(ygg),dbb,polyval(mean(Pi),dbb),'o');

j=1;
for dk=1:25;
vel = polyval(mean(Pi),Ref(topi-dk,:));
velk(j,:)=vel;
j=j+1;
end


vc=median(DV(topi-24:topi,:)-velk);

dk=25;
[P,S] = polyfit(mean(Ref(topi-25:topi-10,:)),mean(DV(topi-25:topi-10,:))-vc,2);
figure;plot(dbb,mean(ygg),dbb,polyval(mean(Pi),dbb),'o',dbb,polyval(P,dbb),'--');

j=1;
for dk=1:25;
vel = polyval(P,Ref(topi-dk,:));
velk2(j,:)=vel;
j=j+1;
end

dk=5;vc2=mean(DV(topi-25:topi-dk,:)-velk2(dk:25,:));

wp=[.02];ws= [.01];rp=3;rs=15;[n,wmn]=cheb1ord(wp,ws,rp,rs);
[b,a]=cheby1(n,rp,wmn);
vcfL=filter(b,a,vc-mean(vc));%\
vcfH=vc-vcfL-mean(vc);

km=10;figure;ii=find(Ref(topi-km,:)>-35);plot(hh(ii),DV(topi-km,ii)-velk2(km,ii)-vcfH(ii));

figure;plot(hh,vcfL);