% Program to Calculate the FFT of a Single Channel of Data % Change Directories cd 'C:\Data' % Load the Recorded Data into Matlab load Model.txt % Read the First Column of the Data File and Store as the Time Array time = Model(:,1); % Read the Second Column of the Data File and Store as an Array of Recorded Data ch1 = Model(:,2); %Remove Linear Offset from Time History by Detrending ch1 = detrend(ch1); % Calculate the Fast Fourier Transform (FFT) of the Data ch1_f = fft(ch1); % Determine the Length of the FFT N = length(ch1_f); %Calculate delta t by Subtracting Point 2 from Point 1 in the Time Array deltat=time(2)-time(1) % Determine the Number of Time Steps in the Data Array n=length(ch1) % Calculate the Frequency Increment of the FFT deltaf=1/n/deltat %Calculate the Nyquist Frequency nyq=1/deltat/2 % Build a Frequency Array f=0:deltaf:nyq-deltaf; % Go From Complex Form, to Determine the Magnitude of the FFT % Convert to a Single-Sided FFT - Ignore All Data from i = N/2+1 Through N in the FFT mag_1 = abs(ch1_f(1:N/2)); % Go From Complex Form, to Determine the Phase Angle of the FFT angl_ch1 = angle(ch1_f(1:N/2)); % Plot the Single-Sided FFT Magnitude Versus Frequency plot (f,mag_1) xlabel('Frequency (Hz)') % X-axis Label ylabel('Fourier Amplitude') % Y-axis Label title('FFT of Channel 1 Acceleration Data') % Plot Title