Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ t, gxyz, vxyz, dxyz] = process( filename, sampleRate ,xoffset,yoffset,zoffset )
- %Function takes in file name, desired sample rate
- %offsets are for axis parrallel to gravity (offset '-1' if so)
- %returns time array in span of sample rate
- %and arrays of data accn vel and disp data
- %Reads in data from file
- rawData = csvread(filename,5,0);
- %Raw data from file split into columns
- %and adjusted
- tr = rawData(:,1);
- gxr = ((rawData(:,2))-xoffset)*9.81;
- gyr = ((rawData(:,3))-yoffset)*9.81;
- gzr = ((rawData(:,4))-zoffset)*9.81;
- %arrays to be returned
- t = []
- %arrays of data to be combined
- gx = []
- gy = []
- gz = []
- vx = []
- vy = []
- vz = []
- dx = []
- dy = []
- dz = []
- %smoothing values over sample rate
- tmax = round(max(tr),1) %duration of data
- sizeT = size(tr) %size of time array
- dataPoints = tmax/sampleRate %determine number of dataPoints for given sample rate
- span = round(sizeT(1)/dataPoints)%determine how many raw data points to average over
- %interates var i, up to length of data
- %in steps of 'span' previously calculated
- for i = 1:span:size(tr)-span
- t = [t tr(i)]
- %averaging values of acceleration over the span
- %then appending to array
- gxavg = mean(gxr(i:i+span))
- gx = [gx gxavg]
- gyavg = mean(gyr(i:i+span))
- gy = [gy gyavg]
- gzavg = mean(gzr(i:i+span))
- gz = [gz gzavg]
- %ATTEMPT AT INTERGRATING
- %'integrating' with function 'trapz' over accerlation
- %calculating velocity and appending to array
- % vxt = cumtrapz(gxr(i:i+span))
- %
- % vx = [vx vxt]
- %
- % vyt = cumtrapz(gyr(i:i+span))
- %
- % vy = [vy vyt]
- %
- % vzt = cumtrapz(gzr(i:i+span))
- %
- % vz = [vz vzt]
- end
- %SUVAT this bad boy for some velocity
- uxt = 0;
- uyt = 0;
- uzt = 0;
- for i = 1:length(t)
- %calculating velocties for time t
- vxt = uxt + gx(i)*sampleRate
- vyt = uyt + gy(i)*sampleRate
- vzt = uzt + gz(i)*sampleRate
- %calculating displacement for time t
- % dxt = sum(cumtrapz(vx))
- % dyt = sum(cumtrapz(vy))
- % dzt = sum(cumtrapz(vz))
- % dxt = uxt*sampleRate + 0.5*gx(i)*sampleRate*sampleRate
- % dyt = uyt*sampleRate + 0.5*gy(i)*sampleRate*sampleRate
- % dzt = uzt*sampleRate + 0.5*gz(i)*sampleRate*sampleRate
- %appending velocities arrays
- vx = [vx vxt]
- vy = [vy vyt]
- vz = [vz vzt]
- %appending displacement to array
- % dx = [dx dxt]
- % dy = [dy dyt]
- % dz = [dz dzt]
- %setting u as v for next calculation
- uxt = vxt
- uyt = vyt
- uzt = vzt
- end
- %
- % %combining data arrays to structure to be returned
- dx = acc2disp(gx,1/sampleRate)
- dy = acc2disp(gy,1/sampleRate)
- dz = acc2disp(gz,1/sampleRate)
- gxyz = struct('gx',gx, 'gy',gy, 'gz',gz) %accn array
- vxyz = struct('vx',vx, 'vy',vy, 'vz',vz) %vel array
- dxyz = struct('dx',dx, 'dy',dy, 'dz',dz) %disp array
- %
- %
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement