hurricane='isabel';
edges_lambda=0:100:2000;
edges_amplit=0:0.5:6;
n_total=zeros(length(edges_amplit)-1,length(edges_lambda)-1);
rep='wavelength analysis\same_psd_length\unfiltered';
files=dir(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\',rep,'\*.mat']); 
for fil=1:length(files)
    load(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\',rep,'\',files(fil).name]);
    [li,col]=size(lambda(1).z_data);
    
    for i=1:length(lambda)
        p_to_p_pos=[];
        p_to_p_neg=[];
        for j=1:col
            data=lambda(i).z_data(:,j);
            u_NaN=find(~isnan(data));
            if length(u_NaN)<40
                data(u_NaN)=NaN;
            end
            %data_copy=data;
            x=lambda(i).plan_axis2(1,:);
            
            maxi=[];
            mini=[];
            extrema=[];
            amplit=[];
            for k=2:length(data)-1
                if data(k)>data(k+1) & data(k)> data(k-1)
                    maxi=[maxi;x(k)];
                    extrema=[extrema;x(k)];
                    amplit=[amplit;data(k)];
                elseif data(k)<data(k+1) & data(k)< data(k-1)
                    mini=[mini;x(k)];
                    extrema=[extrema;x(k)];
                    amplit=[amplit;data(k)];
                elseif isnan(data(k))==1 | isnan(data(k+1))==1 | isnan(data(k-1))==1
                    maxi=[maxi;NaN];
                    mini=[mini;NaN];
                    extrema=[extrema;NaN];
                    amplit=[amplit;NaN];
                end
                
            end 
            
            diff_amplit=abs(amplit(2:length(amplit))-amplit(1:length(amplit)-1));
            diff_extrema=extrema(2:length(extrema))-extrema(1:length(extrema)-1);
            total_wavelength=2*diff_extrema;
            
            
            n=[]; 
            for lim=1:length(edges_lambda)-1
                u_lim=find(total_wavelength >= edges_lambda(lim) & total_wavelength< edges_lambda(lim+1));
                if length(u_lim)==0
                    n_temp=zeros(length(edges_amplit),1);
                else
                    new_amplit=diff_amplit(u_lim)./ratio(lim,3);
                    n_temp=histc(new_amplit,edges_amplit);
                end
                [n_temp_li,n_temp_col]=size(n_temp);
                if n_temp_col>1
                    n_temp=n_temp';
                end
                n=[n n_temp];
                
            end
            
            n=n(1:length(edges_amplit)-1,:);
            n_total=n_total+n;
        end
    end
end
[n_tot_li,n_tot_col]=size(n_total);
for i=1:n_tot_col
n_percent(:,i)=n_total(:,i)./(sum(n_total(:,i)))*100;
end
x_axis=50:100:2000;
y_axis=0.25:0.5:6;
figure
contourf(x_axis,y_axis,n_percent,25)
shading flat