% Pendulum Model % P10010 MSD % Code compares data from ATOMIC, DE, and RAZOR sensors to derived pendulum % system model via best fit harmonic motion curves. This is a proof of % concept to determine which sensor best adheres to system characteristics. % These curve fit equations are not representative of daily human motion; % integration should be used in that case. This is merely a method of % comparing data easily via curve fit equations. clc clear all format long load ATOMIC load DE load RAZOR %Model Pendulum System Data %Measured values Rdisk = .0254; L = 15*.0254; Thetai = 15*(pi/180); g = 9.812865; %Data Constants AIMU_const = 60; %atomic RIMU_const = 30; %razor DIMU_const = 66; %DE Time1 = 0:.01:3.67; %.01s for ATOMIC Time2 = 0:.1:3.9; %.1s for RAZOR and DE %Calculated Values OmgN = sqrt((2*L*g)/(Rdisk*Rdisk+2*L*L)); %Angular Components (Theory) AngA=(-Thetai*OmgN*OmgN*cos(OmgN*Time1+1))'; %added 1.5- phase shift to match test data AngV=(-Thetai*OmgN*sin(OmgN*Time1+1))'; AngP=(Thetai*cos(OmgN*Time1+1.5))'; %Tangential (X) Components (Theory) TanA=(L*AngA); TanV=(L*AngV.*cos(AngP)); TanV2=(L*AngV); TanP=(L*sin(AngP)); TanP2=(L*AngP); %Read Voltage from Excel Files AXVraw=-ATOMIC(:,2); DEXVraw=-DE(:,3); RXVraw=-RAZOR(:,2); %used when baseline is found- start reading while sensor is at rest, then start pendulum swinging %baselineX = XVraw(1); %baselineY = YVraw(1); %used when data is truncated to fit 'n' complete sinusoidal cycles baselineAX = mean(AXVraw); baselineRX = mean(RXVraw); baselineDEX = mean(DEXVraw); %convert data from voltage to m/s^2 %(actualvoltage-baselinevoltage)*1000*9.81/330 AaX =-9.8*(((AXVraw-baselineAX)*1000)/(AIMU_const)); RaX =-9.8*(((RXVraw-baselineRX)*1000)/(RIMU_const)); DEaX =-9.8*(((DEXVraw-baselineDEX)*1000)/(DIMU_const)); %Plot initial data for comparison figure(1), plot(Time1,TanA,'r',Time1,AaX,'b',Time2,RaX,'o',Time2,DEaX,'p'), title('X Acceleration'), xlabel('Time(seconds)'), ylabel('Acceleration (m/s^2)'), grid ON, legend('Modeled System', 'ATOMIC','Razor','DE','Location','South'); %After using Matlab's Curve Fit Toolbox, best fit lines are yielded: AtomicFIT=5.363*sin(5.068*Time1-0.4432); RazorFIT=8.203*sin(4.894*Time1-0.4747); DEFIT=1.434*sin(4.975*Time1-0.4394); figure(3), plot(Time1,TanA,'r',Time1,AtomicFIT,'b',Time1,RazorFIT,'g',Time1,DEFIT,'k'), title('Curve Fit Comparison, Acceleration');xlabel('Time(seconds)'), ylabel('Acceleration (m/s^2)'), grid ON, legend('Modeled System', 'ATOMIC','Razor','DE'); %Integrate once for Velocity AtomicFITV=-(5.363/5.068)*cos(5.068*Time1-0.4432); RazorFITV=-(8.203/4.894)*cos(4.894*Time1-0.4747); DEFITV=-(1.434/4.975)*cos(4.975*Time1-0.4394); figure(4), plot(Time1,TanV,'r',Time1,AtomicFITV,'b',Time1,RazorFITV,'g',Time1,DEFITV,'k'), title('Curve Fit Comparison, Velocity');xlabel('Time(seconds)'), ylabel('Velocity (m/s)'), grid ON, legend('Modeled System', 'ATOMIC','Razor','DE'); %Integrate once again for Position AtomicFITP=-(5.363/(5.068^2))*sin(5.068*Time1-0.4432); RazorFITP=-(8.203/(4.894^2))*sin(4.894*Time1-0.4747); DEFITP=-(1.434/(4.975^2))*sin(4.975*Time1-0.4394); figure(5), plot(Time1,TanP,'r',Time1,AtomicFITP,'b',Time1,RazorFITP,'g',Time1,DEFITP,'k'), title('Curve Fit Comparison, Position');xlabel('Time(seconds)'), ylabel('Position (m)'), grid ON, legend('Modeled System', 'ATOMIC','Razor','DE'); %Average difference of each sensor's best fit line from model: ADiff=sum(abs(AtomicFIT'-TanA))/368; RDiff=sum(abs(RazorFIT'-TanA))/368; DDiff=sum(abs(DEFIT'-TanA))/368;