function [Ax,Ay,ratio] = fft_two_signals(x,y,z) % Performs FFT Analysis of the acceleration signals % and returns their amplitudes Ax, Ay, and ratio. % Inputs are signals x and y, and driving frequency z. %% User Inputs % Sample rate of the Arduino, 1000 corresponds to 115200 Baud Fs = 1000; %% Processing Code % No code here needs to be changed by the user. x=x-mean(x); y=y-mean(y); T = 1/Fs; L=length(x); X = fft(x); Y = fft(y); f = Fs*(0:(L/2))/L; P2X = abs(X/L); P1X = P2X(1:floor(L/2)+1); P1X(2:end-1) = 2*P1X(2:end-1); P2Y = abs(Y/L); P1Y = P2Y(1:floor(L/2)+1); P1Y(2:end-1) = 2*P1Y(2:end-1); % Refine the range to driving frequency so that the % max function gives the amplitude at the frequency % we are interested in: P1Y=P1Y(round(z/f(2))-25:round(z/f(2))+25); P1X=P1X(round(z/f(2))-25:round(z/f(2))+25); [Ay,I2]= max(P1Y); f2=f(I2); [Ax,I1]= max(P1X); f1=f(I1); ratio = Ay/Ax; % Code used for plotting, visualization figure plot(f(round(z/f(2))-25:round(z/f(2))+25),P1X) xlim([z-5,z+5]) hold on plot(f(round(z/f(2))-25:round(z/f(2))+25),P1Y) % Print out answers fprintf('The amplitude of the base is: %5.4f\n',Ax) fprintf('The amplitude of the mass is: %5.4f\n',Ay) fprintf('The magnification ratio is: %5.4f\n',ratio) end