123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <!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_waves</title>
- <meta name="keywords" content="plx_waves">
- <meta name="description" content="plx_waves(filename, channel, unit): Read waveform 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_waves
- </h1>
- <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../../up.png"></a></h2>
- <div class="box"><strong>plx_waves(filename, channel, unit): Read waveform 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 [n, npw, ts, wave] = plx_waves(filename, ch, u) </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_waves(filename, channel, unit): Read waveform data from a .plx file
- [n, npw, ts, wave] = plx_waves(filename, channel, unit)
- INPUT:
- filename - if empty string, will use File Open dialog
- channel - 1-based channel number
- unit - unit number (0- invalid, 1-4 valid)
- OUTPUT:
- n - number of waveforms
- npw - number of points in each waveform
- ts - array of timestamps (in seconds)
- wave - array of waveforms [npw, n], 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 [n, npw, ts, wave] = plx_waves(filename, ch, u)</a>
- 0002 <span class="comment">% plx_waves(filename, channel, unit): Read waveform data from a .plx file</span>
- 0003 <span class="comment">%</span>
- 0004 <span class="comment">% [n, npw, ts, wave] = plx_waves(filename, channel, unit)</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 - 1-based channel number</span>
- 0009 <span class="comment">% unit - unit number (0- invalid, 1-4 valid)</span>
- 0010 <span class="comment">% OUTPUT:</span>
- 0011 <span class="comment">% n - number of waveforms</span>
- 0012 <span class="comment">% npw - number of points in each waveform</span>
- 0013 <span class="comment">% ts - array of timestamps (in seconds)</span>
- 0014 <span class="comment">% wave - array of waveforms [npw, n], raw a/d values</span>
- 0015
- 0016 <span class="keyword">if</span>(nargin ~= 3)
- 0017 disp(<span class="string">'3 input arguments are required'</span>)
- 0018 <span class="keyword">return</span>
- 0019 <span class="keyword">end</span>
- 0020
- 0021 n = 0;
- 0022 npw = 0;
- 0023 ts = 0;
- 0024 wave = 0;
- 0025
- 0026 <span class="keyword">if</span>(isempty(filename))
- 0027 [fname, pathname] = uigetfile(<span class="string">'*.plx'</span>, <span class="string">'Select a plx file'</span>);
- 0028 filename = strcat(pathname, fname);
- 0029 <span class="keyword">end</span>
- 0030
- 0031 fid = fopen(filename, <span class="string">'r'</span>);
- 0032 <span class="keyword">if</span>(fid == -1)
- 0033 disp(<span class="string">'cannot open file'</span>);
- 0034 <span class="keyword">return</span>
- 0035 <span class="keyword">end</span>
- 0036
- 0037 disp(strcat(<span class="string">'file = '</span>, filename));
- 0038
- 0039 <span class="comment">% read file header</span>
- 0040 header = fread(fid, 64, <span class="string">'int32'</span>);
- 0041 freq = header(35); <span class="comment">% frequency</span>
- 0042 ndsp = header(36); <span class="comment">% number of dsp channels</span>
- 0043 nevents = header(37); <span class="comment">% number of external events</span>
- 0044 nslow = header(38); <span class="comment">% number of slow channels</span>
- 0045 npw = header(39); <span class="comment">% number of points in wave</span>
- 0046 npr = header(40); <span class="comment">% number of points before threshold</span>
- 0047 tscounts = fread(fid, [5, 130], <span class="string">'int32'</span>);
- 0048 wfcounts = fread(fid, [5, 130], <span class="string">'int32'</span>);
- 0049 evcounts = fread(fid, [1, 512], <span class="string">'int32'</span>);
- 0050
- 0051 <span class="comment">% skip variable headers</span>
- 0052 fseek(fid, 1020*ndsp + 296*nevents + 296*nslow, <span class="string">'cof'</span>);
- 0053
- 0054 record = 0;
- 0055 wave = zeros(npw, 1);
- 0056 wf = zeros(npw, 1);
- 0057
- 0058 <span class="comment">% read data records</span>
- 0059 <span class="keyword">while</span> feof(fid) == 0
- 0060 type = fread(fid, 1, <span class="string">'int16'</span>);
- 0061 upperbyte = fread(fid, 1, <span class="string">'int16'</span>);
- 0062 timestamp = fread(fid, 1, <span class="string">'int32'</span>);
- 0063 channel = fread(fid, 1, <span class="string">'int16'</span>);
- 0064 unit = fread(fid, 1, <span class="string">'int16'</span>);
- 0065 nwf = fread(fid, 1, <span class="string">'int16'</span>);
- 0066 nwords = fread(fid, 1, <span class="string">'int16'</span>);
- 0067 toread = nwords;
- 0068 <span class="keyword">if</span> toread > 0
- 0069 wf = fread(fid, [toread, 1], <span class="string">'int16'</span>);
- 0070 <span class="keyword">end</span>
- 0071 <span class="keyword">if</span> toread > 0
- 0072 <span class="keyword">if</span> type == 1
- 0073 <span class="keyword">if</span> channel == ch
- 0074 <span class="keyword">if</span> unit == u
- 0075 n = n + 1;
- 0076 ts(n) = timestamp/freq;
- 0077 wave(:, n) = wf;
- 0078 <span class="keyword">end</span>
- 0079 <span class="keyword">end</span>
- 0080 <span class="keyword">end</span>
- 0081 <span class="keyword">end</span>
- 0082
- 0083 record = record + 1;
- 0084 <span class="keyword">if</span> feof(fid) == 1
- 0085 <span class="keyword">break</span>
- 0086 <span class="keyword">end</span>
- 0087
- 0088 <span class="keyword">end</span>
- 0089 disp(strcat(<span class="string">'number of waveforms = '</span>, num2str(n)));
- 0090
- 0091 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>
|