%
%  plot_peak_histogram_th.m  ver 1.1  April 15, 2013
%
function[fig_num]=plot_peak_histogram_th(y,amp_label,fig_num)
%
clear np;
clear pp;
clear abs;
clear pa;
%
np=0;
pp=0;
%
%  do not initialize pa with zeros because do not know final size
%
n=length(y);
%
j=1;
%
for i=2:(n-1)
        if( y(i)>=y(i-1) && y(i)>=y(i+1) && y(i)>0 )
            pa(j)=abs(y(i));
            j=j+1;
            pp=pp+1;
        end
        if( y(i)<=y(i-1) && y(i)<=y(i+1)&& y(i)<0 )
            pa(j)=abs(y(i));
            j=j+1;
            np=np+1;
        end
end
%
while(1)
            clear x;
            nbar=input(' Enter the number of bars ');
            xx=max(abs(pa));
            x=linspace(0,xx,nbar);       
            figure(fig_num);
            fig_num=fig_num+1;
            hist(pa,x)
            ylabel(' Counts');
            xlabel('Amplitude');  
            title(amp_label); 
            disp(' Re-plot with different number of bars? ');
            disp(' 1=yes  2=no ');
            irp=input(' ');
            if(irp==2)
                break;
            end
end
