Hi, I'm trying to take accelerometer data I recorded with an Adafruit BNO05 IMU and generate two graphs: one that plots acc vs. time and one that plots acc vs. freq. I'm attaching a data file for reference. Our current code doesn't seem to be working quite right for the acc vs. freq part. I'm also attaching that code. Any suggestions for how we can fix the code?
%Reads raw data from the xlsfile.
function [acceleration,time] = TremorReader(filename)%Open the Excel file and extract information
[num text raw ] = xlsread(filename) ;[r,c] = size(num) ;%Delete unecessary information
num(2:2:end,:) = [] ;num(:,2) = [] ;num(:,5) = [] ;%Extract time
time = num(:,1) ;time = time - time(1) ;%convert from millisecond to seconds
timesec = time./1000 ;%replace in data again
num(:,1) = timesec ;%Extract all axes
ax = num(:,2) ;ay = num(:,3) ;az = num(:,4) ;%Compute the cumulative/magnitude vector
acc = sqrt(ax.^2 + ay.^2 + az.^2); %possibly in G's
acc_cmpersec = acc.*980; %converts to cm/s^2
hold onsubplot(1,2,2);plot(timesec,acc);dt = .103;%time between samples????
N1 = length(acc); N = 2^nextpow2(N1); if N > N1 acc(N1+1:N) = 0; % pad array with 0's
end df = 1 / (N*dt); % frequency increment
Nyq = 1 / (2*dt); % Nyquist frequency
freq = fftshift(fft(acc));freq = sort(freq);mag_freq = sqrt((real(freq).^2)+(imag(freq).^2)); %magnitude of the frequency, combines the real and imaginary parts
%M = abs(freq), this is the same as mag_freq, just a different method
phase_freq = angle(freq);subplot(1,2,1);plot(mag_freq, acc);%hold on
% used plot(freq,acc,'r') before (other night)
%hold off
RMSacc = norm(acc_cmpersec)./sqrt(length(acc_cmpersec)); %root mean square to combine the acceleration vectors into one value for the amplitude and score
Dom_freq = max(mag_freq); %taking the dominant frequency
T = RMSacc./((2.*pi.*Dom_freq ).^2); %translational displacement
amplitude = abs((T)./(sin(2.*pi*Dom_freq .*4)));%if amplitude==0;
% score=0;
% elseif amplitude<1;
% score=1;
% elseif amplitude>=1 & amplitude<3;
% score=2;
% elseif amplitude>=3 & amplitude<10;
% score=3;
% else
% score=4;
% end
%disp(score); %These will be used to find TP,TN,FP, and NP
end
Best Answer