disp(' ')
disp(' signal_stats.m ')
disp(' ver 3.7   December 3, 2012 ')
disp(' by Tom Irvine  Email: tomirvine@aol.com ')
disp(' ')
disp(' This program gives statistics and plots for ')  
disp(' PSD, SRS and time history functions.')
disp(' ')
%
close all;
%
clear THM;
clear amp;
clear pa;
clear tim;
clear table;
%
clear a2;
clear b2;
clear f2;
clear n2;
clear sz2;
clear THF2;
clear size;
clear length;
clear max;
clear min;
clear diff;
clear disp;
clear abs;
clear temp;
clear y;
clear mat;
%
mina= 1.0e+90;
maxa=-1.0e+90;
%
iflag=0;
%
disp(' Select function: '); 
disp('      1=PSD  ');
disp('      2=SRS  ');
disp('      3=VRS  ');
disp('      4=SPL  ');
disp('      5=time history');
m=input(' ');
disp(' ');
%
if(m<=3)
%
    disp(' Select data input method ')
    disp('  1=data preloaded in matlab ')  
    disp('  2=keyboard entry ');
    disp('  3=external ASCII file ');
    disp('  4=Excel file ');
%
    method=input('');                 
    disp(' ')
%
    clear a;
    clear b;
%
    if(method==1)
        THF = input(' Enter the input filename:  ');
        sz=size(THF);
        f=double(THF(:,1));        
        a=double(THF(:,2));
        n=length(f);       
%
        if(m==2)
            if(sz(2)==2)
                table=[f ; a]';               
            else
                b=double(THF(:,2)); 
                table=[f ; a ; b]';    
            end
        else
            table=[f ; a]';
        end
%        
    end   
    if(method==2)
        n=input(' Input the number of coordinates  ');	
%
        for i=1:n
            if(m==1)
                out = sprintf('\n Enter Frequency %ld ',i);
            else
                out = sprintf('\n Enter Natural Frequency %ld ',i);      
            end
            disp(out);
            f(i)=input('');
%
            out = sprintf('\n Enter amplitude %ld ',i);
            disp(out);
            a(i)=input('');  
        end
        n=length(f);     
        table=[f ; a]';  
        THF=table;
    end
    if(method==3)
        [filename, pathname] = uigetfile('*.*');
        filename = fullfile(pathname, filename);
%      
        fid = fopen(filename,'r');
%        THF = fscanf(fid,'%g %g',[2 inf]);
%        THF=THF';
         THF=load(filename);
        sz=size(THF);
        f=double(THF(:,1));
        a=double(THF(:,2));
        if(sz(2)==3)
            b=double(THF(:,3));
            table=[f , a , b];   
        else
            table=[f , a];
        end
        n=length(f);            
    end 
%
    if(method==4)
        [filename, pathname] = uigetfile('*.*');
        xfile = fullfile(pathname, filename);
%        
        THF = xlsread(xfile);
%        
        f=double(THF(:,1));
        a=double(THF(:,2));  
%       
        n=length(f);
        table=[f ; a]; 
    end   
%
end
if(m==1)  % PSD
    [psd_new]=signal_stats_PSD(m,THF,mina,maxa,iflag);
end
%
if(m==2 || m==3)  % SRS or VRS
    signal_stats_SRS(m,THF,mina,maxa,iflag);
%
end
if(m==4)  % SPL
    [spl_new]=signal_stats_SPL(m,THF,mina,maxa,iflag);
end    
%
if( m==5) % Time History    
%
    signal_stats_TH();
%   
end
%
hold off;