multitaper_spectrogram¶
- multitaper_spectrogram(varargin)¶
MULTITAPER_SPECTROGRAM Compute the multitaper spectrogram for time series data
- Usage:
[spect,stimes,sfreqs] = multitaper_spectrogram(data, Fs, frequency_range, taper_params, window_params, min_NFFT, detrend_opt, weighting, plot_on, verbose)
- Input:
data: <number of samples> x 1 vector - time series data– required Fs: double - sampling frequency in Hz – required
(Can be positional or name-value pair arguments) frequency_range: 1x2 vector - [<min frequency>, <max frequency>] (default: [0 nyquist]) taper_params: 1x2 vector - [<time-halfbandwidth product>, <number of tapers>] (default: [5 9]) window_params: 1x2 vector - [window size (seconds), step size (seconds)] (default: [5 1]) NFFT: double - NFFT size, adds zero padding for interpolation (closest 2^x) (default: 2^(nextpow2(<window samples>)) detrend_opt: string - detrend data window (‘linear’ (default), ‘constant’, ‘off’); weighting: string - weighting of tapers (‘unity’ (default), ‘eigen’, ‘adapt’); plot_on: boolean to plot results (default: true) verbose: boolean to display spectrogram properties (default: true)
- Output:
spect: FxT matrix of spectral power stimes: 1xT vector of times for the center of the spectral bins sfreqs: 1xF vector of frequency bins for the spectrogram
Example: In this example we create some chirp data and run the multitaper spectrogram on it.
Fs=200; %Sampling Frequency frequency_range=[0 25]; %Limit frequencies from 0 to 25 Hz taper_params=[3 5]; %Time bandwidth and number of tapers window_params=[4 1]; %Window size is 4s with step size of 1s nfft=[]; %Use default detrend_opt=’constant’ %detrend each window by subtracting the average weighting=’unity’ %weight each taper at 1 plot_on=true; %plot spectrogram verbose=true; %print extra info
%Generate sample chirp data t=1/Fs:1/Fs:600; %Create 10 minutes of data f_start=1;f_end=20; % Set chirp range in Hz data=chirp(t,f_start,t(end),f_end,’logarithmic’);
%Compute the multitaper spectrogram [spect,stimes,sfreqs] = multitaper_spectrogram(data, Fs,frequency_range, taper_params, window_params, nfft, detrend_opt, weighting, plot_on, verbose);
%Example of name-value pair call [spect,stimes,sfreqs] = multitaper_spectrogram(data, Fs,’nfft’, nfft, ‘plot_on’, true);
- This code is companion to the paper:
“Sleep Neurophysiological Dynamics Through the Lens of Multitaper Spectral Analysis” Michael J. Prerau, Ritchie E. Brown, Matt T. Bianchi, Jeffrey M. Ellenbogen, Patrick L. Purdon December 7, 2016 : 60-92 DOI: 10.1152/physiol.00062.2015
which should be cited for academic use of this code.
A full tutorial on the multitaper spectrogram can be found at: http://www.sleepEEG.org/multitaper
Copyright 2024 Michael J. Prerau Laboratory. - http://www.sleepEEG.org Authors: Michael J. Prerau, Ph.D., Mingjian He, Ph.D.