Home > FMAToolbox > Analyses > MTPointSpectrogram.m

MTPointSpectrogram

PURPOSE ^

MTPointSpectrogram - Compute point process spectrogram by multi-taper estimation.

SYNOPSIS ^

function [spectrogram,t,f] = MTPointSpectrogram(times,varargin)

DESCRIPTION ^

MTPointSpectrogram - Compute point process spectrogram by multi-taper estimation.

  The spectrogram is computed using the <a href="http://www.chronux.org">chronux</a> toolbox.

  USAGE

    [spectrogram,t,f] = MTPointSpectrogram(times,<options>)

    times          event times, e.g. spike times
    <options>      optional list of property-value pairs (see table below)

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'frequency'   sampling rate (in Hz) (default = 20000Hz)
     'range'       frequency range (in Hz) (default = all)
     'window'      duration (in s) of the time window (default = 5)
     'overlap'     overlap between successive windows (default = window/2)
     'step'        step between successive windows (default = window/2)
     'tapers'      relative resolution and order of the tapers [NW K]
                   (default = [3 5])
     'pad'         FFT padding (see help for <a href="matlab:help mtspecgrampt">mtspecgrampt</a>) (default = 0)
     'show'        plot spectrogram (default = 'off')
     'parent'      parent figure or uipanel handle (default = gcf)
     'cutoffs'     cutoff values for color plot (default = [0 13])
    =========================================================================

  NOTES

    The time displacement between successive short time spectra can be supplied
    either as a 'step' (explicit time difference) or as an 'overlap' (between
    successive time windows).

  OUTPUT

    spectrogram    time-frequency matrix
    t              time bins
    f              frequency bins

  DEPENDENCIES

    This function requires the <a href="http://www.chronux.org">chronux</a> toolbox.

  SEE

    See also SpectrogramBands, PlotColorMap.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [spectrogram,t,f] = MTPointSpectrogram(times,varargin)
