warning off MATLAB:polyfit:RepeatedPointsOrRescale damper1=Monturn2; % assign displacement data to Matlab vector damper2=LBturn4; Fs=200; % sampling frequency n1=length(damper1); % Data from Pi Toolbox has time and distance x1=damper1(n1+1:200/Fs:end); % Only getting distance data n1=length(x1); t1=[0:1/Fs:(n1-1)/Fs]; % Make a separate time vector n2=length(damper2); x2=damper2(n2+1:200/Fs:end); n2=length(x2); t2=[0:1/Fs:(n2-1)/Fs]; figure(1) % Graph displacements of the two dampers plot(t1,x1,'-b',t2,x2,'-r') xlabel('time [s]') ylabel('displacement [in]') legend('Montreal turn 2 (road)','Long Beach turn 4 (street)') title('Damper Displacement') grid; t1=(0:n1-1)/Fs; % Re-assign time vector p1=abs(fft(x1))*2/(n1); % Absolute value of the FFT divided by N/2 p1=p1-p1(round(n1/2)); % Subtraction to account for voltage offset p1(1)=p1(1)/2; f1=(0:n1-1)*(Fs/n1); % Frequency vector (in Hz) t2=(0:n2-1)/Fs; p2=abs(fft(x2))*2/(n2); p2=p2-p2(round(n2/2)); p2(1)=p2(1)/2; f2=(0:n2-1)*(Fs/n2); [P1,S1]=polyfit(f1(round(n1/13):round(n1/1.5)),p1(round(n1/13):round(n1/1.5)),7); fit1=polyval(P1,f1); % Best fit polynomial to the frequency data [P2,S2]=polyfit(f2(round(n2/13):round(n2/1.5)),p2(round(n2/13):round(n2/1.5)),7); fit2=polyval(P2,f2); figure(2) % Graph the Fourier Transform plot(f1,p1,'-b',f2,p2,'--r') xlabel('Frequency [Hz]') ylabel('Amplitude [in]') legend('Montreal turn 2 (road)','Long Beach turn 4 (street)') title('Frequency Distribution') axis([15 100 0 0.003]) grid; figure(3) plot(f1,fit1,'-b',f2,fit2,'--r') xlabel('Frequency [Hz]') ylabel('Amplitude [in]') legend('Montreal turn 2 (road)','Long Beach turn 4 (street)') title('Frequency Distribution (Best Fit line)') axis([15 100 0 0.003]) grid;