MATLAB Answers

Amit
0

Precision Issue in adding very small fractions of seconds to datenum

Asked by Amit
on 6 May 2014
Latest activity Commented on by Amit
on 6 May 2014
Hello All:
I am trying to plot a .wav file audio signature with 'true time of recording' on the x-axis. My ideas was to use datenum, and the datetick to achieve this. But I ran into problems pretty early.
The file is coded at 14kHz, and is exactly 1 minute long. So audioread gives me 14000*60=840000 points. So the time 'relative to the wav file' runs from t=0 to t=60 seconds in steps of 1/14000 second.
I am then trying to use datenum to add 'true' time to the above. The actual time of recording is 05-March-2013 14:00:00 hrs. For simplicity, lets say it was 05-March-2013 00:00:00 hrs.
05-March-2013 00:00:00 is 735298. Call it 'a'. 1 second on top of this is 1/86400. The fraction of second I am dealing with is 1/14000. So fraction in 'datenum' terms is 1/14000/86400. Call it 'b'.
If I add 1/14000th of a second to the date, I already have 735298.0000000008267195767195768 which runs out of precision.
What can I do?
My ultimate aim is to achieve the audio signature of 'y' axis and 'actual date & time' on x-axis.
Thanks all for your attention. Any help will be highly appreciated.

  5 Comments

This is my code -
load FileNameList.mat;
%starting plot
format compact; hold off; figure; plot(0); hold on; set(gcf,'units','normalized','position',[0,0.82,1,0.2]);
t_end=0; t_unit=180; %3 hours at a time recommended on Amit's 4GB RAM computer
for i=1:1:length(FListM1)
[yM1Temp fsM1Temp]=audioread(FListM1(i,:));
t=[t_end:1/fsM1Temp:t_end+((length(yM1Temp)-1)/fsM1Temp)]';
t_end=t(end);
%fsM1Temp is 14000. length(yM1Temp)=14000*60=840000
%plot(VDR_start_time + (t/86400), yM1Temp); datetick('x', 'HH:MM'); hold on; %%%%%%%%%%leads to precision issues
%%%THIS IS WHAT I WANT
plot(t/60, yM1Temp); hold on; %temporary measure leading to relative time in minutes
%%INSTEAD THIS IS WHAT I HAVE TO LIVE WITH AT THE MOMENT
i %to track progress on screen
if (mod(i,t_unit))==0
title('Full Audio Signature Channel 1'); xlabel('Time in minutes'); axis tight; grid on; grid minor; %datetick('x', 'HH:MM');
screen2jpeg(strcat('FullAudioSignature_',num2str((i-t_unit)/60), '-', num2str(i/60), 'hrs.jpg'));
hold off;
end
end
if mod(i, t_unit)~=0
title('Full Audio Signature Channel 1'); xlabel('Time in minutes'); axis tight; grid on; grid minor; %datetick('x', 'HH:MM');
screen2jpeg(strcat('FullAudioSignature_',num2str(uint8((i-t_unit)/60)), 'hrs+.jpg'));
end
hold off; close; clear t; clear yM1Temp; clear i; clear fsM1Temp;
Can you work with datevec formats instead?
Hello James:
Won't that amount to the same thing? Unless you mean that I somehow forget about the date-month-year and focus only on time of the day, as that's what I want to be shown on the xlabels.
Good idea to try. Though I am currently not sure how to do it. Thanks indeed. If you have some quick illustration for me, that'll be amazing.

Sign in to comment.

0 Answers