function [time, data] = ReadRedBoardData_v1(serialPort, nSkips, nMax,opFilename) % A simple function to read single channel data from the RedBoard and save as a % time-stamped, two-column array of length nMax as opFilename.mat file % % Input arguments: % serialPort - char specification of the COM port name your RedBoard is using % nSkips - no of received points to skip from saving/analysis etc. % nMax - no of points to save/analyze after skipping nSkips points % opFilename - char string for the file name to be saved in MATLAB binary format (.mat) % % Output arguments: % time - time vector AFTER first nskips points are skipped. % These are time-stamps collected using the toc command at the instant when the data is % received from the serial port. So the output data is NOT sampled at fixed-freuqency. % data - the single channel floting point data acquired from serialPort ('%f') % % % Last Updated: May 13, 2020 % ------------------------------------------------------------------------------------------------------------ % Created By: % Anil Maybhate % Whiting School of Engineering | Johns Hopkins University % 3400 N. Charles St., Baltimore, MD 21218 USA % Email: anil.maybhate@jhu.edu % ------------------------------------------------------------------------------------------------------------ % total No of points read from the redboard N=nSkips+nMax; % initialization of required arrays and variables time = zeros(1,N); data = zeros(1,N); count = 0; % Define the serial object and open communication with the specified COM port. % BaudRate is default (9600). Do NOT change it. s = serial(serialPort); fopen(s); % start stopwatch tic; % loop to read and store incoming data, store current stopwatch time while count