0002 
0003 %MTPointSpectrogram - Compute point process spectrogram by multi-taper estimation.
0004 %
0005 %  The spectrogram is computed using the <a href="http://www.chronux.org">chronux</a> toolbox.
0006 %
0007 %  USAGE
0008 %
0009 %    [spectrogram,t,f] = MTPointSpectrogram(times,<options>)
0010 %
0011 %    times          event times, e.g. spike times
0012 %    <options>      optional list of property-value pairs (see table below)
0013 %
0014 %    =========================================================================
0015 %     Properties    Values
0016 %    -------------------------------------------------------------------------
0017 %     'frequency'   sampling rate (in Hz) (default = 20000Hz)
0018 %     'range'       frequency range (in Hz) (default = all)
0019 %     'window'      duration (in s) of the time window (default = 5)
0020 %     'overlap'     overlap between successive windows (default = window/2)
0021 %     'step'        step between successive windows (default = window/2)
0022 %     'tapers'      relative resolution and order of the tapers [NW K]
0023 %                   (default = [3 5])
0024 %     'pad'         FFT padding (see help for <a href="matlab:help mtspecgrampt">mtspecgrampt</a>) (default = 0)
0025 %     'show'        plot spectrogram (default = 'off')
0026 %     'parent'      parent figure or uipanel handle (default = gcf)
0027 %     'cutoffs'     cutoff values for color plot (default = [0 13])
0028 %    =========================================================================
0029 %
0030 %  NOTES
0031 %
0032 %    The time displacement between successive short time spectra can be supplied
0033 %    either as a 'step' (explicit time difference) or as an 'overlap' (between
0034 %    successive time windows).
0035 %
0036 %  OUTPUT
0037 %
0038 %    spectrogram    time-frequency matrix
0039 %    t              time bins
0040 %    f              frequency bins
0041 %
0042 %  DEPENDENCIES
0043 %
0044 %    This function requires the <a href="http://www.chronux.org">chronux</a> toolbox.
0045 %
0046 %  SEE
0047 %
0048 %    See also SpectrogramBands, PlotColorMap.
0049 
0050 % Copyright (C) 2004-2012 by Michaƫl Zugaro
0051 %
0052 % This program is free software; you can redistribute it and/or modify
0053 % it under the terms of the GNU General Public License as published by
0054 % the Free Software Foundation; either version 3 of the License, or
0055 % (at your option) any later version.
0056 
0057 % Make sure chronux is installed and functional
0058 CheckChronux('mtspecgrampt');
0059 
0060 % Defaults
0061 frequency = 20000;
0062 window = 5;
0063 range = [];
0064 overlap = [];
0065 step = [];
0066 show = 'off';
0067 cutoffs = [0 13];
0068 tapers = [3 5];
0069 pad = 0;
0070 parent = [];
0071 averageTrials = 1;
0072 
0073 % Check number of parameters
0074 if nargin < 1 | mod(length(varargin),2) ~= 0,
0075   error('Incorrect number of parameters (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).');
0076 end
0077 
0078 % Check parameter sizes
0079 if ~isdvector(times),
0080     error('Parameter ''times'' is not a vector (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).');
0081 end
0082 
0083 % Parse parameter list
0084 for i = 1:2:length(varargin),
0085     if ~ischar(varargin{i}),
0086         error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).']);
0087     end
0088     switch(lower(varargin{i})),
0089         case 'frequency',
0090             frequency = varargin{i+1};
0091             if ~isdscalar(frequency,'>0'),
0092                 error('Incorrect value for property ''frequency'' (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).');
0093             end
0094         case 'range',
0095             range = varargin{i+1};
0096             if ~isdvector(range,'#2','>=0','<'),
0097                 error('Incorrect value for property ''range'' (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).');
0098             end
0099         case 'window',
0100             window = varargin{i+1};
0101             if ~isdscalar(window,'>0'),
0102                 error('Incorrect value for property ''window'' (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).');
0103             end
0104         case 'overlap',
0105             overlap = varargin{i+1};
0106             if ~isdscalar(overlap,'>0'),
0107                 error('Incorrect value for property ''overlap'' (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).');
0108             end
0109         case 'step',
0110             step = varargin{i+1};
0111             if ~isdscalar(step,'>0'),
0112                 error('Incorrect value for property ''step'' (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).');
0113             end
0114         case 'tapers',
0115             tapers = varargin{i+1};
0116             if ~isivector(tapers,'#2','>0'),
0117                 error('Incorrect value for property ''tapers'' (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).');
0118             end
0119         case 'pad',
0120             pad = varargin{i+1};
0121             if ~isdscalar(pad,'>-1'),
0122                 error('Incorrect value for property ''pad'' (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).');
0123             end
0124         case 'show',
0125             show = varargin{i+1};
0126             if ~isastring(show,'on','off'),
0127                 error('Incorrect value for property ''show'' (type ''help <a href="matlab:help FindRipples">FindRipples</a>'' for details).');
0128             end
0129         case 'cutoffs',
0130             cutoffs = varargin{i+1};
0131             if ~isdvector(cutoffs,'#2','>=0','<'),
0132                 error('Incorrect value for property ''cutoffs'' (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).');
0133             end
0134         case 'parent',
0135             parent = varargin{i+1};
0136             if ~ishandle(parent),
0137                 error('Incorrect value for property ''parent'' (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).');
0138             end
0139         otherwise,
0140             error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).']);
0141     end
0142 end
0143 
0144 % Determine step/overlap
0145 if isempty(step),
0146     if isempty(overlap),
0147         overlap = window/2;
0148     end
0149 else
0150     if isempty(overlap),
0151         overlap = window-step;
0152     elseif overlap ~= window-step,
0153         error('Incompatible ''step'' and ''overlap'' parameters (type ''help <a href="matlab:help MTPointSpectrogram">MTPointSpectrogram</a>'' for details).');
0154     end
0155 end
0156 
0157 % Compute and plot spectrogram
0158 parameters.Fs = frequency;
0159 if ~isempty(range), parameters.fpass = range; end
0160 parameters.tapers = tapers;
0161 parameters.pad = pad;
0162 parameters.trialave = averageTrials;
0163 % mtspecgrampt was optimized, until Chonux releases a new updated version, we are calling our mtspecgrampt_optimized version:
0164 % [spectrogram,t,f] = mtspecgrampt(times,[window window-overlap],parameters);
0165 [spectrogram,t,f] = mtspecgrampt_optimized(times,[window window-overlap],parameters);
0166 t = t';
0167 f = f';
0168 spectrogram = spectrogram';
0169 if strcmp(lower(show),'on'),
0170     if isempty(parent), parent = figure; end
0171     logTransformed = log(spectrogram);
0172     PlotColorMap(logTransformed,1,'x',t,'y',f,'cutoffs',cutoffs);
0173     xlabel('Time (s)');
0174     ylabel('Frequency (Hz)');
0175     title('Power Spectrogram');
0176 end

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005