123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/REC-html40/loose.dtd">
- <html>
- <head>
- <title>Description of plx_ad</title>
- <meta name="keywords" content="plx_ad">
- <meta name="description" content="plx_ad(filename, channel): Read a/d data from a .plx file">
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="generator" content="m2html © 2005 Guillaume Flandin">
- <meta name="robots" content="index, follow">
- <link type="text/css" rel="stylesheet" href="../../../m2html.css">
- <script type="text/javascript">
- if (top.frames.length == 0) { top.location = "../../../index.html"; };
- </script>
- </head>
- <body>
- <a name="_top"></a>
- <!-- ../../menu.html chronux_2_10 --><!-- ../menu.html dataio --><!-- menu.html ReadingPLXandDDTfilesinMatlab -->
- <h1>plx_ad
- </h1>
- <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
- <div class="box"><strong>plx_ad(filename, channel): Read a/d data from a .plx file</strong></div>
- <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
- <div class="box"><strong>function [adfreq, n, ts, fn, ad] = plx_ad(filename, ch) </strong></div>
- <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
- <div class="fragment"><pre class="comment"> plx_ad(filename, channel): Read a/d data from a .plx file
- [adfreq, n, ts, fn, ad] = plx_ad(filename, ch)
- INPUT:
- filename - if empty string, will use File Open dialog
- channel - 0 - based channel number
- a/d data come in fragments. Each fragment has a timestamp
- and a number of a/d data points. The timestamp corresponds to
- the time of recording of the first a/d value in this fragment.
- All the data values stored in the vector ad.
- OUTPUT:
- n - total number of data points
- ts - array of fragment timestamps (one timestamp for fragment, in seconds)
- fn - number of data points in each fragment
- ad - array of raw a/d values</pre></div>
- <!-- crossreference -->
- <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
- This function calls:
- <ul style="list-style-image:url(../../../matlabicon.gif)">
- </ul>
- This function is called by:
- <ul style="list-style-image:url(../../../matlabicon.gif)">
- </ul>
- <!-- crossreference -->
- <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
- <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [adfreq, n, ts, fn, ad] = plx_ad(filename, ch)</a>
- 0002 <span class="comment">% plx_ad(filename, channel): Read a/d data from a .plx file</span>
- 0003 <span class="comment">%</span>
- 0004 <span class="comment">% [adfreq, n, ts, fn, ad] = plx_ad(filename, ch)</span>
- 0005 <span class="comment">%</span>
- 0006 <span class="comment">% INPUT:</span>
- 0007 <span class="comment">% filename - if empty string, will use File Open dialog</span>
- 0008 <span class="comment">% channel - 0 - based channel number</span>
- 0009 <span class="comment">%</span>
- 0010 <span class="comment">% a/d data come in fragments. Each fragment has a timestamp</span>
- 0011 <span class="comment">% and a number of a/d data points. The timestamp corresponds to</span>
- 0012 <span class="comment">% the time of recording of the first a/d value in this fragment.</span>
- 0013 <span class="comment">% All the data values stored in the vector ad.</span>
- 0014 <span class="comment">% OUTPUT:</span>
- 0015 <span class="comment">% n - total number of data points</span>
- 0016 <span class="comment">% ts - array of fragment timestamps (one timestamp for fragment, in seconds)</span>
- 0017 <span class="comment">% fn - number of data points in each fragment</span>
- 0018 <span class="comment">% ad - array of raw a/d values</span>
- 0019
- 0020 <span class="keyword">if</span>(nargin ~= 2)
- 0021 disp(<span class="string">'2 input arguments are required'</span>)
- 0022 <span class="keyword">return</span>
- 0023 <span class="keyword">end</span>
- 0024
- 0025 i = 0;
- 0026 n = 0;
- 0027 ts = 0;
- 0028 fn = 0;
- 0029 ad = 0;
- 0030
- 0031 <span class="keyword">if</span>(isempty(filename))
- 0032 [fname, pathname] = uigetfile(<span class="string">'*.plx'</span>, <span class="string">'Select a plx file'</span>);
- 0033 filename = strcat(pathname, fname);
- 0034 <span class="keyword">end</span>
- 0035
- 0036 fid = fopen(filename, <span class="string">'r'</span>);
- 0037 <span class="keyword">if</span>(fid == -1)
- 0038 disp(<span class="string">'cannot open file'</span>);
- 0039 <span class="keyword">return</span>
- 0040 <span class="keyword">end</span>
- 0041
- 0042 <span class="comment">% calculate file size</span>
- 0043 fseek(fid, 0, <span class="string">'eof'</span>);
- 0044 fsize = ftell(fid);
- 0045 fseek(fid, 0, <span class="string">'bof'</span>);
- 0046
- 0047
- 0048 disp(strcat(<span class="string">'file = '</span>, filename));
- 0049
- 0050 <span class="comment">% read file header</span>
- 0051 header = fread(fid, 64, <span class="string">'int32'</span>);
- 0052 freq = header(35); <span class="comment">% frequency</span>
- 0053 ndsp = header(36); <span class="comment">% number of dsp channels</span>
- 0054 nevents = header(37); <span class="comment">% number of external events</span>
- 0055 nslow = header(38); <span class="comment">% number of slow channels</span>
- 0056 npw = header(39); <span class="comment">% number of points in wave</span>
- 0057 npr = header(40); <span class="comment">% number of points before threshold</span>
- 0058 tscounts = fread(fid, [5, 130], <span class="string">'int32'</span>);
- 0059 wfcounts = fread(fid, [5, 130], <span class="string">'int32'</span>);
- 0060 evcounts = fread(fid, [1, 512], <span class="string">'int32'</span>);
- 0061
- 0062 <span class="comment">% A/D counts are stored in evcounts (301, 302, etc.)</span>
- 0063 count = 0;
- 0064 <span class="keyword">if</span> evcounts(301+ch) > 0
- 0065 count = evcounts(301+ch);
- 0066 ad = 1:count;
- 0067 <span class="keyword">end</span>
- 0068
- 0069 <span class="comment">% skip DSP and Event headers</span>
- 0070 fseek(fid, 1020*ndsp + 296*nevents, <span class="string">'cof'</span>);
- 0071
- 0072 <span class="comment">% read one A/D header and get the frequency</span>
- 0073 adheader = fread(fid, 74, <span class="string">'int32'</span>);
- 0074 adfreq = adheader(10);
- 0075
- 0076 <span class="comment">% skip all other a/d headers</span>
- 0077 fseek(fid, 296*(nslow-1), <span class="string">'cof'</span>);
- 0078
- 0079 record = 0;
- 0080
- 0081 wf = zeros(1, npw);
- 0082 adpos = 1;
- 0083
- 0084 <span class="keyword">while</span> feof(fid) == 0
- 0085 type = fread(fid, 1, <span class="string">'int16'</span>);
- 0086 upperbyte = fread(fid, 1, <span class="string">'int16'</span>);
- 0087 timestamp = fread(fid, 1, <span class="string">'int32'</span>);
- 0088 channel = fread(fid, 1, <span class="string">'int16'</span>);
- 0089 unit = fread(fid, 1, <span class="string">'int16'</span>);
- 0090 nwf = fread(fid, 1, <span class="string">'int16'</span>);
- 0091 nwords = fread(fid, 1, <span class="string">'int16'</span>);
- 0092 <span class="keyword">if</span> nwords > 0
- 0093 wf = fread(fid, [1 nwords], <span class="string">'int16'</span>);
- 0094 <span class="keyword">end</span>
- 0095 <span class="keyword">if</span> nwords > 0
- 0096 <span class="keyword">if</span> type == 5
- 0097 <span class="keyword">if</span> channel == ch
- 0098 i = i + 1;
- 0099 n = n + nwords;
- 0100 ts(i) = timestamp/freq;
- 0101 fn(i) = nwords;
- 0102 <span class="keyword">if</span> count > 0
- 0103 <span class="keyword">if</span> adpos+nwords-1 <= count
- 0104 ad(adpos:adpos+nwords-1) = wf(1:nwords);
- 0105 adpos = adpos + nwords;
- 0106 <span class="keyword">else</span>
- 0107 <span class="keyword">for</span> i=1:nwords
- 0108 ad(adpos) = wf(i); adpos = adpos + 1;
- 0109 <span class="keyword">end</span>
- 0110 <span class="keyword">end</span>
- 0111 <span class="keyword">else</span>
- 0112 ad = [ad wf(1, 1:nwords)];
- 0113 <span class="keyword">end</span>
- 0114 <span class="keyword">end</span>
- 0115 <span class="keyword">end</span>
- 0116 <span class="keyword">end</span>
- 0117
- 0118 record = record + 1;
- 0119 <span class="keyword">if</span> mod(record, 1000) == 0
- 0120 disp(sprintf(<span class="string">'records %d points %d (%.1f%%)'</span>, record, n, 100*ftell(fid)/fsize));
- 0121 <span class="keyword">end</span>
- 0122
- 0123 <span class="keyword">if</span> feof(fid) == 1
- 0124 <span class="keyword">break</span>
- 0125 <span class="keyword">end</span>
- 0126
- 0127 <span class="keyword">end</span>
- 0128
- 0129 <span class="keyword">if</span> adpos-1 < count
- 0130 ad = ad(1:adpos-1);
- 0131 <span class="keyword">end</span>
- 0132
- 0133 disp(strcat(<span class="string">'number of data points = '</span>, num2str(n)));
- 0134
- 0135 fclose(fid);</pre></div>
- <hr><address>Generated on Fri 12-Aug-2011 11:36:15 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> © 2005</address>
- </body>
- </html>
|