%
%   signal_stats_PSD.m  ver 1.0    December 3, 2012
%
function[psd_new]=signal_stats_PSD(m,THF,mina,maxa,iflag)
%
    psd_new=THF;
    [~,mina,maxa]=coordinates_ss(m,THF,mina,maxa,iflag);
    io=0;
    while(io < 3 )
        disp(' ');
        disp(' Additional Options         ');
        disp(' 1=add dB margin            ');
        disp(' 2=convert to octave format ');
        disp(' 3=scale to GRMS            ');
        disp(' 4=exit                     ');   
        io=input(' ');
        disp(' ')
        if(io==1)
            dB=input(' Input Margin (dB) ');
            scale=10^(dB/10);
            THF(:,2)=THF(:,2)*scale;
            [~,mina,maxa]=coordinates_ss(m,THF,mina,maxa,iflag);       
        end   
        if(io==2)
            disp(' ');
            disp(' Enter output format ')
            disp(' 1= octave  2= 1/3 octave  3= 1/6 octave  4= 1/12 octave ');
            ioct=input(' ');
%
            disp(' ');
            disp(' set octave... ');
% 
            if(ioct==1)     % octave
                oex=1./2.;
            end
            if(ioct==2)     % one-third octave
                oex=1./6.;
            end
            if(ioct==3)     % one-sixth octave
                oex=1./12.;
            end
            if(ioct==4)     % one-twelfth octave
                oex=1./24.;
            end
%                
            [fc,imax]=octaves(ioct);            
            clear THX;
            [THX]=PSD_octave(THF,fc,imax,oex);
            clear THF;
            THF=THX;
            [~,mina,maxa]=coordinates_ss(m,THF,mina,maxa,iflag);    
        end
        if(io==3)
            disp(' ');
            GRMS=input(' Input GRMS ');
            [~,mina,maxa,THF]=coordinates_ss_scale(m,THF,mina,maxa,iflag,GRMS);       
        end
%
        if(io~=4)
            psd_new=THF;
            disp(' ');
            disp(' Matlab output array = psd_new ');
        end
%
    end