clcclear allclose alls1 = serial('COM26', 'BaudRate', 57600);set(s1,'Terminator',35); fopen(s1);V=[];val='';time=200;count=0;f=0; % ********************************************************************** % Read Serial valuestictt=toc;while(tt<time) val=fscanf(s1); tt=toc; %######################################################################## A=[]; B=[]; C=[]; b=[]; x=[]; j=1; if(j<numel(val)) while(val(j)~='$') a=val(j); b=[b,a]; j=j+1; end A=[A,str2num(b)]; j=j+1; b=[]; while(val(j)~='*') a=val(j); b=[b,a]; j=j+1; end B=[B,str2num(b)]; j=j+1; b=[]; while(val(j)~='#') a=val(j); b=[b,a]; j=j+1; end C=[C,str2num(b)]; i=j; b=[]; f=f+i; end x=[x,round(toc)];if(~(isempty(A)&&isempty(B)&&isempty(C))) subplot(1,2,1) plot(x,A,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',5); hold on % if u want this in different graph remove hold on and add "figure" command before each graph; plot(x,B,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',5); grid on; subplot(1,2,2) plot(x,(B/(A+B))*100,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','m','MarkerSize',5); hold on plot(x,C,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',5); grid on; pause(.01);endendhold offfclose(s1);%Script to load and plot 16-bit accelerometer dataprintf "Running acceleration data analysis script\r\n"clear *%Clear all variablests = (1/1000);%1KHz sampling rate%Path to TXT file with accelerometer samplesaccel_data_path = "accel_data.txt";%Open the acceleration data file as read-only, binary modefile_accel_data = fopen(accel_data_path,"rb");%Read unit16 samples from TXT file into an array%count is # of samples, val is array of values[val,count] = fread(file_accel_data,Inf,"uint16");fclose(file_accel_data);%Generate a time vector from t=0 to the end determined by count and sampling timetmax = (count-1)*ts;t=0:ts:tmax;%Open figure 1figure(1)%Plot accelerometer samplesplot(t,val','1')%Make the plot look prettytitle("Raw Sampled Accelerometer Data")xlabel("Time (s)")ylabel("Accelerometer Data")%Save the plot to diskprint("plots/raw_accel_data.png")%Script to load and plot 16-bit accelerometer dataprintf "Running acceleration data analysis script\r\n"clear *%Clear all variablests = (1/1000);%1KHz sampling rate%Path to TXT file with accelerometer samplesaccel_data_path = "accel_data.txt";%Open the acceleration data file as read-only, binary modefile_accel_data = fopen(accel_data_path,"rb");%Read unit16 samples from TXT file into an array%count is # of samples, val is array of values[val,count] = fread(file_accel_data,Inf,"uint16");fclose(file_accel_data);%Generate a time vector from t=0 to the end determined by count and sampling timetmax = (count-1)*ts;t=0:ts:tmax;%Open figure 1figure(1)%Plot accelerometer samplesplot(t,val','1')%Make the plot look prettytitle("Raw Sampled Accelerometer Data")xlabel("Time (s)")ylabel("Accelerometer Data")%Save the plot to diskprint("plots/raw_accel_data.png")clcclear allclose alls1 = serial('COM26', 'BaudRate', 57600);set(s1,'Terminator',35); fopen(s1);V=[];val='';time=200;count=0;f=0; % ********************************************************************** % Read Serial valuestictt=toc;while(tt<time) val=fscanf(s1); tt=toc; %######################################################################## A=[]; B=[]; C=[]; b=[]; x=[]; j=1; if(j<numel(val)) while(val(j)~='$') a=val(j); b=[b,a]; j=j+1; end A=[A,str2num(b)]; j=j+1; b=[]; while(val(j)~='*') a=val(j); b=[b,a]; j=j+1; end B=[B,str2num(b)]; j=j+1; b=[]; while(val(j)~='#') a=val(j); b=[b,a]; j=j+1; end C=[C,str2num(b)]; i=j; b=[]; f=f+i; end x=[x,round(toc)];if(~(isempty(A)&&isempty(B)&&isempty(C))) subplot(1,2,1) plot(x,A,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',5); hold on % if u want this in different graph remove hold on and add "figure" command before each graph; plot(x,B,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',5); grid on; subplot(1,2,2) plot(x,(B/(A+B))*100,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','m','MarkerSize',5); hold on plot(x,C,'--rs','LineWidth',2,'MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',5); grid on; pause(.01);endendhold offfclose(s1);