Best method to handle time series HH:MM:SS.FFF

조회 수: 3 (최근 30일)
Erik
Erik 2014년 8월 28일
댓글: Star Strider 2014년 8월 28일
What is the best method to create a time vector for plots and for comparing data when knowing the start time in HH:MM:SS.FFF and the sampling rate? The constant sampling rate/interval is in microseconds, thus several samples would have the same HH:MM:SS.FFF if kept in that format with only three decimal places.
I want to be able to compare data from the same time periods (that may have different start times) for comparisson and plot them showing the HH:MM:SS.FFF on the x axis.
Thanks.

답변 (1개)

Star Strider
Star Strider 2014년 8월 28일
It’s difficult to answer your question because I can’t determine whether your priorities are to keep the time in HH:MM:SS.FFF format or to display all the samples.
One possibility is for you to keep all the original sampling times and simply label your time axis every millisecond. (That would be my approach.) This might require a visit to the realm of handle graphics to set the 'XTick' values to be only where you want them. You will likely need to use the datetick function to label your time axis in any event.
Another possibility is to average them over every millisecond and simply display them every millisecond. (That would not be my approach if I went through the trouble to sample them every microsecond.)
Plotting them with different start times would be relatively easy, since the plot function would take care of that automatically. I don’t see a need to actually label the start times on your time (probably x) axis though, unless that is an important parameter.
  댓글 수: 2
Erik
Erik 2014년 8월 28일
편집: Erik 2014년 8월 28일
The priority is to be able to plot and compare multiple data arrays with the same known sampling rates but have different record lengths and have different start times. I'm curious what is the best method in matlab to align data that do not all start at time zero for a plot.
I have no time vectors and have to create them for each data series knowing the start time, sample rate, and number of samples; I basically try to create the time vector by incrementing the decimal datenum output for the start time by pico (10^-12) parts of a day (e.g. sample rate/sec equiv in days). The other method I have is to figure our the time to array index relationship for each series and pull out same time period from each series to align them on a plot.
Both methods seem cumbersome and was hoping there was an easier way with some of the newer features in Matlab I am not familiar with...
Star Strider
Star Strider 2014년 8월 28일
The plot command will align them with respect to ‘absolute’ times even if they do not start at some arbitrary t=0.
Example:
x1 = linspace(0,2*pi,90);
x2 = linspace(pi/3,7*pi/3,110);
y1 = sin(x1);
y2 = cos(x2);
plot(x1,y1, x2,y2)
grid
They don’t even have to have the same sampling times or sampling intervals, so long as the associated x- and y-vectors have the same lengths.
The only problem is the conversion to datestr or datevec format. You would there be restricted to millisecond resolution. So long as you keep them as datenum serial numbers (parts of which you create), you can do pretty much anything within MATLAB’s floating-point precision.
Aligning them outside the plot, for instance to compare them somehow, would be a bit more challenging, depending on how you want to align them.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by