1function Q=arspectrum(s,arg2,arg3,impedance)
2% Spectral analysis using autoregressive method.
3%
4%  X = arspectrum(s,Fs,PhysDim)
5%       s  	signal data
6%       Fs      Sampling Rate
7%       PhysDim   physical units of s
8%
9%  X = arspectrum(filename)
10%  X = arspectrum(filename,CHAN)
11%       filename must be a signal format known by BIOSIG
12%
13%  Result can be displayed with PLOTA(Q)
14%
15%  see also: SLOAD, PLOTA, TSA/LATTICE, TSA/DURLEV
16
17%	$Id$
18%	Copyright (C) 2005,2009,2011 by Alois Schloegl <alois.schloegl@gmail.com>
19%    	This is part of the BIOSIG-toolbox http://biosig.sf.net/
20
21% This program is free software; you can redistribute it and/or
22% modify it under the terms of the GNU General Public License
23% as published by the Free Software Foundation; either version 2
24% of the  License, or (at your option) any later version.
25%
26% This program is distributed in the hope that it will be useful,
27% but WITHOUT ANY WARRANTY; without even the implied warranty of
28% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29% GNU General Public License for more details.
30%
31% You should have received a copy of the GNU General Public License
32% along with this program; if not, write to the Free Software
33% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
34
35
36Mode='log';
37
38if ischar(s),
39        if nargin==2,
40                CHAN = arg2;
41                %[s,H]=sload(s,CHAN,'OVERFLOWDETECTION:OFF');
42                [s,H]=sload(s,CHAN);
43                Q = H;
44                Q.Label = H.Label(CHAN,:);
45                Q.PhysDim = H.PhysDim(CHAN,:);
46                Q.PhysDimCode = H.PhysDimCode(CHAN);
47        else
48                %[s,H]=sload(s,0,'OVERFLOWDETECTION:OFF');
49                [s,H]=sload(s,0);
50                Q = H;
51        end;
52        Fs = H.SampleRate;
53elseif isnumeric(s)
54        H.NS = size(s,2);
55        Q.SampleRate = arg2;
56        Q.PhysDim = arg3;
57        Q.PhysDimCode = physicalunits(Q.PhysDim);
58        Q.Label = [repmat('#',H.NS,1),int2str([1:H.NS]')];
59end;
60
61if isnumeric(s)
62	try
63	        h = histo3(s);
64        	q = hist2res(h);
65		Q.HISTO = h;
66        	Q.stats = hist2res(h);
67	        Q.MEAN = q.MEAN;
68	        Q.RMS = q.RMS;
69	        Q.STD = q.STD;
70	        if isempty(q.QUANT)
71	                Q.QUANT = full(diag(H.Calib(H.InChanSelect+1,:)));
72	        else
73	                Q.QUANT = q.QUANT;
74	        end;
75        catch
76		Q = y2res(s);
77	end
78        Q.ENTROPY = q.ENTROPY;
79	[Q.AR,Q.RC,Q.PE]  = lattice(center(s)',50);
80	%[Q.AR,Q.RC,Q.PE] = lattice(center(s)',500);
81	%[Q.AR,Q.RC,Q.PE] = durlev(acovf(center(s)',50));
82        Q.datatype   = 'spectrum';
83	%[Q.VAR,Q.VRC,Q.VPE] = mvar(center(s),50);
84end;
85
86