mtspecgramc_slow.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/REC-html40/loose.dtd">
  3. <html>
  4. <head>
  5. <title>Description of mtspecgramc_slow</title>
  6. <meta name="keywords" content="mtspecgramc_slow">
  7. <meta name="description" content="Multi-taper time-frequency spectrum - continuous process">
  8. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  9. <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  10. <meta name="robots" content="index, follow">
  11. <link type="text/css" rel="stylesheet" href="../../m2html.css">
  12. <script type="text/javascript">
  13. if (top.frames.length == 0) { top.location = "../../index.html"; };
  14. </script>
  15. </head>
  16. <body>
  17. <a name="_top"></a>
  18. <!-- ../menu.html chronux_2_10 --><!-- menu.html test -->
  19. <h1>mtspecgramc_slow
  20. </h1>
  21. <h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
  22. <div class="box"><strong>Multi-taper time-frequency spectrum - continuous process</strong></div>
  23. <h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
  24. <div class="box"><strong>function [S,t,f,Serr]=mtspecgramc_slow(data,movingwin,params) </strong></div>
  25. <h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
  26. <div class="fragment"><pre class="comment"> Multi-taper time-frequency spectrum - continuous process
  27. Usage:
  28. [S,t,f,Serr]=mtspecgramc(data,movingwin,params)
  29. Input:
  30. Note units have to be consistent. Thus, if movingwin is in seconds, Fs
  31. has to be in Hz. see chronux.m for more information.
  32. data (in form samples x channels/trials) -- required
  33. movingwin (in the form [window winstep] i.e length of moving
  34. window and step size)
  35. Note that units here have
  36. to be consistent with
  37. units of Fs - required
  38. params: structure with fields tapers, pad, Fs, fpass, err, trialave
  39. - optional
  40. tapers : precalculated tapers from dpss or in the one of the following
  41. forms:
  42. (1) A numeric vector [TW K] where TW is the
  43. time-bandwidth product and K is the number of
  44. tapers to be used (less than or equal to
  45. 2TW-1).
  46. (2) A numeric vector [W T p] where W is the
  47. bandwidth, T is the duration of the data and p
  48. is an integer such that 2TW-p tapers are used. In
  49. this form there is no default i.e. to specify
  50. the bandwidth, you have to specify T and p as
  51. well. Note that the units of W and T have to be
  52. consistent: if W is in Hz, T must be in seconds
  53. and vice versa. Note that these units must also
  54. be consistent with the units of params.Fs: W can
  55. be in Hz if and only if params.Fs is in Hz.
  56. The default is to use form 1 with TW=3 and K=5
  57. Note that T has to be equal to movingwin(1).
  58. pad (padding factor for the FFT) - optional. Defaults to 0.
  59. e.g. For N = 500, if PAD = 0, we pad the FFT
  60. to 512 points; if PAD = 2, we pad the FFT
  61. to 2048 points, etc.
  62. Fs (sampling frequency) - optional. Default 1.
  63. fpass (frequency band to be used in the calculation in the form
  64. [fmin fmax])- optional.
  65. Default all frequencies between 0 and Fs/2
  66. err (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars
  67. [0 p] or 0 - no error bars) - optional. Default 0.
  68. trialave (average over trials/channels when 1, don't average when 0) - optional. Default 0
  69. Output:
  70. S (spectrum in form time x frequency x channels/trials if trialave=0; in the form time x frequency if trialave=1)
  71. t (times)
  72. f (frequencies)
  73. Serr (error bars) only for err(1)&gt;=1</pre></div>
  74. <!-- crossreference -->
  75. <h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
  76. This function calls:
  77. <ul style="list-style-image:url(../../matlabicon.gif)">
  78. <li><a href="../../chronux_2_10/spectral_analysis/continuous/mtspectrumc.html" class="code" title="function [S,f,Serr]=mtspectrumc(data,params)">mtspectrumc</a> Multi-taper spectrum - continuous process</li><li><a href="../../chronux_2_10/spectral_analysis/helper/change_row_to_column.html" class="code" title="function data=change_row_to_column(data)">change_row_to_column</a> Helper routine to transform 1d arrays into column vectors that are needed</li><li><a href="../../chronux_2_10/spectral_analysis/helper/dpsschk.html" class="code" title="function [tapers,eigs]=dpsschk(tapers,N,Fs)">dpsschk</a> Helper function to calculate tapers and, if precalculated tapers are supplied,</li><li><a href="../../chronux_2_10/spectral_analysis/helper/getfgrid.html" class="code" title="function [f,findx]=getfgrid(Fs,nfft,fpass)">getfgrid</a> Helper function that gets the frequency grid associated with a given fft based computation</li><li><a href="../../chronux_2_10/spectral_analysis/helper/getparams.html" class="code" title="function [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params)">getparams</a> Helper function to convert structure params to variables used by the</li></ul>
  79. This function is called by:
  80. <ul style="list-style-image:url(../../matlabicon.gif)">
  81. <li><a href="testspecgram.html" class="code" title="function testspecgram(data)">testspecgram</a> cd 'C:\Documents and Settings\Admin\Desktop\';</li></ul>
  82. <!-- crossreference -->
  83. <h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
  84. <div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [S,t,f,Serr]=mtspecgramc_slow(data,movingwin,params)</a>
  85. 0002 <span class="comment">% Multi-taper time-frequency spectrum - continuous process</span>
  86. 0003 <span class="comment">%</span>
  87. 0004 <span class="comment">% Usage:</span>
  88. 0005 <span class="comment">% [S,t,f,Serr]=mtspecgramc(data,movingwin,params)</span>
  89. 0006 <span class="comment">% Input:</span>
  90. 0007 <span class="comment">% Note units have to be consistent. Thus, if movingwin is in seconds, Fs</span>
  91. 0008 <span class="comment">% has to be in Hz. see chronux.m for more information.</span>
  92. 0009 <span class="comment">% data (in form samples x channels/trials) -- required</span>
  93. 0010 <span class="comment">% movingwin (in the form [window winstep] i.e length of moving</span>
  94. 0011 <span class="comment">% window and step size)</span>
  95. 0012 <span class="comment">% Note that units here have</span>
  96. 0013 <span class="comment">% to be consistent with</span>
  97. 0014 <span class="comment">% units of Fs - required</span>
  98. 0015 <span class="comment">% params: structure with fields tapers, pad, Fs, fpass, err, trialave</span>
  99. 0016 <span class="comment">% - optional</span>
  100. 0017 <span class="comment">% tapers : precalculated tapers from dpss or in the one of the following</span>
  101. 0018 <span class="comment">% forms:</span>
  102. 0019 <span class="comment">% (1) A numeric vector [TW K] where TW is the</span>
  103. 0020 <span class="comment">% time-bandwidth product and K is the number of</span>
  104. 0021 <span class="comment">% tapers to be used (less than or equal to</span>
  105. 0022 <span class="comment">% 2TW-1).</span>
  106. 0023 <span class="comment">% (2) A numeric vector [W T p] where W is the</span>
  107. 0024 <span class="comment">% bandwidth, T is the duration of the data and p</span>
  108. 0025 <span class="comment">% is an integer such that 2TW-p tapers are used. In</span>
  109. 0026 <span class="comment">% this form there is no default i.e. to specify</span>
  110. 0027 <span class="comment">% the bandwidth, you have to specify T and p as</span>
  111. 0028 <span class="comment">% well. Note that the units of W and T have to be</span>
  112. 0029 <span class="comment">% consistent: if W is in Hz, T must be in seconds</span>
  113. 0030 <span class="comment">% and vice versa. Note that these units must also</span>
  114. 0031 <span class="comment">% be consistent with the units of params.Fs: W can</span>
  115. 0032 <span class="comment">% be in Hz if and only if params.Fs is in Hz.</span>
  116. 0033 <span class="comment">% The default is to use form 1 with TW=3 and K=5</span>
  117. 0034 <span class="comment">% Note that T has to be equal to movingwin(1).</span>
  118. 0035 <span class="comment">%</span>
  119. 0036 <span class="comment">% pad (padding factor for the FFT) - optional. Defaults to 0.</span>
  120. 0037 <span class="comment">% e.g. For N = 500, if PAD = 0, we pad the FFT</span>
  121. 0038 <span class="comment">% to 512 points; if PAD = 2, we pad the FFT</span>
  122. 0039 <span class="comment">% to 2048 points, etc.</span>
  123. 0040 <span class="comment">% Fs (sampling frequency) - optional. Default 1.</span>
  124. 0041 <span class="comment">% fpass (frequency band to be used in the calculation in the form</span>
  125. 0042 <span class="comment">% [fmin fmax])- optional.</span>
  126. 0043 <span class="comment">% Default all frequencies between 0 and Fs/2</span>
  127. 0044 <span class="comment">% err (error calculation [1 p] - Theoretical error bars; [2 p] - Jackknife error bars</span>
  128. 0045 <span class="comment">% [0 p] or 0 - no error bars) - optional. Default 0.</span>
  129. 0046 <span class="comment">% trialave (average over trials/channels when 1, don't average when 0) - optional. Default 0</span>
  130. 0047 <span class="comment">% Output:</span>
  131. 0048 <span class="comment">% S (spectrum in form time x frequency x channels/trials if trialave=0; in the form time x frequency if trialave=1)</span>
  132. 0049 <span class="comment">% t (times)</span>
  133. 0050 <span class="comment">% f (frequencies)</span>
  134. 0051 <span class="comment">% Serr (error bars) only for err(1)&gt;=1</span>
  135. 0052
  136. 0053 <span class="keyword">if</span> nargin &lt; 2; error(<span class="string">'Need data and window parameters'</span>); <span class="keyword">end</span>;
  137. 0054 <span class="keyword">if</span> nargin &lt; 3; params=[]; <span class="keyword">end</span>;
  138. 0055
  139. 0056 <span class="keyword">if</span> length(params.tapers)==3 &amp; movingwin(1)~=params.tapers(2);
  140. 0057 error(<span class="string">'Duration of data in params.tapers is inconsistent with movingwin(1), modify params.tapers(2) to proceed'</span>)
  141. 0058 <span class="keyword">end</span>
  142. 0059
  143. 0060 [tapers,pad,Fs,fpass,err,trialave,params]=<a href="../../chronux_2_10/spectral_analysis/helper/getparams.html" class="code" title="function [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params)">getparams</a>(params);
  144. 0061 <span class="keyword">if</span> nargout &gt; 3 &amp;&amp; err(1)==0;
  145. 0062 <span class="comment">% Cannot compute error bars with err(1)=0. change params and run again.</span>
  146. 0063 error(<span class="string">'When Serr is desired, err(1) has to be non-zero.'</span>);
  147. 0064 <span class="keyword">end</span>;
  148. 0065 data=<a href="../../chronux_2_10/spectral_analysis/helper/change_row_to_column.html" class="code" title="function data=change_row_to_column(data)">change_row_to_column</a>(data);
  149. 0066 N=size(data,1);
  150. 0067 Nwin=round(Fs*movingwin(1)); <span class="comment">% number of samples in window</span>
  151. 0068 Nstep=round(movingwin(2)*Fs); <span class="comment">% number of samples to step through</span>
  152. 0069 nfft=2^(nextpow2(Nwin)+pad);
  153. 0070 f=<a href="../../chronux_2_10/spectral_analysis/helper/getfgrid.html" class="code" title="function [f,findx]=getfgrid(Fs,nfft,fpass)">getfgrid</a>(Fs,nfft,fpass);
  154. 0071 params.tapers=<a href="../../chronux_2_10/spectral_analysis/helper/dpsschk.html" class="code" title="function [tapers,eigs]=dpsschk(tapers,N,Fs)">dpsschk</a>(tapers,Nwin,Fs); <span class="comment">% check tapers</span>
  155. 0072
  156. 0073 winstart=1:Nstep:N-Nwin+1;
  157. 0074 nw=length(winstart);
  158. 0075
  159. 0076 <span class="keyword">if</span> trialave
  160. 0077 S = zeros(nw,length(f));
  161. 0078 <span class="keyword">else</span>
  162. 0079 <span class="comment">%S = zeros(nw,length(f),size(data,2));</span>
  163. 0080 <span class="keyword">end</span>
  164. 0081
  165. 0082 <span class="keyword">for</span> n=1:nw;
  166. 0083 indx=winstart(n):winstart(n)+Nwin-1;
  167. 0084 datawin=data(indx,:);
  168. 0085 <span class="keyword">if</span> nargout==4
  169. 0086 [s,f,serr]=<a href="../../chronux_2_10/spectral_analysis/continuous/mtspectrumc.html" class="code" title="function [S,f,Serr]=mtspectrumc(data,params)">mtspectrumc</a>(datawin,params);
  170. 0087 Serr(1,n,:,:)=squeeze(serr(1,:,:));
  171. 0088 Serr(2,n,:,:)=squeeze(serr(2,:,:));
  172. 0089 <span class="keyword">else</span>
  173. 0090 [s,f]=<a href="../../chronux_2_10/spectral_analysis/continuous/mtspectrumc.html" class="code" title="function [S,f,Serr]=mtspectrumc(data,params)">mtspectrumc</a>(datawin,params);
  174. 0091 <span class="keyword">end</span>
  175. 0092 S(n,:,:)=s;
  176. 0093 <span class="keyword">end</span>;
  177. 0094 S=squeeze(S);
  178. 0095 <span class="keyword">if</span> nargout==4;Serr=squeeze(Serr);<span class="keyword">end</span>;
  179. 0096 winmid=winstart+round(Nwin/2);
  180. 0097 t=winmid/Fs;</pre></div>
  181. <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> &copy; 2005</address>
  182. </body>
  183. </html>