MATLAB: Matching data and time with sample number

image processingmathematicssignal processingstatisticstime series

Hi all, i have a data for 24hrs with sampling frequency of fs= 500Hz (so t=1/fs:1/fs:1/fs*length(data)). Now i want to extract the data from a particular time. For example the start time of the data is "11/19/2015 18:00" and i want to find the point in "t" at "11/20/2015 6:34".Can someone please help me with this? I am new to Matlab and not sure how to use datevectors.

Best Answer

Find the elapsed time and convert to number of samples--
>> t0='11/19/2015 18:00';target='11/20/2015 6:34'; % given example times
>> dt=datenum(target,'mm/dd/yyyy HH:MM')-datenum(t0,'mm/dd/yyyy HH:MM') % the time delta
dt =
0.5236
>> nSampTarget=fix(dt*24*3600*500)
nSampTarget =
22619999
>>
So, at approximately the 22,620,000th sample will be the beginning of the time history of interest. The originating timestamp will only allow you to locate a precise time down to somewhere around +/- 1 minute which, at 500 Hz, is a number of samples of +/-500*60 = +/30,000