Use retime() to resample to fractional seconds?

조회 수: 6 (최근 30일)
RM
RM 2018년 2월 15일
답변: Peter Perkins 2018년 2월 17일
Timetables look to be very flexible, but I have data timed to msecs and would like to resample to some higher fractional second rate, such as 0.1 sec. Is there any way to use retime to do that? It appears retime may be limited to 1 second in resolution.

채택된 답변

Steven Lord
Steven Lord 2018년 2월 15일
The smallest value allowed for the newTimeStep input argument describe in the documentation for retime is 'secondly', but you can create a vector of new times with whatever spacing you want and use that as the newTimes input argument for retime.
% Get a starting time
N = datetime('now');
N.Format = 'HH:mm:ss.SSSS';
% Make the timetable spanning 1 second with some arbitrary data to retime
tt = timetable(N+seconds([0; 1; 3; 6; 10]./10), [0; 1; 10; 100; 1000])
% New time vector with spacing (timing?) of 0.1 second
tv = (N:seconds(0.1):N+seconds(1)).'
% retime it
newtt = retime(tt, tv, 'linear')
The value of Var1 for the third entry in tv, N+seconds(0.2), should be 5.5 which is halfway between the value of 1 for N+seconds(0.1) and the value of 10 for N+seconds(0.3).
  댓글 수: 1
RM
RM 2018년 2월 15일
That is exactly what I needed. Thank you.

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

추가 답변 (1개)

Peter Perkins
Peter Perkins 2018년 2월 17일
If you are working in sub-second resolutions, probably best to use the milliseconds function, rather than seconds, for anything involving fractional seconds. By the time you type 0.1, you're into floating point round-off. That may or may not matter; in many cases it won't. And of course this really only pushes the issue down into sub-MILLIsecond resolutions.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by