disp(' ')
disp(' full_FFT.m ')
disp(' ver 3.2  October 19, 2012 ')
disp(' by Tom Irvine  Email: tomirvine@aol.com ')
disp(' ')
disp(' This program calculates the one-sided, full amplitude FFT ')
disp(' of a time history ')
disp(' ')
disp(' The time history must be in a two-column matrix format: ')
disp(' Time(sec)  & amplitude ')
disp(' ')
%
close all;
%
clear n;
clear Y;
clear amp;
clear tim;
clear N;
clear df;
clear dt;
clear Mag;
clear full;
clear freq;
clear complex_FFT;
clear THM;
clear mu;
clear mean;
%
fig_num=1;
%
disp(' ')
[tim,amp,dt,sr,tmx,tmi,n,ncontinue]=enter_time_history();
%
N=2^floor(log(n)/log(2));
%
out4 = sprintf(' time history length = %d ',n);
disp(out4)
disp(' ');
out5 = sprintf(' samples used for FFT = %d',N);
disp(out5)
%
if(ncontinue==1)
%
    disp(' ')
    disp(' mean removal?  1=yes 2=no ')
    m_choice = input(' ');
 %   
    disp(' ')
    disp(' Select Window ')
    h_choice = input(' 1=Rectangular 2=Hanning  ');
%
    [freq,full,phase,complex_FFT]=...
                                 full_FFT_core(m_choice,h_choice,amp,N,dt);    
%    
    clear magnitude_FFT;
    magnitude_FFT=[freq full];
%    
    [~,fmax]=find_max(magnitude_FFT);
%
    out5 = sprintf('\n Peak occurs at %10.5g Hz \n',fmax);
    disp(out5)
%
    disp(' Plot the FFT magnitude? ')
    choice = input(' 1=yes 2=no ');
%
    if(choice == 1)
        figure(fig_num);
        fig_num=fig_num+1;
        plot(freq,full)
        xlabel(' Frequency (Hz)');
        ylabel(' Magnitude');
        title(' FFT Magnitude ');
        grid on; 
        zoom on;
    end
    disp(' ')
    disp(' Plot the FFT phase? ')
    choice = input(' 1=yes 2=no ');
%
    if(choice == 1)
        figure(fig_num);    
        fig_num=fig_num+1;        
        plot(freq,phase)
        xlabel(' Frequency (Hz)');
        ylabel(' Phase (deg)'); 
        title(' FFT Phase ');
        grid on;
    end
%
    complex_FFT_b=...
    [complex_FFT(:,1) complex(complex_FFT(:,2),complex_FFT(:,3))]; 
%
    disp(' ');
    disp(' The complex FFT names are:  ');  
    disp('   complex_FFT    (freq real imag)' );
    disp('   complex_FFT_b  (freq complex  )' );
%
    disp(' ');
    disp(' The FFT magnitude name is: magnitude_FFT ' );
%
    disp(' ');
    disp(' Output full FFT Magnitude file to ASCII text? ');
    choice=input(' 1=yes  2=no  ' );
    disp(' ')
%
    if choice == 1 
        disp(' Enter output filename ');
        g_filename = input(' ','s');
%
        fid = fopen(g_filename,'w');
        for j=1:length(freq);
            fprintf(fid,'%12.5e \t %10.4e \n',freq(j),full(j));
        end
        fclose(fid);
    end
%
end