<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mike Renfro's Blog &#187; National Instruments</title>
	<atom:link href="http://blogs.cae.tntech.edu/mwr/category/national-instruments/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.cae.tntech.edu/mwr</link>
	<description>A partial repository of whatever comes to mind</description>
	<lastBuildDate>Sat, 31 Oct 2009 23:02:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Converting National Instruments LVM Timestamps to Excel (UPDATED: and Matlab)</title>
		<link>http://blogs.cae.tntech.edu/mwr/2008/04/14/converting-national-instruments-lvm-timestamps-to-excel/</link>
		<comments>http://blogs.cae.tntech.edu/mwr/2008/04/14/converting-national-instruments-lvm-timestamps-to-excel/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 19:41:14 +0000</pubDate>
		<dc:creator>Mike Renfro</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Matlab]]></category>
		<category><![CDATA[National Instruments]]></category>

		<guid isPermaLink="false">http://blogs.cae.tntech.edu/mwr/2008/04/14/converting-national-instruments-lvm-timestamps-to-excel/</guid>
		<description><![CDATA[A few days ago, I had a student looking into what would be required to periodically log some temperatures and pressures from a long-running furnace experiment, so that he doesn&#8217;t have to babysit it and come back every 30 minutes to record his data. We borrowed a National Instruments USB-6008 data acquisition device and downloaded [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, I had a student looking into what would be required to periodically log some temperatures and pressures from a long-running furnace experiment, so that he doesn&#8217;t have to babysit it and come back every 30 minutes to record his data. We borrowed a National Instruments USB-6008 data acquisition device and downloaded NI SignalExpress LE to try some things out.</p>
<p>There wasn&#8217;t much of a problem with actually capturing the data, but the timestamps (in column 1) were odd-looking:</p>
<pre>
LabVIEW Measurement
Writer_Version	0.92
Reader_Version	1
Separator	Tab
Multi_Headings	Yes
X_Columns	One
Time_Pref	Absolute
Date	2008/04/11
Time	16:24:24.354863
***End_of_Header***	

Channels	1
Samples	100
Date	2008/04/11
Time	16:22:45.354864
X_Dimension	Time
X0	0.0000000000000000E+0
Delta_X	1.000000
***End_of_Header***
X_Value	Voltage - Dev1_ai0	Comment
3.29079376535486410E+9	2.64872102540972910E+0
3.29079376635486410E+9	2.64872102540972910E+0
3.29079376735486410E+9	2.64872102540972910E+0
3.29079376835486410E+9	2.64872102540972910E+0
3.29079376935486410E+9	2.65280301912685700E+0
3.29079377035486410E+9	2.65280301912685700E+0
</pre>
<p>There may be a simple way to reformat them inside SignalExpress LE, but it wasn&#8217;t obvious enough when we looked. So here&#8217;s one solution.</p>
<p>The primary difference between National Instruments&#8217; timestamp format and Excel&#8217;s is that NI counts a real-valued number of seconds since January 1, 1904, while Excel counts a real-valued number of days since January 1, 1900. So<br />
the formula (A6/86400)+365*4+2 (convert seconds into days, add four years plus two leap days for 1900 and 1904) will convert NI&#8217;s timestamp value of 3290793765.35486 in cell A6 into an Excel equivalent 39549.8908, or April 11, 2008.</p>
<p>But that&#8217;s not quite enough. The test run we made was at 4:22 PM, and that&#8217;s nowhere near 89% of a full day. Sure enough, putting 39549.8908 into a time format gave us 9:22:45 PM, a full five hours ahead of local time. So there&#8217;s a timezone shift in there, too, and we&#8217;re currently on GMT-5. So strip off the fractional part of the Excel timestamp, offset it by 5/24, and convert it back into a time. The final resulting spreadsheet in tabular form:</p>
<table border="1">
<tr align="center">
<td></td>
<td>A</td>
<td>B</td>
<td>C</td>
<td>D</td>
<td>E</td>
<td>F</td>
<td>G</td>
<td>H</td>
<td>I</td>
<td>J</td>
</tr>
<tr valign="bottom">
<td>5</td>
<td>Original LVM Time</td>
<td>Original LVM Voltage</td>
<td>Convert Secs to Days</td>
<td>Offset by 4 Years (plus 2 leap days)</td>
<td>Final Date</td>
<td>Time (before timezone offset)</td>
<td>Decimal part of Timestamp</td>
<td>Offset for Timezone</td>
<td>Final Time</td>
<td>Final Date/Time</td>
</tr>
<tr>
<td>6</td>
<td>3290793765.35486</td>
<td>2.64872102540972</td>
<td>=A6/86400</td>
<td>=C6+365*4+2</td>
<td>=D6	</td>
<td>=D6</td>
<td>=D6-ROUNDDOWN(D6,0)</td>
<td>=G6+$C$3/24</td>
<td>=H6</td>
<td>=ROUNDDOWN(E6,0)+H6</td>
</tr>
</table>
<p>where cell C3 contained a -5 for our timezone shift from GMT. Columns E, F, I, and J were all in date, time, or date/time format as needed. The result in cell J6 could be cut down to <code>=(A6/86400+365*4+2)+$C$3/24</code> if you&#8217;re in a rush to just convert it.</p>
<p>There may be a math or other error that&#8217;s been compensated for somewhere in here, since I&#8217;m not 100% positive about the 2 leap days. But it does equal out down to the second.</p>
<p><strong>Matlab Addendum:</strong></p>
<p>Matlab has another time format altogether &#8212; it uses a real-valued number of days since the zeroth of January, year 0000, whatever that means:</p>
<pre>
&gt;&gt; datestr(0,0)

ans =

00-Jan-0000 00:00:00

&gt;&gt; datestr(1,0)

ans =

01-Jan-0000 00:00:00

&gt;&gt; datestr(1/86400,0)

ans =

00-Jan-0000 00:00:01
</pre>
<p>Since that goes back far enough to include the current Gregorian calendar, Julian calendar, and possibly even the pre-Julian Roman calendar standards, the conversion equation is a bit more obtuse (in particular, the 97 day offset was found entirely by trial and error):</p>
<pre>
tzoffset=-5;
data=dlmread('test1.csv',',',1,0);
time=data(:,1);
temperature=data(:,2);
time=time/86400+365*1905+97+tzoffset/24;
plot(time,temperature);
datetick('x',0);
grid on;
xlabel('Time');
ylabel('Temperature');
</pre>
<p>resulting in the correct plot for the brief experiment:<br />
<img src='http://blogs.cae.tntech.edu/mwr/files/2008/05/time-temperature.png' alt='Time and Temperature Plot' /></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.cae.tntech.edu/mwr/2008/04/14/converting-national-instruments-lvm-timestamps-to-excel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
