0001 function [spectrum,f,s] = MTPointSpectrum(times,varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 CheckChronux('mtspectrumpt');
0048
0049
0050 frequency = 20000;
0051 range = [];
0052 show = 'off';
0053 tapers = [3 5];
0054 pad = 0;
0055 err = [1 0.95];
0056
0057
0058 if nargin < 1 | mod(length(varargin),2) ~= 0,
0059 error('Incorrect number of parameters (type ''help <a href="matlab:help MTPointSpectrum">MTPointSpectrum</a>'' for details).');
0060 end
0061
0062
0063 if size(times,2) ~= 1 && size(times,2) ~= 2,
0064 error('Parameter ''times'' is not a vector or a Nx2 matrix (type ''help <a href="matlab:help MTPointSpectrum">MTPointSpectrum</a>'' for details).');
0065 end
0066
0067
0068 v = {};
0069 for i = 1:2:length(varargin),
0070 if ~ischar(varargin{i}),
0071 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help MTPointSpectrum">MTPointSpectrum</a>'' for details).']);
0072 end
0073 switch(lower(varargin{i})),
0074 case 'frequency',
0075 frequency = varargin{i+1};
0076 if ~isdscalar(frequency,'>0'),
0077 error('Incorrect value for property ''frequency'' (type ''help <a href="matlab:help MTPointSpectrum">MTPointSpectrum</a>'' for details).');
0078 end
0079 case 'range',
0080 range = varargin{i+1};
0081 if ~isdvector(range,'#2','<','>=0'),
0082 error('Incorrect value for property ''range'' (type ''help <a href="matlab:help MTPointSpectrum">MTPointSpectrum</a>'' for details).');
0083 end
0084 case 'tapers',
0085 tapers = varargin{i+1};
0086 if ~isivector(tapers,'#2'),
0087 error('Incorrect value for property ''tapers'' (type ''help <a href="matlab:help MTPointSpectrum">MTPointSpectrum</a>'' for details).');
0088 end
0089 case 'pad',
0090 pad = varargin{i+1};
0091 if ~isiscalar(pad,'>-1'),
0092 error('Incorrect value for property ''pad'' (type ''help <a href="matlab:help MTPointSpectrum">MTPointSpectrum</a>'' for details).');
0093 end
0094 case 'show',
0095 show = varargin{i+1};
0096 if ~isastring(show,'on','off'),
0097 error('Incorrect value for property ''show'' (type ''help <a href="matlab:help MTPointSpectrum">MTPointSpectrum</a>'' for details).');
0098 end
0099 otherwise,
0100 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help MTPointSpectrum">MTPointSpectrum</a>'' for details).']);
0101 end
0102 if ~strcmp(varargin{i},'show'), v = {v{:},varargin{i:i+1}}; end
0103 end
0104
0105
0106 [spectrogram,~,f] = MTPointSpectrogram(times,v{:});
0107 spectrogram = spectrogram';
0108 mu = mean(spectrogram);
0109 v = var(spectrogram);
0110
0111
0112 spectrum = mu;
0113 s = sqrt(v);
0114
0115
0116
0117 if strcmp(lower(show),'on'),
0118 figure;
0119
0120 logSpectrum = log(mu)-v./(2*mu.*mu);
0121 logS = sqrt(v./mu.^2);
0122 PlotMean(f,logSpectrum,logSpectrum-logS,logSpectrum+logS,':');
0123 xlabel('Frequency (Hz)');
0124 ylabel('Power');
0125 title('Power Spectrum');
0126 end