1 function analyzeRaw(device)
3 downsample = 12; % relevant for knowing block size
4 Fs = 512; % need to verify, close
7 s = serial(device,'Baud',115200);
8 set(s,'InputBufferSize',10000);
14 if(i > 5) % must flush buffer
15 dat = [dat; uint8(fread(s))];
23 starts = strfind(char(dat'),char(raw_framing));
24 if(starts) % found raw data, process
25 % warning - could occasionally crash if at very last 3 or less bytes
26 counts = typecast(reshape(dat(bsxfun(@plus,starts,(16:19)')),1,[]),'int32');
27 gaps = find(diff(counts) > 1) % exclude any discontiuous sections
29 starts(1:gaps(end)) = [];
31 blocks = typecast(reshape(dat(bsxfun(@plus,starts(1:end-1),(20:20+downsample*8*2-1)')),1,[]),'int16');
32 blocks = double(reshape(blocks,8,[]));
34 accel_y = 0.012*(blocks(1,:)-2048);
35 accel_x = 0.012*(blocks(3,:)-2048);
36 accel_z = 0.012*(blocks(5,:)-2048);
37 gyro_x = 0.007*(blocks(2,:)-1675);
38 gyro_y = 0.007*(blocks(4,:)-1675);
39 gyro_z = 0.007*(blocks(6,:)-1675);
41 time = (1:length(accel_x))/512;
48 ylim([mean(accel_x)-2*std(accel_x) mean(accel_x)+4*std(accel_x)]);
51 pwelch(accel_x-mean(accel_x),[],[],[],Fs);
56 ylim([mean(accel_y)-2*std(accel_y) mean(accel_y)+4*std(accel_y)]);
59 pwelch(accel_y-mean(accel_y),[],[],[],Fs);
64 ylim([mean(accel_z)-2*std(accel_z) mean(accel_z)+4*std(accel_z)]);
67 pwelch(accel_z-mean(accel_z),[],[],[],Fs);
74 ylim([mean(gyro_x)-2*std(gyro_x) mean(gyro_x)+4*std(gyro_x)]);
77 pwelch(gyro_x-mean(gyro_x),[],[],[],Fs);
82 ylim([mean(gyro_y)-2*std(gyro_y) mean(gyro_y)+4*std(gyro_y)]);
85 pwelch(gyro_y-mean(gyro_y),[],[],[],Fs);
90 ylim([mean(gyro_z)-2*std(gyro_z) mean(gyro_z)+4*std(gyro_z)]);
93 pwelch(gyro_z-mean(gyro_z),[],[],[],Fs);