function lidar_proc=hard_target(lidar)
%create laser pulse shape Note:10ns time division for 3m range gate seperation
dt=(lidar.ranges(2) - lidar.ranges(1)) / .3;
t=[-150:dt:150];
sig=180/2/sqrt(2);
nearly=ceil(72/(lidar.ranges(2) - lidar.ranges(1)));
R=exp(-(t/sig).^2); % gaussian temporal shape with full width of 180ns at 1/e^2
[na,nr]=size(lidar.SNR);
SNR=lidar.SNR;
RWS=lidar.RWS;
Beta=lidar.Beta;
lidar_proc=lidar;
lidar_proc.hard.xh=[];
lidar_proc.hard.yh=[];
lidar_proc.hard.zh=[];
lidar_proc.hard.lath=[];
lidar_proc.hard.lonh=[];
lidar_proc.hard.hh=[];


for ja=1:na
    ihard=1;
    P=lidar.SNR(ja,:);
    for j=1:20
%         B=imfilter(P,R,'replicate','conv');
%         BB=imfilter(P./B,R,'replicate','conv');
         B=ConvolutionDft( P,R,'Same' );
         BB=ConvolutionDft(P./B,R,'Same');

        pp=P.*BB;
        P=pp;
    end
    [locs pks]=peakseek(P,10,10);
    if ~isempty(locs)
        % first look at meanRWS in small window
        minp=locs(1)-lidar.gatelengthinpts/2;
        if minp<1
            minp=1;
        end
        maxp=locs(1)+lidar.gatelengthinpts/2;
        if maxp>nr
            maxp=nr;
        end
        rwsmean=mean(lidar.RWS(ja,[minp:maxp]));

        % fix window for NaN'ing RWS around buildings (extended to end of
        % range)
        minp=locs(1)-nearly;
        if minp<1
            minp=1;
        end

        if abs(rwsmean)<.25
            lidar_proc.hard.xh(ja,ihard)=lidar.xd(ja,locs(1));
            lidar_proc.hard.yh(ja,ihard)=lidar.yd(ja,locs(1));
            lidar_proc.hard.zh(ja,ihard)=lidar.zd(ja,locs(1));
            lidar_proc.hard.lath(ja,ihard)=lidar.lat(ja,locs(1));
            lidar_proc.hard.lonh(ja,ihard)=lidar.lon(ja,locs(1));
            lidar_proc.hard.hh(ja,ihard)=lidar.h(ja,locs(1));
            
            ihard=ihard+1;

            SNR(ja,minp:nr)=NaN;
            RWS(ja,minp:nr)=NaN;
            Beta(ja,minp:nr)=NaN;
        end

    else %check for cloud deck
        
        windowSize=20;  %window size for smoothing filter
        S=filter(ones(1,windowSize)/windowSize,1,lidar.SNR(ja,:));
        P=autofindpeaks(1:length(lidar.ranges),S);
        PP=autofindpeaks(lidar.ranges,S);

        if ~isempty(P)
            [np,l]=size(P);
            istart=1;
            Sav(istart)=mean(S(1:floor(P(1,2)-P(1,4)/2)));
            for jp=1:np-1
                Sav(istart+jp)=mean(S(floor(P(jp,2)+P(jp,4)/2):floor(P(jp+1,2)-P(jp+1,4)/2)));
                istart+1;
            end
            Sav(istart)=mean(S(floor(P(np,2)+P(np,4)/2):end));
            iii=find(Sav<1.008);
            if ~isempty(iii)
                it=min(iii);
                if it==1
                    SNR(ja,:)=NaN;
                    RWS(ja,:)=NaN;
                    Beta(ja,:)=NaN;
                else
                    SNR(ja,floor(P(it-1,2)+P(it-1,4)/2):end)=NaN;
                    RWS(ja,floor(P(it-1,2)+P(it-1,4)/2):end)=NaN;
                    Beta(ja,floor(P(it-1,2)+P(it-1,4)/2):end)=NaN;
                    cloud(ja).base=PP(it-1,2);
                    cloud(ja).width=PP(it-1,4);
                end
            else
                cloud(ja).base=[];
                cloud(ja).width=[];
            end
        else
            iii=find(SNR(ja,:)<1.008)
            SNR(ja,iii)=NaN;
            RWS(ja,iii)=NaN;
            Beta(ja,iii)=NaN;
            cloud(ja).base=[];
            cloud(ja).width=[];
        end
                    
    end


end
ind=find(SNR<1.008);
SNR(ind)=NaN;
RWS(ind)=NaN;
Beta(ind)=NaN;
lidar_proc.SNR_filt=SNR;
lidar_proc.RWS_filt=RWS;
lidar_proc.Beta_filt=Beta;
lidar_proc.cloud=cloud;

return